Multiplexer TCA9548A not changing channels

Hi, i have two seeed studio oled displays connected to a TCA9548A to an arduino nano esp32. the problem is that all of my display is going to the screen in the port 1, even though I select port 0. I have no idea what's causing this or how to fix it.


* List item

#include <Wire.h>
#include <Arduino.h>
#include <U8g2lib.h>


U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2a(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);   // All Boards without Reset of the Display
U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2b(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);

// Select I2C BUS
void TCA9548A(uint8_t bus){
  Wire.beginTransmission(0x70);  // TCA9548A address
  Wire.write(1 << bus);          // send byte to select bus
  Wire.endTransmission();
  Serial.println(bus);
}

void NOTCA9548A(){
  Wire.beginTransmission(0x70);
  Wire.write(0);  // no channel selected
  Wire.endTransmission();
}
 
void setup() {
  Serial.begin(9600);
  Serial.println("starting");

  // Start I2C communication with the Multiplexer
  Wire.begin();

  TCA9548A(1);
  u8g2a.begin();
  NOTCA9548A();

  TCA9548A(0);
  u8g2b.begin();
  NOTCA9548A();
  // Write to OLED on bus number 0

}
 
void loop() {

  TCA9548A(1);
  delay(100);
  u8g2a.clearBuffer();
  u8g2a.setFont(u8g2_font_ncenB08_tr);
  u8g2a.drawStr(32,30,"I am \n");
  u8g2a.drawStr(32,45,"Screen 1 \n");
  u8g2a.sendBuffer();
  delay(1000);  
  NOTCA9548A();

  TCA9548A(0);
  delay(100);
  u8g2b.clearBuffer();
  u8g2b.setFont(u8g2_font_ncenB08_tr);
  u8g2b.drawStr(32,30,"I am  \n");
  u8g2b.drawStr(32,45,"Screen 2 \n");
  u8g2b.sendBuffer();
  delay(1000); 
  NOTCA9548A();
  
}

so the problem is that the oled connected to the port 1 switches between saying screen 1 and screen 2 and the oled connected to port 0 stays blank

I can't see a problem in your code.

NOTCA9548A() is not needed, or should not be. You can remove it and try again, but I don't really think it would fix the problem.

Please post some bright, sharp photos, taken from above the circuit, so that every wire can be traced.

What is the sense of switching all channels off before selecting another one?

Please show a schematic of your wiring.

Try this to see what appears on serial monitor:

void TCA9548A(uint8_t bus){
  Wire.beginTransmission(0x70);  // TCA9548A address
  Wire.write(1 << bus);          // send byte to select bus
  int result = Wire.endTransmission();
  Serial.printf("channel=%i result=%i\n", bus, result);
}

We are hoping for "result=0"

No point. But it should not cause a problem, either.

Also try running the i2c scanner, from the examples menu in the IDE.

It should pick up only the multiplexer on address 0x70.


Sorry it’s a bit hard to get a good image of the wires

I'm getting result = 5 for both bus

See about half way to 2/3 of the way down the page --

TCA9548A I2C Multiplexer: ESP32, ESP8266, Arduino | Random Nerd Tutorials

Your circuit is a mess. That's why it doesn't work.

You should plug the multiplexer and the OLEDs into the breadboard. That's what breadboards are for. If the breadboard isn't big enough, get a bigger one, or get several the same and clip them together to make one that is big enough.

Screenshot_20240802-200045-030

This looks to me like the PCB headers have been pushed into the module (probably because there wasn't enough space on the breadboard). Are these headers soldered to the module? I guess not. This will not work. PCB headers must be soldered to the module. Pushing them into the bare holes will never make a reliable connection on all the pins at the same time.

Are the PCB pins soldered to the ESP32, or are they also pushed into the bare holes?

In summary:

  • Get a breadboard big enough for all your components. Clip multiple breadboards together if necessary.
  • Solder PCB headers to all modules as needed.
  • Check all Dupont cables with a multimeter before using them. They are notoriously unreliable.
  • Use solid-core hookup wire, cut to length and laid flat on the breadboard, in preference to Dupont wires. This type of wire can also unreliable, but you can easily tell when it is broken because it is suddenly no longer rigid.

This is what good solder joints should look like:
Soldering_Results