Skip to content

Commit faca48c

Browse files
committed
Add concept of additional sensors and add SCD41
1 parent 832162c commit faca48c

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

enviro/__init__.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ def get_board():
3030
if model == "urban":
3131
import enviro.boards.urban as board
3232
return board
33-
33+
34+
# return any additional sensors connected with Qw/ST
35+
def get_additional_sensors():
36+
if 98 in i2c_devices:
37+
import enviro.sensors.scd41 as scd41
38+
yield scd41
39+
3440
# set up the activity led
3541
# ===========================================================================
3642
from machine import PWM, Timer
@@ -304,9 +310,14 @@ def get_sensor_readings():
304310
readings = get_board().get_sensor_readings(seconds_since_last)
305311
readings["voltage"] = 0.0 # battery_voltage #Temporarily removed until issue is fixed
306312

313+
# Add any additional sensor readings
314+
for sensor in get_additional_sensors():
315+
for key, value in sensor.get_sensor_readings(seconds_since_last).items():
316+
readings[key] = value
317+
307318
# write out the last time log
308319
with open("last_time.txt", "w") as timefile:
309-
timefile.write(now_str)
320+
timefile.write(now_str)
310321

311322
return readings
312323

enviro/sensors/scd41.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import time
2+
3+
import breakout_scd41
4+
5+
from enviro import i2c
6+
7+
breakout_scd41.init(i2c)
8+
breakout_scd41.start()
9+
10+
def get_sensor_readings(seconds_since_last):
11+
retries = 25
12+
while retries > 0 and not breakout_scd41.ready():
13+
time.sleep(0.2)
14+
retries -= 1
15+
16+
if retries == 0:
17+
return {}
18+
19+
scd_co2, scd_temp, scd_humidity = breakout_scd41.measure()
20+
21+
from ucollections import OrderedDict
22+
return OrderedDict({
23+
"scd_co2": scd_co2,
24+
"scd_temperature": scd_temp,
25+
"scd_humidity": scd_humidity
26+
})

main.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@
7373
# here you can customise the sensor readings by adding extra information
7474
# or removing readings that you don't want, for example:
7575
#
76-
# del readings["temperature"] # remove the temperature reading
76+
# del reading["temperature"] # remove the temperature reading
7777
#
78-
# readings["custom"] = my_reading() # add my custom reading value
78+
# reading["custom"] = my_reading() # add my custom reading value
7979

8080
# is an upload destination set?
8181
if enviro.config.destination:

0 commit comments

Comments
 (0)