-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
37 lines (26 loc) · 858 Bytes
/
example.py
File metadata and controls
37 lines (26 loc) · 858 Bytes
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
from time import sleep
from .i2c_class import I2C
from .sensor_class import SCD4x
i2c = I2C()
sensor = SCD4x()
i2c.sensirion_i2c_hal_init()
# Clean up potential SCD40 states
sensor.scd4x_wake_up()
sensor.scd4x_stop_periodic_measurement()
sensor.scd4x_reinit()
serial = sensor.scd4x_get_serial_number()
print(f"Serial number: {hex(serial)}")
# Start Measurement
sensor.scd4x_start_periodic_measurement()
print("Waiting for first measurement... (5 sec)")
while True:
# Read Measurement
# TODO: sleep with native c method
sleep(5)
data_ready = sensor.scd4x_get_data_ready_status()
print(f"Data ready: {data_ready}")
if (data_ready):
co2, temperature, humidity = sensor.scd4x_read_measurement()
print(f"CO2: {co2} ppm")
print(f"Temperature: {temperature} °C")
print(f"Humidity: {humidity} RH")