two tca9548a

I need to use two multiplexers to control 15 sensors, now I can read 7 sensors, when I change the direction of the tca9548a to read the other 7 sensors I do not know how to select the channels of the second multiplexer.

#include <BH1750.h>
#include <Wire.h>



#define TCAADDR0 0x70
#define TCAADDR1 0x71
BH1750 lightMeter(0x23);


void setup(){

 pinMode(22, OUTPUT);  
 pinMode(23, OUTPUT); 

  
  
 Serial.begin(9600);
 Wire.begin();
 
 lightMeter.begin(BH1750_CONTINUOUS_HIGH_RES_MODE);
 Serial.println(F("BH1750 4 Test"));
 delay(1000);

}

 

void tcaselect(uint8_t sensor, uint8_t canal) { 
  if (canal==TCAADDR0){ //0x70
    
    digitalWrite(22,HIGH);//reset tca9548a
    digitalWrite(23,LOW);
  }
  if (canal==TCAADDR1){ //0x77
    digitalWrite(22,LOW);
    digitalWrite(23,HIGH);
  }
  Wire.beginTransmission(canal);
  Wire.write(1 << sensor);
  Wire.endTransmission();
  delay(1);
  
 
}


void loop() {
 

  tcaselect(0, TCAADDR0);
  uint16_t lux1 = lightMeter.readLightLevel();
  Serial.print("Light1: ");
  Serial.print(lux1);
  Serial.println(" lx");
  delay(2000);

  tcaselect(0, TCAADDR1);
  uint16_t lux2 = lightMeter.readLightLevel();
  Serial.print("Light2: ");
  Serial.print(lux2);
  Serial.println(" lx");
  delay(2000);
  


  }

You are saying that you know how to change the channel of the first multiplexer but you do not know how to change the channel of the second multiplexer? But the two multiplexers are identical. How can you know how to change one but not the other?

What I am saying is that your question did not make sense to me. You must give more information. What sensors are you using? How have you connected them? What code and libraries are you using? Why do you say that 7 + 7 is 15?

Please read the forum guidance on the sticky post to find out what information we need to help you and how you should post it.

EDIT: I see you have added your sketch and you are using bh1750 light sensors. I will read that.

Do you have a sensor on channel 0 of both multiplexers?

I think the problem may be that when you select channel 0 on the second multiplexer, you do not de-select channel 0 on the first multiplexer. The result is that you have two sensors both at address 0x23. When the Arduino transmits to that address, both sensors will respond and the message will be garbled.

Have you changed one of the multiplexer's addresses to 0x71 by applying a solder bridge on the contracts underneith the board (assuming you are using the AdaFruit board or a clone)?

If so, why are you trying to use the reset pins to select one multiplexer or the other? Does that even work?

PaulRB:
You are saying that you know how to change the channel of the first multiplexer but you do not know how to change the channel of the second multiplexer? But the two multiplexers are identical. How can you know how to change one but not the other?

What I am saying is that your question did not make sense to me. You must give more information. What sensors are you using? How have you connected them? What code and libraries are you using? Why do you say that 7 + 7 is 15?

Please read the forum guidance on the sticky post to find out what information we need to help you and how you should post it.

EDIT: I see you have added your sketch and you are using bh1750 light sensors. I will read that.

hi
what I need is to connect 15 sensors, but I'm doing the test with only two, connecting a bh1750 sensor to channel 0 of the first multiplexer and another to the other channel 0 of the second multiplexer

Dibujo2.jpg

PaulRB:
Do you have a sensor on channel 0 of both multiplexers?

I think the problem may be that when you select channel 0 on the second multiplexer, you do not de-select channel 0 on the first multiplexer. The result is that you have two sensors both at address 0x23. When the Arduino transmits to that address, both sensors will respond and the message will be garbled.

I think the same but I do not know how to deselect the first multiplexer sensor, so I use the reset pins of the multiplexers but it does not work.

You need to write a zero to the other multiplexer, so that all its channels are disabled.

Dibujo2.jpg

Maybe try this

void tcaselect(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);
  
 
}

With the above, sensor number will be 0 to 15. Your 2 sensors will be on channels 0 and 8.

Hi,

I know that it is not correct to post in an old topic.

Just to say that i had the same problem with two tca9548a and what PaulRB propose in his last post works to me.

Thank you so much.

You are welcome. I'm glad someone found my help useful.

Hı, ı have a project that have 2x tca9548 to control 16 sensor(sht 20).
I can read 8 sensor with only one multiplexer( tca9548) but ı could'nt find the true code for 16 sensor and connection with 2x tca9548.

I tried;

#define TCAADDR0 0x70
#define TCAADDR1 0x71

but could'nt. Is everybody can help me?