-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsensorloop.py
51 lines (40 loc) · 1.56 KB
/
sensorloop.py
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
def writeToFile(data):
with open("sensor.txt", "a") as f:
f.write(data + "\n")
def main():
import time
import adafruit_bno055 as adb
import board
import time
import bme280
import smbus2
from datetime import datetime
import adafruit_dps310
i2c = board.I2C()
port = 1
address_bme = 0x77
address_dps = 0x77
bus = smbus2.SMBus(port)
calib_param = bme280.load_calibration_params(bus, address_bme)
bno_sensor = adb.BNO055_I2C(i2c)
dps_sensor = adafruit_dps310.DPS310(bus, address=address_dps)
while True:
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
writeToFile("Time: " + timestamp)
writeToFile("Gyro: " + str(bno_sensor.gyro))
writeToFile("Acceleration: " + str(bno_sensor.acceleration))
writeToFile("Gravity: " + str(bno_sensor.gravity))
writeToFile("Magnetic: " + str(bno_sensor.magnetic))
writeToFile("Euler: " + str(bno_sensor.euler))
bme_data = bme280.sample(bus, address_bme, calib_param)
writeToFile("Temperature: " + str(bme_data.temperature) + " C")
writeToFile("Pressure: " + str(bme_data.pressure) + " Pa")
writeToFile("Humidity: " + str(bme_data.humidity) + " %")
dps_temp = dps_sensor.temperature
dps_pressure = dps_sensor.pressure
writeToFile("DPS310 Temperature: " + str(dps_temp) + " C")
writeToFile("DPS310 Pressure: " + str(dps_pressure) + " Pa")
writeToFile("") # Empty line for separation
time.sleep(1)
if __name__ == "__main__":
main()