-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollect_data.py
More file actions
40 lines (32 loc) · 1.08 KB
/
collect_data.py
File metadata and controls
40 lines (32 loc) · 1.08 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
import qwiic_as726x
import time
import csv
sensor = qwiic_as726x.QwiicAS726x()
if not sensor.connected:
print("AS726x not detected. Check connections.")
exit()
sensor.begin()
print("AS726x Initialized. Starting data collection...")
filename = "datasets/glucose_data.csv"
header = ["610", "680", "730", "760", "810", "860", "glucose"]
with open(filename, mode="a", newline='') as f:
writer = csv.writer(f)
if f.tell() == 0:
writer.writerow(header)
while True:
sensor.take_measurements()
vals = [
sensor.get_calibrated_value(0),
sensor.get_calibrated_value(1),
sensor.get_calibrated_value(2),
sensor.get_calibrated_value(3),
sensor.get_calibrated_value(4),
sensor.get_calibrated_value(5),
]
print("Spectral values:", vals)
glucose = input("Enter corresponding glucose reading (mg/dL): ")
if glucose.lower() == "q":
print("Data collection ended.")
break
writer.writerow(vals + [glucose])
print("Saved entry.\n")