just wanted to share my recent project with you: A HDC1008 temperature and humidity sensor connected via IC2 to a Arduino, connected via USB to a PI2 which uploads the data to google docs.
The time has come to start sharing my stuff, after struggeling with the setup. Anyway, it works.
What you need: Arduino, a HDC1008, a PI2 and the stuff to connect them. Other sensors will work the same way, if you use the Arduino as the sensor backbone.
Step 1
Wire the HDC1008 according specification to PIN4 and 5 of the Arduino. Use the HDC1000 library from http://www.truzzi.me to skip the manual I2C implementation. The sketch must output the temperature and humidity in the format "XX.XX_XX.XX" / "25.00_48.00" to be parsed with regular expressions later on. Save the sketch and test it. [To understand what the HDC1000 library does, have a look at the HDC1000.h and HDC1000.cpp]. You can connect other sensors to the Arduino, this tutorial is more about get data to google docs. This will work with any values, just change the pattern of the regular expressions.
Step 2
Connect the Arduino to the PI2 via USB cable. Install the Arduino IDE. Test the connection by uploading the sketch. That should be no problem, if you had values in Step 1, you likely have the same values here.
Step 3
Install all the necessary libaries to get started with uploading data to google docs. I used gspread to connect to google.
Code: Select all
sudo apt-get updateCode: Select all
sudo apt-get install build-essential python-dev libssl-dev libffi-dev python-pipCode: Select all
sudo pip install gspread oauth2client pyopenssl Code: Select all
import serial
import re
import time
import json
import gspread
from oauth2client.client import SignedJwtAssertionCredentials
pattern = r"(\d+\.\d*)_(\d+\.\d*)\r\n" #check regual impressions generator at google
port = '/dev/ttyACM1'
port2 = '/dev/ttyACM0' #Select if not on ACM1
baud = 115200
json_key = json.load(open('temphumi-86f9d0378d0f.json'))
scope = ['https://spreadsheets.google.com/feeds']
credentials = SignedJwtAssertionCredentials(json_key['client_email'], json_key['private_key'], scope)
s = serial.Serial(port2, baud, timeout = 1)
if s.isOpen():
print "connected"
while True:
line = s.readline()
if len(line) > 6:
m = re.match(pattern, line)
tableline = [str(time.strftime("%d/%m/%Y")), str(time.strftime("%H:%M:%S")), m.group(1), m.group(2)]
gc = gspread.authorize(credentials)
wks = gc.open("humitemp").sheet1 #avoids http 401 unauthorized after 15 minutes
wks.append_row(tableline)
#print ("GROUP1: " + m.group(1) + " GROUP2: " + m.group(2))
print (tableline)
time.sleep(30)
else:
time.sleep(1)
print "killing"
s.close()
else:
print ("Failure opening serial port at " + port)
Code: Select all
python google.pyStep 4
Enjoy sensor values comming in from anywhere in the world
Hope that helps someone out there.
Regards
dahunter