-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_logging.py
More file actions
44 lines (39 loc) · 1.02 KB
/
data_logging.py
File metadata and controls
44 lines (39 loc) · 1.02 KB
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
from sense_hat import SenseHat
from datetime import datetime
from csv
timestamp = datetime.now()
# Delay in seconds
delay = 3
sense = SenseHat()
def get_sense_data():
orientation = sense.get_orientation()
mag = sense.get_compass_raw()
acc = sense.get_accelerometer_raw()
gyro = sense.get_gyroscope_raw()
return [
datetime.now(),
sense.get_temperature(),
sense.get_pressure(),
sense.get_humidity(),
orientation['yaw'],
orientation['pitch'],
orientation['roll'],
mag["x"],
mag["y"],
mag["z"],
acc["x"],
acc["y"],
acc["z"],
gyro["x"],
gyro["y"],
gyro["z"]
]
with open('data.csv', 'w', newline='') as f:
writer = csv.writer(f)
writer.writerow(['datetime', 'temperature','pressure','humidity', 'yaw','pitch','roll', 'mag_x','mag_y','mag_z', 'acc_x','acc_y','acc_z', 'gyro_x', 'gyro_y', 'gyro_z'])
while True:
delta = datetime.now() - timestamp
if delta.seconds > delay:
data = get_sense_data()
writer.writerow(data)
timestamp = datetime.now()