Temp recording and upload live to Google Doc`s

This project is a mismatch off a couple of project on-line at the moment . I will reference all the sites where I got the information from. In a nutshell this project takes the temperature from a DS18B20 sensor. This is a great piece of kit as it only needs 3 leads attached to it and 2 off those are 3.3v and ground. The resistor is used to pump up the voltage on the output pin to keep the Pi happy. Because the digital sensor is accessed by it serial number it means more sensors can be added and no extra resistors just extra cables. The idea of this project was to explorer putting live data on-line. In fact my 9 year son came up with an idea for this project. Dad he said ” we could put this in nanny`s house and keep an eye on her temp in the house and even link up some LED`s too” . So I can see this becoming a stand alone project. So have a read try it out and let`s get cooking.

Ingredients 

1. DS18B20 digital temperature sensor

2. 4.7k Resistor

3. Couple of jumper cables

4. Google Account

breadboard-ic

 

Follow the diagram to wire up the sensor and resistor. To test the sensors is working follow this guide from Adafruit`s site.

 

 

Pre heat

First you`ll need to create a blank spreadsheet on google drive. Rename it what you want I called mine Temperature_Log in cell A1 type Date/Time , B1 Temp In and C1 Temp Pi . you can call these what ever you like. Then delete all the other rows. If you do not your data will be entered right at the bottom.

Next we need to download a new python module called gspread . code from Daniel Hansen

wget https://pypi.python.org/packages/source/g/gspread/gspread-0.0.15.tar.gz
tar -zxvf gspread-0.0.15.tar.gz
cd gspread
sudo python setup.py install

Once this is done here is the code to make it all work.

#!/usr/bin/python3
#
import os, glob, time, gspread, sys, datetime # all normal imports and the gspread module
#
#Google account details
email = 'foobar@gmail.com'# your google email
password = 'foobar`s password'# your google password
spreadsheet = 'Temperature_Log' #the name of the spreadsheet already created
#
#attempt to log in to your google account
try:
gc = gspread.login(email,password)
except:
print('fail')
sys.exit()
#
#open the spreadsheet
worksheet = gc.open(spreadsheet).sheet1
#
#initiate the temperature sensor
os.system('modprobe w1-gpio')
os.system('modprobe w1-therm')
#
#set up the location of the sensor in the system
base_dir = '/sys/bus/w1/devices/'
device_folder = glob.glob(base_dir + '28*')[0]
device_file = device_folder + '/w1_slave'
#
#
def read_temp_raw():
f = open(device_file, 'r')
lines = f.readlines()
f.close()
return lines
#
def read_temp():
lines = read_temp_raw()
while lines[0].strip()[-3:] != 'YES':
time.sleep(0.2)
lines = read_temp_raw()
equals_pos = lines[1].find('t=')
if equals_pos != -1:
temp_string = lines[1][equals_pos+2:]
temp_c = float(temp_string) / 1000.0
temp_f = temp_c * 9.0 / 5.0 + 32.0
return temp_c
#
# Return CPU temperature as a character string
def getCPUtemperature():
res = os.popen('vcgencmd measure_temp').readline()
return res
#
while True: #infinite loop
tempin = read_temp() #get the temp sensor
temppi = getCPUtemperature() #get the pi temp
values = [datetime.datetime.now(), tempin , temppi]
worksheet.append_row(values) #write to the spreadsheet
print(values)
time.sleep(600) #wait 10 minutes

Hopefully if all this worked you should see the temp from the sensors , temp of the CPU and time and date in your SSH connection and live on your Google spread sheet.

gdriveputty

 

 

 

 

 

References.

Adafruits Tutorial on DS18B20 

Daniel Hansen Tutorial on DS18B20

  

1st Time Lapse

2 hour`s in 5 seconds time lapse.

Done with a Raspberry Pi and Pi Camera . It took 120 shots and compressed them into a 5 second video. No we are not being invaded by aliens it is the red light from the camera this will be covered in future ones.

I used the command – raspistill -o timelapse%04d.jpg -t 75000000 -tl 60000

and ls *.jpg > stills.txt to create the list. You`ll need to sudo apt-get install mencorder for the next bit.    mencoder -nosound -ovc lavc -lavcopts vcodec=mpeg4:aspect=16/9:vbitrate=8000000 -vf scale=1920:1080 -o tlcam.avi -mf type=jpeg:fps=24 mf://@stills.txt   .

This creates the video file.