How to distinguish sensors?
-
What are the possibilities to distinguish between different sensors?
I have 3 different sensors BME280 SHT21 and SHT31.
How can I find out which sensor is connected to the Wipy/Lopy?
Is that even possible?
Who can help me?
-
@robert-hh Thank You!
-
@Wolli01 You may change I2C addresses by wiring at the module. Besides that, they are constant. But the code should better be:
i2c = I2C(0, I2C.MASTER) device_list = i2c.scan() print(device_list) if 68 in device_list: Sensorwahl = 'sht31' #Vorgabe welcher Sensor verwendet werden soll if 64 in device_list: Sensorwahl = 'sht20_21' #Vorgabe welcher Sensor verwendet werden soll
Reason: i2c.scan() may return more than one entry, if more than one device is connected.
-
@robert-hh
I'm so busy now. Are the I2C addresses always the same or is this solution not advisable?i2c = I2C(0, I2C.MASTER) print(i2c.scan()) if i2c.scan() == [68]: Sensorwahl = 'sht31' #Vorgabe welcher Sensor verwendet werden soll if i2c.scan() == [64]: Sensorwahl = 'sht20_21' #Vorgabe welcher Sensor verwendet werden soll
-
@robert-hh said in How to distinguish sensors?:
The must have different I2C addresses. If a sensor is responding, it is present (BME280: 0x76, SHT21: 0x40, SHT31: 0x44).
Thanks for the info. How can you ask for something like this before?
Is there a code snippet somewhere?
-
@Wolli01 The must have different I2C addresses. If a sensor is responding, it is present (BME280: 0x76, SHT21: 0x40, SHT31: 0x44).