File size: 1,049 Bytes
9045f65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# -*- coding: utf-8 -*-
"""Wupitul.195

Automatically generated by Colab.

Original file is located at
    https://colab.research.google.com/drive/1qljd7QuB5ROr7LMRyzTu4YlsINVu4A1F
"""

import time
try:
  from smbus2 import SMBus
except ImportError:
  from smbus import SMBus
from bme280 import BME280
import time
import datetime
from datetime import date
from openpyxl import load_workbook

print("""all-values.py - Read temperature, pressure, and humidity)

Press Ctrl+C to exit!
""")

# Initialise the BME280
bus = SMBus(1)
bme280 - BME280(12c_dev=bus)

while True:
  temperature = bme280.get_temperature()
  pressure = bme280.get_pressure()
  humidity = bme280.get_humidity()
  today = date.today()
  now = datetime.datetime.now().time()

  print('Adding this data to the spreadsheet:')
  print(today)
  print(now)
  print('{:0.5.2f}*C {:05/2f}hPa {:05/2f}%'.format(temperature, pressure, humidity))

  row = (today, now, temperature, pressure, humidity)
  sheet.append(row)

  wb.save

  time.sleep(600)

finally:
  wb.save

  print('Goodbye!')