1
\$\begingroup\$

The case is that I have 5 temperature sensors.

I want to connect 4 of them to the first TCA9548A (TCAADDR0), the SDA and SCL busses (from the ports 0 to 3) and connect the fifth one to the second TCA9548A (TCAADDR1).

If the fifth sensor connect is connected to the busses 0 to 3 of TCAADDR1, I receive an incorrect temperature. However, if I connect it the busses No.4 of the TCAADDR1, I receive the correct temperature.

I think the problem is that I can not switch off the TCAADDR0 and only talk to the TCAADDR1. On the other hand, if I connect A0 of the TCAADDR1 to the 5V, I have 3 addresses 0x70 0x71 and 0x77. If I don't connect it, I have 0x70 and 0x77. So I decided not to connect A0 to 5V.

This is my program code:

#include <Wire.h>
#include <Adafruit_BMP085.h>
Adafruit_BMP085 bmp;

Adafruit_BMP085 bmp180_0;
Adafruit_BMP085 bmp180_1;
Adafruit_BMP085 bmp180_2;
Adafruit_BMP085 bmp180_3;
Adafruit_BMP085 bmp180_4;

#define TCAADDR0 0x70
#define TCAADDR1 0x77


void tcaselect0(uint8_t sensor) { 
  unsigned int mask = 1 << sensor;
  Wire.beginTransmission(TCAADDR0);
  Wire.write(lowByte(mask));
  Wire.endTransmission();
  Wire.beginTransmission(TCAADDR1);
  Wire.write(highByte(mask));
  Wire.endTransmission();
  delay(1);
}

void tcaselect1(uint8_t sensor) { 
  unsigned int mask = 1 << sensor;
  Wire.beginTransmission(TCAADDR0);
  Wire.write(lowByte(mask));
  Wire.endTransmission();
  Wire.beginTransmission(TCAADDR1);
  Wire.write(highByte(mask));
  Wire.endTransmission();
  delay(1);
}

void setup() {
  Serial.begin(9600);
  Wire.begin();  //enabling the I2C protocol through the Wire.begin()

  //FIRST SENSOR**                
  tcaselect0(0); 
  if (bmp180_0.begin() != 0x60)
  { Serial.print(F("BMP180 Nr.1 detected?\t")); Serial.println(F("No"));}
  else
  { Serial.print(F("BMP180 Nr.1 detected?\t")); Serial.println(F("Yes"));}


  //SECOND SENSOR
  tcaselect0(1); 
  if (bmp180_1.begin() != 0x60)
  { Serial.print(F("BMP180 Nr.2 detected?\t")); Serial.println(F("No"));}
  else
  { Serial.print(F("BMP180 Nr.2 detected?\t")); Serial.println(F("Yes"));}


  //THIRD SENSOR
  tcaselect0(2);  
  if (bmp180_2.begin() != 0x60)
  { Serial.print(F("BMP180 Nr.3 detected?\t")); Serial.println(F("No"));}
  else
  { Serial.print(F("BMP180 Nr.3 detected?\t")); Serial.println(F("Yes"));}


  //FOURTH SENSOR
  tcaselect0(3);  
  if (bmp180_3.begin() != 0x60)
  { Serial.print(F("BMP180 Nr.4 detected?\t")); Serial.println(F("No"));}
  else
  { Serial.print(F("BMP180 Nr.4 detected?\t")); Serial.println(F("Yes"));}



Wire.beginTransmission(TCAADDR0);
Wire.write(0);
Wire.endTransmission();

  //*FIFTH SENSOR
  tcaselect1(4);  
  if (bmp180_4.begin() != 0x60)
  { Serial.print(F("BMP180 Nr.5 detected?\t")); Serial.println(F("No"));}
  else
  { Serial.print(F("BMP180 Nr.5 detected?\t")); Serial.println(F("Yes"));}

  Serial.println();
  Serial.println(F("##############################"));            //30-times #
  Serial.println(F("Initialization Finished"));
  Serial.println(F("##############################"));            //30-times # 
  Serial.println();
  Serial.println();

}

void loop() 
{

  //SENSOR-FIRST
    tcaselect0(0);
    Serial.println("*****SENSOR NO.1***** ");
    Serial.print("Temperature = ");
    Serial.print(bmp180_0.readTemperature());
    Serial.println(" *C");

//*SENSOR-SECOND
    tcaselect0(1);
    Serial.println("*****SENSOR NO.2***** ");
    Serial.print("Temperature = ");
    Serial.print(bmp180_1.readTemperature());
    Serial.println(" *C");

//**SENSOR-THIRD
    tcaselect0(2);
     Serial.println("*****SENSOR NO.3***** ");
    Serial.print("Temperature = ");
    Serial.print(bmp180_2.readTemperature());
    Serial.println(" *C");

//*SENSOR-FOURTH
    tcaselect0(3);
     Serial.println("*****SENSOR NO.4***** ");
    Serial.print("Temperature = ");
    Serial.print(bmp180_3.readTemperature());
    Serial.println(" *C");


Wire.beginTransmission(TCAADDR0);
Wire.write(0);
Wire.endTransmission();


//*SENSOR-FIFTH
    tcaselect1(4);
     Serial.println("*****SENSOR NO.5***** ");
    Serial.print("Temperature = ");
    Serial.print(bmp180_4.readTemperature());
    Serial.println(" *C");


    Serial.println();
    delay(2000);

}
\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

The TCA9548A has three address pins, A0-A2 which let you set the address of the mux. Therefore, you can place two of them on your main buss, at different addresses (for example, 0x70 and 0x71). I’d place 5 of your sensors on each mux.

To switch between mixes, first write to the first mux, disabling all channels and then write to the second mux, enabling the selected channel. This could be generalized as always disabling the existing channel before enabling the new channel. You could create a table, indexed by the sensor number, containing the addresses of the mux and the value to write into the mux register.

\$\endgroup\$
3
  • \$\begingroup\$ thanks for your comments. I could not solve it yet The project that I am doing is that I have 5 temperature sensors and I connected 4 of them to the first mux (SD & SC 0-1-2-3). The second mux is connected to the (SD & SC 5) first mux. I also connected the fifth sensor to the SD & SC 4 of the first mux. A0, A1 and A2 of the second mux are connected to the 5v. The problem by the above connections and the below code is that it just gives me the temperature from the first 4 sensors connected to the first mux but not the fifth one connected to the second mux. \$\endgroup\$
    – Behnam
    Aug 13, 2019 at 10:19
  • \$\begingroup\$ @Behnam Your comments about how things are connected are unclear. Please edit your original question to add a rough schematic. Also, I don’t see any code (please try to post the simplest code to reproduce the problem). \$\endgroup\$
    – DoxyLover
    Aug 13, 2019 at 11:36
  • \$\begingroup\$ I edited the main question and I have uploaded the codes \$\endgroup\$
    – Behnam
    Aug 13, 2019 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.