Problem with BME280 sensors on Mux

Hi. I am trying to read temperature, pressure and relative humidity from multiple BME280 sensors. I am running the QWiic Mux on a standard redboard and observed the following behavior:

  1. When I plug a single BME280 into the redboard, the measurements converge to stable and expected readings for the environment.

  2. When I plug the same sensor into the Mux and read from just that single channel, the measurements also converge to the expected reading for the environment.

  3. When I add a 2nd BME280 to the Mux, the steady-state temperature, pressure, and rel. humidity readings of the first sensor converge to readings that are entirely different from the previous readings (temp: 20.5 → 22.4C; pressure: 101484 → 99479 Pa; rel. humidity: 44.0% → 40.8%); this effect is reproducible (i.e. disabling the 2nd channel results in the first sensor reading the original steady-state values); the readings from the 2nd sensor are also different from those obtained by just reading from the 2nd sensor without the first being present (either directly on the redboard or from a single-channel Mux reading).

  4. If I add a third sensor to the Mux, all temperature, pressure, and humidity readings converge to different values from what they read with just one or two sensor active; each sensor converges to its own steady-state and in general do not converge to the values they should be reading for the environment that they are in. Again, the behavior is reproducible.

  5. I tested all individual sensors separately by just running them individually off the redboard; their readings all converged to the same expected values (for the environment they are in), well within the tolerances of the BME280.

  6. It does not matter whether the redboard is powered through USB or from an external power supply.

  7. I rotated cables and ports, but the qualitative behavior (i.e. significant change in readings) persisted. I also tried different Mux boards, which (for the same cable/sensors configurations on corresponding ports) resulted in measurements that converged to exactly the same results for each sensor (i.e. exchanging Mux boards had no effect on the actual readings when everything else was kept the same).

In terms of code, I just slightly modified the sample code of the BME280 and the Mux that is posted online for each of these components.

Finally, it does not matter whether I actually read data from the 2nd, 3rd, etc. BME280 sensor. If I connect them and have the code verify that it can see the sensors, but I only read from the first sensor, the mere fact that the ports are recognized leads to a change in the values read from the first sensor.

Any idea why the readings of one sensor would be so significantly affected by the presence of other sensors on the Mux? Needless to say, this behavior invalidates the measurements I would like to take.

Not sure if this is your issue, but I have seen this before when using the mux. You need to have a separate instance of the BME280 object for each board as the object stores data read out of the sensor (cal values, states, etc.) between calls. Changing the chip behind the back of the software will really confuse it. I would make an array of BME280 objects, one per board, and then when doing the readings, use the appropriate one for each port on the mux. See viewtopic.php?f=105&t=54277&p=220782#p220782 for a similar issue

/mike

Thanks. This indeed solved the problem. Thanks also for the link.