Skip to content

Commit 6ce7ddc

Browse files
author
K. Townsend
committed
First commit
1 parent 85037d3 commit 6ce7ddc

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/python
2+
3+
import sys
4+
import time
5+
import datetime
6+
import gspread
7+
from Adafruit_BMP085 import BMP085
8+
9+
# ===========================================================================
10+
# Google Account Details
11+
# ===========================================================================
12+
13+
# Account details for google docs
14+
15+
password = '$hhh!'
16+
spreadsheet = 'SpreadsheetName'
17+
18+
# ===========================================================================
19+
# Example Code
20+
# ===========================================================================
21+
22+
# Initialise the BMP085 and use STANDARD mode (default value)
23+
# bmp = BMP085(0x77, debug=True)
24+
bmp = BMP085(0x77)
25+
26+
# To specify a different operating mode, uncomment one of the following:
27+
# bmp = BMP085(0x77, 0) # ULTRALOWPOWER Mode
28+
# bmp = BMP085(0x77, 1) # STANDARD Mode
29+
# bmp = BMP085(0x77, 2) # HIRES Mode
30+
# bmp = BMP085(0x77, 3) # ULTRAHIRES Mode
31+
32+
# Login with your Google account
33+
try:
34+
gc = gspread.login(email, password)
35+
except:
36+
print "Unable to log in. Check your email address/password"
37+
sys.exit()
38+
39+
# Open a worksheet from your spreadsheet using the filename
40+
try:
41+
worksheet = gc.open(spreadsheet).sheet1
42+
# Alternatively, open a spreadsheet using the spreadsheet's key
43+
# worksheet = gc.open_by_key('0BmgG6nO_6dprdS1MN3d3MkdPa142WFRrdnRRUWl1UFE')
44+
except:
45+
print "Unable to open the spreadsheet. Check your filename: %s" % spreadsheet
46+
sys.exit()
47+
48+
# Continuously append data
49+
while(True):
50+
temp = bmp.readTemperature()
51+
pressure = bmp.readPressure()
52+
altitude = bmp.readAltitude()
53+
54+
print "Temperature: %.2f C" % temp
55+
print "Pressure: %.2f hPa" % (pressure / 100.0)
56+
print "Altitude: %.2f" % altitude
57+
58+
# Append the data in the spreadsheet, including a timestamp
59+
try:
60+
values = [datetime.datetime.now(), temp, pressure, altitude]
61+
worksheet.append_row(values)
62+
except:
63+
print "Unable to append data. Check your connection?"
64+
sys.exit()
65+
66+
# Wait 5 seconds before continuing
67+
print "Wrote a row to %s" % spreadsheet
68+
time.sleep(5)
69+

0 commit comments

Comments
 (0)