Thanks hzrnbgy. I needed a couple days to understand what you wrote. It is way over my knowledge. Basically, all I wanted is to connect 4 identical sensors, and I could find no example of similar programs.
I finally got it working. I'm not sure why it works, I do not understand everything (far from it). Your last message made me do more tests, and you made me realise that it was always the last sensor I initialised that worked fine. I'm explaining what I've done, if that can help someone one day.
To initialize, I put these lines in my setup(). I found these lines on the web, and I could not get them explained :
TCA9548A(2); // select the #2 bus of the multiplexer
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. /
Adafruit_BMP280::SAMPLING_X2, / Temp. oversampling /
Adafruit_BMP280::SAMPLING_X16, / Pressure oversampling /
Adafruit_BMP280::FILTER_X16, / Filtering. /
Adafruit_BMP280::STANDBY_MS_500); / Standby time. /
TCA9548A(3); // select the #3 bus of the multiplexer
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, / Operating Mode. /
Adafruit_BMP280::SAMPLING_X2, / Temp. oversampling /
Adafruit_BMP280::SAMPLING_X16, / Pressure oversampling /
Adafruit_BMP280::FILTER_X16, / Filtering. /
Adafruit_BMP280::STANDBY_MS_500); / Standby time. */
Choosing the bus is OK, but the setSampling part is Chinese to me. I repeated for every sensor by selecting a different bus number. It didn't work, since I'm here. I realised that my problem was that I needed a different object "bmp" for each sensor. Then I wrote instead :
TCA9548A(2); // select the #2 bus of the multiplexer
bmp1.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. /
Adafruit_BMP280::SAMPLING_X2, / Temp. oversampling /
Adafruit_BMP280::SAMPLING_X16, / Pressure oversampling /
Adafruit_BMP280::FILTER_X16, / Filtering. /
Adafruit_BMP280::STANDBY_MS_500); / Standby time. /
TCA9548A(2); // select the #2 bus of the multiplexer
bmp2.setSampling(Adafruit_BMP280::MODE_NORMAL, / Operating Mode. /
Adafruit_BMP280::SAMPLING_X2, / Temp. oversampling /
Adafruit_BMP280::SAMPLING_X16, / Pressure oversampling /
Adafruit_BMP280::FILTER_X16, / Filtering. /
Adafruit_BMP280::STANDBY_MS_500); / Standby time. */
And it worked! Of course, I had to declare first, at the beginning :
Adafruit_BMP280 bmp1; // I2C
Adafruit_BMP280 bmp2;
Adafruit_BMP280 bmp3;
Adafruit_BMP280 bmp4;
So by using the same object "bmp" for each sensor, I think I also used the same calibration for all of them, as you explained, superseding each previous calibration by the next one. That was effectively my problem. Having bmp1 to bmp4 made it work.
I still don't understand why
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. /
Adafruit_BMP280::SAMPLING_X2, / Temp. oversampling /
Adafruit_BMP280::SAMPLING_X16, / Pressure oversampling /
Adafruit_BMP280::FILTER_X16, / Filtering. /
Adafruit_BMP280::STANDBY_MS_500); / Standby time. */
is required for calibrating each of them, since it is the same 5 lines for all sensors. Since calibration is mandatory, why isn'it done automatically?
Thanks a lot anyway, you made me search a lot, and it made me learn. I could not understand everything, but I did my best. Cheers!