diff --git a/enviro/__init__.py b/enviro/__init__.py index 07b1633..7f0ca48 100644 --- a/enviro/__init__.py +++ b/enviro/__init__.py @@ -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 @@ -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 diff --git a/enviro/sensors/scd41.py b/enviro/sensors/scd41.py new file mode 100644 index 0000000..ae0f307 --- /dev/null +++ b/enviro/sensors/scd41.py @@ -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 + }) \ No newline at end of file diff --git a/main.py b/main.py index 95eff3b..de938bb 100644 --- a/main.py +++ b/main.py @@ -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: