The begin() method currently checks the I2C address that was passed (or the base address 0x77), and if that fails, it checks the other address (base 0x77 or alternate 0x76). This can cause a false success return if two sensors are being used and one is successful and the other is not. In this case, both sensor objects will return success but point to the same device address.
Checking both addresses should only be done if no address was passed (e.g. begin(void) or begin(TwoWire*)). In cases where the address is passed, only that address should be checked (begin(addr) or begin(addr, TwoWire*)).
Test can be done using one BME280 sensor on address 0x76 with the following code:
Adafruit_BME280 bme1, bme2;
bool rc1 = bme1.begin(0x77); // should be false
bool rc2 = bme2.begin(0x76); // should be true
rc1 = bme1.begin(); // should be true because both addresses were checked
Note that prior to this change, all of the above begin() calls would return true because both addresses were always checked.
I made the requested changes in my repository and I think it pushed them here, but not sure if I did it right (github noob). Please let me know if there is something else I need to do.
Thanks!
The begin() method currently checks the I2C address that was passed (or the base address 0x77), and if that fails, it checks the other address (base 0x77 or alternate 0x76). This can cause a false success return if two sensors are being used and one is successful and the other is not. In this case, both sensor objects will return success but point to the same device address.
Checking both addresses should only be done if no address was passed (e.g.
begin(void)
orbegin(TwoWire*)
). In cases where the address is passed, only that address should be checked (begin(addr)
orbegin(addr, TwoWire*)
).Test can be done using one BME280 sensor on address 0x76 with the following code:
Note that prior to this change, all of the above begin() calls would return true because both addresses were always checked.