Upload wupitul_195.py
Browse files- wupitul_195.py +52 -0
wupitul_195.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
"""Wupitul.195
|
3 |
+
|
4 |
+
Automatically generated by Colab.
|
5 |
+
|
6 |
+
Original file is located at
|
7 |
+
https://colab.research.google.com/drive/1qljd7QuB5ROr7LMRyzTu4YlsINVu4A1F
|
8 |
+
"""
|
9 |
+
|
10 |
+
import time
|
11 |
+
try:
|
12 |
+
from smbus2 import SMBus
|
13 |
+
except ImportError:
|
14 |
+
from smbus import SMBus
|
15 |
+
from bme280 import BME280
|
16 |
+
import time
|
17 |
+
import datetime
|
18 |
+
from datetime import date
|
19 |
+
from openpyxl import load_workbook
|
20 |
+
|
21 |
+
print("""all-values.py - Read temperature, pressure, and humidity)
|
22 |
+
|
23 |
+
Press Ctrl+C to exit!
|
24 |
+
""")
|
25 |
+
|
26 |
+
# Initialise the BME280
|
27 |
+
bus = SMBus(1)
|
28 |
+
bme280 - BME280(12c_dev=bus)
|
29 |
+
|
30 |
+
while True:
|
31 |
+
temperature = bme280.get_temperature()
|
32 |
+
pressure = bme280.get_pressure()
|
33 |
+
humidity = bme280.get_humidity()
|
34 |
+
today = date.today()
|
35 |
+
now = datetime.datetime.now().time()
|
36 |
+
|
37 |
+
print('Adding this data to the spreadsheet:')
|
38 |
+
print(today)
|
39 |
+
print(now)
|
40 |
+
print('{:0.5.2f}*C {:05/2f}hPa {:05/2f}%'.format(temperature, pressure, humidity))
|
41 |
+
|
42 |
+
row = (today, now, temperature, pressure, humidity)
|
43 |
+
sheet.append(row)
|
44 |
+
|
45 |
+
wb.save
|
46 |
+
|
47 |
+
time.sleep(600)
|
48 |
+
|
49 |
+
finally:
|
50 |
+
wb.save
|
51 |
+
|
52 |
+
print('Goodbye!')
|