Skip to content

Commit

Permalink
Name I2C address constants, and check for error initializing the SCD41
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelBell committed Jan 24, 2023
1 parent faca48c commit 7676a72
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
14 changes: 9 additions & 5 deletions enviro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
i2c = PimoroniI2C(I2C_SDA_PIN, I2C_SCL_PIN, 100000)
i2c_devices = i2c.scan()
model = None
if 56 in i2c_devices: # 56 = colour / light sensor and only present on Indoor
if I2C_ADDR_BH1745 in i2c_devices: # colour / light sensor and only present on Indoor
model = "indoor"
elif 35 in i2c_devices: # 35 = ltr-599 on grow & weather
elif I2C_ADDR_LTR559 in i2c_devices: # ltr-599 on grow & weather
pump3_pin = Pin(12, Pin.IN, Pin.PULL_UP)
model = "grow" if pump3_pin.value() == False else "weather"
pump3_pin.init(pull=None)
Expand All @@ -33,9 +33,13 @@ def get_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
if I2C_ADDR_SCD41 in i2c_devices:
try:
import enviro.sensors.scd41 as scd41
yield scd41
except RuntimeError:
# Likely another device present on the SCD41 address
pass

# set up the activity led
# ===========================================================================
Expand Down
5 changes: 5 additions & 0 deletions enviro/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,8 @@
UPLOAD_SUCCESS = 0
UPLOAD_FAILED = 1
UPLOAD_RATE_LIMITED = 2

# I2C addresses
I2C_ADDR_BH1745 = 0x38
I2C_ADDR_LTR559 = 0x23
I2C_ADDR_SCD41 = 0x62

0 comments on commit 7676a72

Please sign in to comment.