diff --git a/enviro/__init__.py b/enviro/__init__.py index 7f0ca48..4a05659 100644 --- a/enviro/__init__.py +++ b/enviro/__init__.py @@ -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) @@ -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 # =========================================================================== diff --git a/enviro/constants.py b/enviro/constants.py index 0dadcea..f57f153 100644 --- a/enviro/constants.py +++ b/enviro/constants.py @@ -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