Skip to content

Commit

Permalink
Add concept of additional sensors and add SCD41
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelBell committed Jan 22, 2023
1 parent 832162c commit faca48c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
15 changes: 13 additions & 2 deletions enviro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ def get_board():
if model == "urban":
import enviro.boards.urban as board
return board


# return any additional sensors connected with Qw/ST
def get_additional_sensors():
if 98 in i2c_devices:
import enviro.sensors.scd41 as scd41
yield scd41

# set up the activity led
# ===========================================================================
from machine import PWM, Timer
Expand Down Expand Up @@ -304,9 +310,14 @@ def get_sensor_readings():
readings = get_board().get_sensor_readings(seconds_since_last)
readings["voltage"] = 0.0 # battery_voltage #Temporarily removed until issue is fixed

# Add any additional sensor readings
for sensor in get_additional_sensors():
for key, value in sensor.get_sensor_readings(seconds_since_last).items():
readings[key] = value

# write out the last time log
with open("last_time.txt", "w") as timefile:
timefile.write(now_str)
timefile.write(now_str)

return readings

Expand Down
26 changes: 26 additions & 0 deletions enviro/sensors/scd41.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import time

import breakout_scd41

from enviro import i2c

breakout_scd41.init(i2c)
breakout_scd41.start()

def get_sensor_readings(seconds_since_last):
retries = 25
while retries > 0 and not breakout_scd41.ready():
time.sleep(0.2)
retries -= 1

if retries == 0:
return {}

scd_co2, scd_temp, scd_humidity = breakout_scd41.measure()

from ucollections import OrderedDict
return OrderedDict({
"scd_co2": scd_co2,
"scd_temperature": scd_temp,
"scd_humidity": scd_humidity
})
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@
# here you can customise the sensor readings by adding extra information
# or removing readings that you don't want, for example:
#
# del readings["temperature"] # remove the temperature reading
# del reading["temperature"] # remove the temperature reading
#
# readings["custom"] = my_reading() # add my custom reading value
# reading["custom"] = my_reading() # add my custom reading value

# is an upload destination set?
if enviro.config.destination:
Expand Down

0 comments on commit faca48c

Please sign in to comment.