Skip to content

Commit f67f9a6

Browse files
committed
Name I2C address constants, and check for error initializing the SCD41
1 parent d80c8b3 commit f67f9a6

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

enviro/__init__.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
i2c = PimoroniI2C(I2C_SDA_PIN, I2C_SCL_PIN, 100000)
1111
i2c_devices = i2c.scan()
1212
model = None
13-
if 56 in i2c_devices: # 56 = colour / light sensor and only present on Indoor
13+
if I2C_ADDR_BH1745 in i2c_devices: # colour / light sensor and only present on Indoor
1414
model = "indoor"
15-
elif 35 in i2c_devices: # 35 = ltr-599 on grow & weather
15+
elif I2C_ADDR_LTR559 in i2c_devices: # ltr-599 on grow & weather
1616
pump3_pin = Pin(12, Pin.IN, Pin.PULL_UP)
1717
model = "grow" if pump3_pin.value() == False else "weather"
1818
pump3_pin.init(pull=None)
@@ -33,9 +33,13 @@ def get_board():
3333

3434
# return any additional sensors connected with Qw/ST
3535
def get_additional_sensors():
36-
if 98 in i2c_devices:
37-
import enviro.sensors.scd41 as scd41
38-
yield scd41
36+
if I2C_ADDR_SCD41 in i2c_devices:
37+
try:
38+
import enviro.sensors.scd41 as scd41
39+
yield scd41
40+
except RuntimeError:
41+
# Likely another device present on the SCD41 address
42+
pass
3943

4044
# set up the activity led
4145
# ===========================================================================

enviro/constants.py

+5
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,8 @@
4747
WATER_VAPOR_SPECIFIC_GAS_CONSTANT = 461.5
4848
CRITICAL_WATER_TEMPERATURE = 647.096
4949
CRITICAL_WATER_PRESSURE = 22064000
50+
51+
# I2C addresses
52+
I2C_ADDR_BH1745 = 0x38
53+
I2C_ADDR_LTR559 = 0x23
54+
I2C_ADDR_SCD41 = 0x62

0 commit comments

Comments
 (0)