Skip to content

Commit

Permalink
Add optional SCD41 CO2 sensor to Enviro Indoor
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelBell committed Jan 21, 2023
1 parent 832162c commit dadd9fa
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions enviro/boards/indoor.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import math
import time
from breakout_bme68x import BreakoutBME68X
from breakout_bh1745 import BreakoutBH1745

from enviro import i2c
from enviro import i2c, i2c_devices

# Detect whether an SCD41 CO2+ sensor is connected
have_scd41 = 98 in i2c_devices
if have_scd41:
import breakout_scd41

breakout_scd41.init(i2c)
breakout_scd41.start()

bme688 = BreakoutBME68X(i2c, address=0x77)

bh1745 = BreakoutBH1745(i2c)
Expand Down Expand Up @@ -54,14 +63,31 @@ def get_sensor_readings(seconds_since_last):

bh1745.measurement_time_ms(160)
r, g, b, c = bh1745.rgbc_raw()

co2 = 0
if have_scd41:
retries = 25
while retries > 0 and not breakout_scd41.ready():
time.sleep(0.2)
retries -= 1

if retries != 0:
co2, temp_scd, hum_scd = breakout_scd41.measure()

# Prefer the SCD41 temperature as it is further from the potentially warm Pico
temperature = round(temp_scd, 2)

from ucollections import OrderedDict
return OrderedDict({
d = OrderedDict({
"temperature": temperature,
"humidity": humidity,
"pressure": pressure,
"gas_resistance": gas_resistance,
"aqi": aqi,
"luminance": lux_from_rgbc(r, g, b, c),
"color_temperature": colour_temperature_from_rgbc(r, g, b, c)
})
})
if co2 > 0:
d["CO2"] = co2

return d

0 comments on commit dadd9fa

Please sign in to comment.