Closed F-Schmidt99 closed 10 months ago
Unfortunately we don't support to change I2C address on runtime. You can simply modify the driver and change the I2C address
Maybe I explained the issue with too little details, so for now I will reformulate it as a question.
How could I communicate with a sensor of type SHT40-BD1B-R2 using this library? I can not set the i2c address anywhere and the default is not 0x44 but 0x45
Hej @F-Schmidt99 ,
Not sure @psachs still has this old issue under the radar so I will jump in. In the file https://github.com/Sensirion/arduino-i2c-sht4x/blob/master/src/SensirionI2CSht4x.cpp you can change the I2C address to 0x45 by setting SHT4X_I2C_ADDRESS
I hope it helps Cheers
Edit: to be clear I am talking about directly editing the file. Which typically is easier when you cloned the repository and transferred the driver to your project (instead of installing it using the Arduino library manager)
Hello @qfisch,
thank you for the response. I know how to control the sensor by editing the file. But keeping in mind, that this library is for the Arduino framework, and therefor also used by many beginners, I think, that you should provide either a constructor or a 'begin' method taking the i2c address as uint8_t address argument. Alternatively, you could also pass an enum value like this:
enum SHTSensorType {
A = 0x44,
B = 0x45
};
for better readable code. See here for guidelines of Arduino: https://docs.arduino.cc/learn/contributions/arduino-creating-library-guide
Kind regards.
Hej @F-Schmidt99 ,
I just saw your PR as well. As explained there, the feature is planned and should be rolled out soon through our typical generation process. I will keep this issue open to make sure to notify you once it is available.
Cheers Q
Driver is now updated to included this feature
Could you please add support for SHT40-B sensors that have the alternative i2c address 0x45?
Currently it is hardcoded in SensirionI2CSht4x.cpp, line 44:
#define SHT4X_I2C_ADDRESS 0x44
You could just add a uint8_t field to the sensor object and use either the constructor or begin(...) method with the current address as the default. This would even be backward compatible with the current library version.