Hello,
I am using a TCA9548A i2c multiplexer to read data from 4 BMP180 sensors.
Everything seems to be connected properly, as I am getting data, but the data are not correct (except for one sensor).
I have check the sensors one by one, there are working correctly.
I have tried to add "delay" in my code, but it doesn't change anything.
Does anyone know how to solve this issue?
Thank you
#include <Wire.h>
#include <SFE_BMP180.h>
SFE_BMP180 pressure_0;
SFE_BMP180 pressure_1;
SFE_BMP180 pressure_2;
SFE_BMP180 pressure_3;
#define TCAADDR 0x70
void tcaselect(uint8_t i) {
if (i > 7) return;
Wire.beginTransmission(TCAADDR);
Wire.write(1 << i);
Wire.endTransmission();
}
void setup() {
Serial.begin(9600);
Wire.begin();
Serial.println("Starting Initialization");
pressure_0.begin();
delay(100);
pressure_1.begin();
delay(100);
pressure_2.begin();
delay(100);
pressure_3.begin();
Serial.println("Initialization Finished");
}
void loop()
{
delay(1000);
tcaselect(0);
char status;
double T0,P0;
status = pressure_0.startTemperature();
if (status != 0)
{
// Wait for the measurement to complete:
delay(status);
status = pressure_0.getTemperature(T0);
if (status != 0)
{
// Print out the measurement:
Serial.print("T0: ");
Serial.print(T0,2);
Serial.print(" °C, ");
status = pressure_0.startPressure(3);
if (status != 0)
{
// Wait for the measurement to complete:
delay(status);
status = pressure_0.getPressure(P0,T0);
if (status != 0)
{
Serial.print("P0: ");
Serial.print(P0,2);
Serial.println(" mb ");
}
else Serial.println("error retrieving pressure measurement\n");
}
else Serial.println("error starting pressure measurement\n");
}
else Serial.println("error retrieving temperature measurement\n");
}
else Serial.println("error starting temperature measurement\n");
delay(1000);
tcaselect(1);
double T1,P1;
status = pressure_1.startTemperature();
if (status != 0)
{
// Wait for the measurement to complete:
delay(status);
status = pressure_1.getTemperature(T1);
if (status != 0)
{
// Print out the measurement:
Serial.print("T1: ");
Serial.print(T1,2);
Serial.print(" °C, ");
status = pressure_1.startPressure(3);
if (status != 0)
{
// Wait for the measurement to complete:
delay(status);
status = pressure_1.getPressure(P1,T1);
if (status != 0)
{
Serial.print("P1: ");
Serial.print(P1,2);
Serial.println(" mb, ");
}
else Serial.println("error retrieving pressure measurement\n");
}
else Serial.println("error starting pressure measurement\n");
}
else Serial.println("error retrieving temperature measurement\n");
}
else Serial.println("error starting temperature measurement\n");
delay(1000);
tcaselect(2);
;
double T2,P2;
status = pressure_2.startTemperature();
if (status != 0)
{
// Wait for the measurement to complete:
delay(status);
status = pressure_2.getTemperature(T2);
if (status != 0)
{
// Print out the measurement:
Serial.print("T2: ");
Serial.print(T2,2);
Serial.print(" °C, ");
status = pressure_2.startPressure(3);
if (status != 0)
{
// Wait for the measurement to complete:
delay(status);
status = pressure_2.getPressure(P2,T2);
if (status != 0)
{
Serial.print("P2: ");
Serial.print(P2,2);
Serial.println(" mb, ");
}
else Serial.println("error retrieving pressure measurement\n");
}
else Serial.println("error starting pressure measurement\n");
}
else Serial.println("error retrieving temperature measurement\n");
}
else Serial.println("error starting temperature measurement\n");
delay(1000);
tcaselect(3);
double T3,P3;
status = pressure_3.startTemperature();
if (status != 0)
{
// Wait for the measurement to complete:
delay(status);
status = pressure_3.getTemperature(T3);
if (status != 0)
{
// Print out the measurement:
Serial.print("T3: ");
Serial.print(T3,2);
Serial.print(" °C, ");
status = pressure_3.startPressure(3);
if (status != 0)
{
// Wait for the measurement to complete:
delay(status);
status = pressure_3.getPressure(P3,T3);
if (status != 0)
{
Serial.print("P3: ");
Serial.print(P3,2);
Serial.println(" mb, ");
}
else Serial.println("error retrieving pressure measurement\n");
}
else Serial.println("error starting pressure measurement\n");
}
else Serial.println("error retrieving temperature measurement\n");
}
else Serial.println("error starting temperature measurement\n");
Serial.println();
delay(1000);
}
In french:
Bonjour,
j'utilise un i2c multiplexer pour lire les donner de 4 capteurs BMP180. Tout semble correctement branché. J'obtiens de données mais sont erronées.
(voir image) Seul un des capteurs semble donner des valeurs plausibles. J'ai testé les capteurs un par un. Ils donnent des résultats corrects.
J'ai essayé d'ajouter des "delay" dans mon code, me disant que la ligne SDA est peut-être "embouteillée. ça ne change rien.
Est-ce que quelqu'un a une idée?
Merci
Olivier