Trouble using multiple TCA9548A and SSD1306 OLED

Im working on a project where I need to display different static lines of text to 28 SSD1306 OLED screens using a TCA9548A Multiplexer. Ive found the following code from another forum that works great when using one multiplexer but have not have any luck getting two multiplexers to update successfully. Im currently only working with those two adresses and 4 screens (2per multiplexer) to minimize complexity and power requirments. any help with how to update the code to be able to use multiple TCAs would be helpful.

I have ruled out some of the likley issues such as verifying SDA and SCL lines are bussed correctly and testing each OLED screen individually to make sure they work and have verified that the adressing is correct as well as wired each TCA board to the 0x71 adress and have sucessfully managed to update screens to that adress. One thing that im not sure if it makes a huge difference when using multiple TCA boards is the use of floating pins when addressing particularly if only using two. I wired the 0x70 adress all the ground and for 0x71 wired A0 to VCC and A1 and A2 to GND. Though i dont have any resistors to any of the address pins installed (didint think i needed them when only using two adress boards)

#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

// 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.print(bus);
}
 
void setup() {
  Serial.begin(115200);

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

  // Init OLED display on bus number 2
  TCA9548A(2);
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  } 
  // Clear the buffer
  display.clearDisplay();

  // Init OLED display on bus number 3
  TCA9548A(3);
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  } 
  // Clear the buffer
  display.clearDisplay();

  // Init OLED display on bus number 4
  TCA9548A(4);
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  } 
  // Clear the buffer
  display.clearDisplay();

  // Init OLED display on bus number 5
  TCA9548A(5);
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  } 
  // Clear the buffer
  display.clearDisplay();

  // Write to OLED on bus number 2
  TCA9548A(2);
  display.clearDisplay();
  display.setTextSize(8);
  display.setTextColor(WHITE);
  display.setCursor(45, 10);
  // Display static text
  display.println("1");
  display.display(); 

  // Write to OLED on bus number 3
  TCA9548A(3);
  display.clearDisplay();
  display.setTextSize(8);
  display.setTextColor(WHITE);
  display.setCursor(45, 10);
  // Display static text
  display.println("2");
  display.display(); 
  
  // Write to OLED on bus number 4
  TCA9548A(4);
  display.clearDisplay();
  display.setTextSize(8);
  display.setTextColor(WHITE);
  display.setCursor(45, 10);
  // Display static text
  display.println("3");
  display.display(); 
  
  // Write to OLED on bus number 5
  TCA9548A(5);
  display.clearDisplay();
  display.setTextSize(8);
  display.setTextColor(WHITE);
  display.setCursor(45, 10);
  // Display static text
  display.println("4");
  display.display(); 
}
 
void loop() {
  
}

Thanks in advance for any help or refrences

Please show the code you are using for two multiplexers, that does not work.

One common mistake with multiple multiplexers is that you need to turn off all eight channels of one multiplexer when using the other multiplexer. The code you posted does not have an obvious method of doing that.

1 Like

Post an annotated schematic showing how you have wired this.

Heres the modified code i attempted but im having issues with 3 of the 4 cahannels im using cycling together when using the 70 and 71 adress. Ive read some stuff about using 0x00 but im not sure how to incoorporate it

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

// Select I2C BUS on a specific TCA
void TCA9548A(uint8_t multiplexerAddr, uint8_t channelMask) {
  Wire.beginTransmission(multiplexerAddr); // TCA9548A address
  Wire.write(channelMask);                 // Send byte to select bus
  Wire.endTransmission();
  Serial.print("Multiplexer ");
  Serial.print(multiplexerAddr, HEX);
  Serial.print(" Channel Mask ");
  Serial.println(channelMask, BIN);
}

void setup() {
  Serial.begin(115200);

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

  // Init OLED display on channels 0 and 1 (TCA 0x70)
  TCA9548A(0x70, 0x01); // Enable channel 0
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed on channel 0 (0x70)"));
    for (;;);
  }
  display.clearDisplay();

  TCA9548A(0x70, 0x02); // Enable channel 1
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed on channel 1 (0x70)"));
    for (;;);
  }
  display.clearDisplay();

  // Init OLED display on channels 2 and 3 (TCA 0x71)
  TCA9548A(0x71, 0x04); // Enable channel 2
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed on channel 2 (0x71)"));
    for (;;);
  }
  display.clearDisplay();

  TCA9548A(0x71, 0x10); // Enable channel 3
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed on channel 3 (0x71)"));
    for (;;);
  }
  display.clearDisplay();

  // Write to OLED on channel 0 at 0x70
  TCA9548A(0x70, 0x01); // Switch to channel 0
  display.clearDisplay();
  display.setTextSize(8);
  display.setTextColor(WHITE);
  display.setCursor(45, 10);
  display.println("9");
  display.display();
delay(2000);
  // Write to OLED on channel 1 at 0x70
  TCA9548A(0x70, 0x02); // Switch to channel 1
  display.clearDisplay();
  display.setTextSize(8);
  display.setTextColor(WHITE);
  display.setCursor(45, 10);
  display.println("8");
  display.display();
delay(2000);
  // Write to OLED on channel 2 at 0x70
  TCA9548A(0x71, 0x04); // Switch to channel 3
  display.clearDisplay();
  display.setTextSize(8);
  display.setTextColor(WHITE);
  display.setCursor(45, 10);
  display.println("7");
  display.display();
 delay(2000);
  // Write to OLED on channel 3 at 0x70
  TCA9548A(0x71, 0x10); // Switch to channel 4
  display.clearDisplay();
  display.setTextSize(8);
  display.setTextColor(WHITE);
  display.setCursor(45, 10);
  display.println("6");
  display.display();
delay(2000);
}

void loop() {
  // Empty loop
}

Start with getting the channel numbers correct:

TCA9548A(0x70, 0x01); // Enable channel 0
TCA9548A(0x70, 0x02); // Enable channel 1
TCA9548A(0x70, 0x04); // Enable channel 2
TCA9548A(0x70, 0x08); // Enable channel 3
TCA9548A(0x70, 0x10); // Enable channel 4
TCA9548A(0x70, 0x20); // Enable channel 5
TCA9548A(0x70, 0x40); // Enable channel 6
TCA9548A(0x70, 0x80); // Enable channel 7

Then the code to disable all channels:

TCA9548A(0x70, 0x00); // Disable all channels

Whenever you enable a channel on one of the multiplexers, the other multiplexer must have all its channels disabled, otherwise you will have two SSD1306 displays connected to the I2C bus at the same time, one from each multiplexer.

Ive updated the code (its terribly repetetive and long but it works...kind of). I can get all channels on the first 3 addresses to display perfectly thruogh number 24 but when it comes to channel 4 it only displays the number 28 (which is the last screen) and skips 25-27. is there any modifications i need to do to have the final TCA only write to channels 0-3 (for numbers 25-28)? The adress is wired correctly and Ive verified that the SCL and SDA lines are connected correctly.

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>


#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display_OLED_1(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_SSD1306 display_OLED_2(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_SSD1306 display_OLED_3(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_SSD1306 display_OLED_4(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_SSD1306 display_OLED_5(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_SSD1306 display_OLED_6(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_SSD1306 display_OLED_7(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_SSD1306 display_OLED_8(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_SSD1306 display_OLED_9(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_SSD1306 display_OLED_10(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_SSD1306 display_OLED_11(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_SSD1306 display_OLED_12(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_SSD1306 display_OLED_13(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_SSD1306 display_OLED_14(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_SSD1306 display_OLED_15(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_SSD1306 display_OLED_16(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_SSD1306 display_OLED_17(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_SSD1306 display_OLED_18(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_SSD1306 display_OLED_19(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_SSD1306 display_OLED_20(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_SSD1306 display_OLED_21(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_SSD1306 display_OLED_22(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_SSD1306 display_OLED_23(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_SSD1306 display_OLED_24(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_SSD1306 display_OLED_25(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_SSD1306 display_OLED_26(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_SSD1306 display_OLED_27(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_SSD1306 display_OLED_28(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);



#define TCAADDR1 0x70
#define TCAADDR2 0x71
#define TCAADDR3 0x72
#define TCAADDR4 0x73


//Selects the channels and address of the TCA9548A for tcaselect1-4
void tcaselect1(uint8_t i) {
  if (i > 7) return;
  Wire.beginTransmission(TCAADDR1);
  Wire.write(1 << i);
  Wire.endTransmission();
}

void tcaselect2(uint8_t i) {
  if (i > 7) return;
  Wire.beginTransmission(TCAADDR2);
  Wire.write(1 << i);
  Wire.endTransmission();
}

void tcaselect3(uint8_t i) {
  if (i > 7) return;
  Wire.beginTransmission(TCAADDR3);
  Wire.write(1 << i);
  Wire.endTransmission();
}

void tcaselect4(uint8_t i) {
  if (i > 7 ) return; 
  Wire.beginTransmission(TCAADDR4);
  Wire.write(1<<1);
  Wire.endTransmission();
}


//Disables the channels and address of the TCA9548A for tcaselect1-4
void tcaselect1_DISABLE() {
  Wire.beginTransmission(TCAADDR1);
  Wire.write(0);  // no channel selected
  Wire.endTransmission();
}

void tcaselect2_DISABLE() {
  Wire.beginTransmission(TCAADDR2);
  Wire.write(0);  // no channel selected
  Wire.endTransmission();
}

void tcaselect3_DISABLE() {
  Wire.beginTransmission(TCAADDR3);
  Wire.write(0);  // no channel selected
  Wire.endTransmission();
}

void tcaselect4_DISABLE() {
  Wire.beginTransmission(TCAADDR4);
  Wire.write(0);  // no channel selected
  Wire.endTransmission();
}


//Establish communications baud rate 115200
void setup() {
  Serial.begin(115200);

  Wire.begin();  // Start I2C communication with the multiplexer 
//IDK if this is actually needed TBD
 tcaselect2_DISABLE(); //Disable TCAADDR2
 tcaselect3_DISABLE(); //Disable TCAADDR3
 tcaselect4_DISABLE(); //Disable TCAADDR4

//Channel 0 OLED_1 TCAADDR1
tcaselect1(0); 
    if (!display_OLED_1.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("display_OLED_1 allocation failed"));
    //for (;;);
    }
  display_OLED_1.clearDisplay();

//Channel 1 OLED_2 TCAADDR1
tcaselect1(1); 
    if (!display_OLED_2.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("display_OLED_2 allocation failed"));
    //for (;;);
    }
  display_OLED_2.clearDisplay();

//Channel 2 OLED_3 TCAADDR1
tcaselect1(2); 
    if (!display_OLED_3.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("display_OLED_3 allocation failed"));
    //for (;;);
    }
  display_OLED_3.clearDisplay();

//Channel 3 OLED_4 TCAADDR1
tcaselect1(3); 
    if (!display_OLED_4.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("display_OLED_4 allocation failed"));
    //for (;;);
    }
  display_OLED_4.clearDisplay();

//Channel 4 OLED_5 TCAADDR1
tcaselect1(4); 
    if (!display_OLED_5.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("display_OLED_5 allocation failed"));
    //for (;;);
    }
  display_OLED_5.clearDisplay();

//Channel 5 OLED_6 TCAADDR1
tcaselect1(5); 
    if (!display_OLED_6.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("display_OLED_6 allocation failed"));
    //for (;;);
    }
  display_OLED_6.clearDisplay();

//Channel 6 OLED_7 TCAADDR1
tcaselect1(6); 
    if (!display_OLED_7.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("display_OLED_7 allocation failed"));
    //for (;;);
    }
  display_OLED_7.clearDisplay(); 

//Channel 7 OLED_8 TCAADDR1
tcaselect1(7); 
    if (!display_OLED_8.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("display_OLED_8 allocation failed"));
    //for (;;);
    }
  display_OLED_8.clearDisplay(); 



  tcaselect1(0);
  display_OLED_1.setTextSize(8);
  display_OLED_1.setTextColor(WHITE);
  display_OLED_1.setCursor(45, 10);
  display_OLED_1.println("1");
  display_OLED_1.display();

  tcaselect1(1);
  display_OLED_2.setTextSize(8);
  display_OLED_2.setTextColor(WHITE);
  display_OLED_2.setCursor(45, 10);
  display_OLED_2.println("2");
  display_OLED_2.display();

   tcaselect1(2);
  display_OLED_3.setTextSize(8);
  display_OLED_3.setTextColor(WHITE);
  display_OLED_3.setCursor(45, 10);
  display_OLED_3.println("3");
  display_OLED_3.display();
  
   tcaselect1(3);
  display_OLED_4.setTextSize(8);
  display_OLED_4.setTextColor(WHITE);
  display_OLED_4.setCursor(45, 10);
  display_OLED_4.println("4");
  display_OLED_4.display();

 tcaselect1(4);
  display_OLED_5.setTextSize(8);
  display_OLED_5.setTextColor(WHITE);
  display_OLED_5.setCursor(45, 10);
  display_OLED_5.println("5");
  display_OLED_5.display();

   tcaselect1(5);
  display_OLED_6.setTextSize(8);
  display_OLED_6.setTextColor(WHITE);
  display_OLED_6.setCursor(45, 10);
  display_OLED_6.println("6");
  display_OLED_6.display();

     tcaselect1(6);
  display_OLED_7.setTextSize(8);
  display_OLED_7.setTextColor(WHITE);
  display_OLED_7.setCursor(45, 10);
  display_OLED_7.println("7");
  display_OLED_7.display();

     tcaselect1(7);
  display_OLED_8.setTextSize(8);
  display_OLED_8.setTextColor(WHITE);
  display_OLED_8.setCursor(45, 10);
  display_OLED_8.println("8");
  display_OLED_8.display();


tcaselect1_DISABLE();

//Channel 0 OLED_9 TCAADDR2
tcaselect2(0); 
    if (!display_OLED_9.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("display_OLED_9 allocation failed"));
    //for (;;);
    }
  display_OLED_9.clearDisplay();

//Channel 1 OLED_10 TCAADDR2
tcaselect2(1); 
    if (!display_OLED_10.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("display_OLED_10 allocation failed"));
    //for (;;);
    }
  display_OLED_10.clearDisplay();

//Channel 2 OLED_11 TCAADDR2
  tcaselect2(2); 
    if (!display_OLED_11.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("display_OLED_11 allocation failed"));
    //for (;;);
    }
  display_OLED_11.clearDisplay();

//Channel 3 OLED_12 TCAADDR2
  tcaselect2(3); 
    if (!display_OLED_12.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("display_OLED_12 allocation failed"));
    //for (;;);
    }
  display_OLED_12.clearDisplay();

//Channel 4 OLED_13 TCAADDR2
  tcaselect2(4); 
    if (!display_OLED_13.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("display_OLED_13 allocation failed"));
    //for (;;);
    }
  display_OLED_13.clearDisplay();

//Channel 5 OLED_14 TCAADDR2
  tcaselect2(5); 
    if (!display_OLED_14.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("display_OLED_14 allocation failed"));
    //for (;;);
    }
  display_OLED_14.clearDisplay();

//Channel 6 OLED_15 TCAADDR2
  tcaselect2(6); 
    if (!display_OLED_15.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("display_OLED_15 allocation failed"));
    //for (;;);
    }
  display_OLED_15.clearDisplay();

//Channel 7 OLED_16 TCAADDR2
  tcaselect2(7); 
    if (!display_OLED_16.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("display_OLED_16 allocation failed"));
    //for (;;);
    }
  display_OLED_16.clearDisplay();


tcaselect2(0);
  display_OLED_9.setTextSize(8);
  display_OLED_9.setTextColor(WHITE);
  display_OLED_9.setCursor(45, 10);
  display_OLED_9.println("9");
  display_OLED_9.display();

tcaselect2(1);
  display_OLED_10.setTextSize(2);
  display_OLED_10.setTextColor(WHITE);
  display_OLED_10.setCursor(45, 10);
  display_OLED_10.println("10");
  display_OLED_10.display();

tcaselect2(2);
  display_OLED_11.setTextSize(2);
  display_OLED_11.setTextColor(WHITE);
  display_OLED_11.setCursor(45, 10);
  display_OLED_11.println("11");
  display_OLED_11.display();

tcaselect2(3);
  display_OLED_12.setTextSize(2);
  display_OLED_12.setTextColor(WHITE);
  display_OLED_12.setCursor(45, 10);
  display_OLED_12.println("12");
  display_OLED_12.display();

tcaselect2(4);
  display_OLED_13.setTextSize(2);
  display_OLED_13.setTextColor(WHITE);
  display_OLED_13.setCursor(45, 10);
  display_OLED_13.println("13");
  display_OLED_13.display();

tcaselect2(5);
  display_OLED_14.setTextSize(2);
  display_OLED_14.setTextColor(WHITE);
  display_OLED_14.setCursor(45, 10);
  display_OLED_14.println("14");
  display_OLED_14.display();

tcaselect2(6);
  display_OLED_15.setTextSize(2);
  display_OLED_15.setTextColor(WHITE);
  display_OLED_15.setCursor(45, 10);
  display_OLED_15.println("15");
  display_OLED_15.display();

tcaselect2(7);
  display_OLED_16.setTextSize(2);
  display_OLED_16.setTextColor(WHITE);
  display_OLED_16.setCursor(45, 10);
  display_OLED_16.println("16");
  display_OLED_16.display();

tcaselect2_DISABLE(); 

//Channel 0 OLED_17 TCAADDR3
tcaselect3(0); 
    if (!display_OLED_17.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("display_OLED_17 allocation failed"));
    //for (;;);
    }
  display_OLED_17.clearDisplay();

//Channel 1 OLED_18 TCAADDR3
tcaselect3(1); 
    if (!display_OLED_18.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("display_OLED_18 allocation failed"));
    //for (;;);
    }
  display_OLED_18.clearDisplay();

//Channel 2 OLED_19 TCAADDR3
tcaselect3(2); 
    if (!display_OLED_19.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("display_OLED_19 allocation failed"));
    //for (;;);
    }
  display_OLED_19.clearDisplay();

//Channel 3 OLED_20 TCAADDR3
tcaselect3(3); 
    if (!display_OLED_20.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("display_OLED_20 allocation failed"));
    //for (;;);
    }
  display_OLED_20.clearDisplay();

//Channel 4 OLED_21 TCAADDR3
tcaselect3(4); 
    if (!display_OLED_21.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("display_OLED_21 allocation failed"));
    //for (;;);
    }
  display_OLED_21.clearDisplay(); 

//Channel 5 OLED_22 TCAADDR3
tcaselect3(5); 
    if (!display_OLED_22.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("display_OLED_22 allocation failed"));
    //for (;;);
    }
  display_OLED_22.clearDisplay(); 

//Channel 6 OLED_23 TCAADDR3
tcaselect3(6); 
    if (!display_OLED_23.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("display_OLED_23 allocation failed"));
    //for (;;);
    }
  display_OLED_23.clearDisplay();

//Channel 7 OLED_24 TCAADDR3
tcaselect3(7); 
    if (!display_OLED_24.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("display_OLED_24 allocation failed"));
    //for (;;);
    }
  display_OLED_24.clearDisplay();

tcaselect3(0);
  display_OLED_17.setTextSize(2);
  display_OLED_17.setTextColor(WHITE);
  display_OLED_17.setCursor(45, 10);
  display_OLED_17.println("17");
  display_OLED_17.display();

tcaselect3(1);
  display_OLED_18.setTextSize(2);
  display_OLED_18.setTextColor(WHITE);
  display_OLED_18.setCursor(45, 10);
  display_OLED_18.println("18");
  display_OLED_18.display();  

tcaselect3(2);
  display_OLED_19.setTextSize(2);
  display_OLED_19.setTextColor(WHITE);
  display_OLED_19.setCursor(45, 10);
  display_OLED_19.println("19");
  display_OLED_19.display();

tcaselect3(3);
  display_OLED_20.setTextSize(2);
  display_OLED_20.setTextColor(WHITE);
  display_OLED_20.setCursor(45, 10);
  display_OLED_20.println("20");
  display_OLED_20.display();  

tcaselect3(4);
  display_OLED_21.setTextSize(2);
  display_OLED_21.setTextColor(WHITE);
  display_OLED_21.setCursor(45, 10);
  display_OLED_21.println("21");
  display_OLED_21.display();

tcaselect3(5);
  display_OLED_22.setTextSize(2);
  display_OLED_22.setTextColor(WHITE);
  display_OLED_22.setCursor(45, 10);
  display_OLED_22.println("22");
  display_OLED_22.display();

tcaselect3(6);
  display_OLED_23.setTextSize(2);
  display_OLED_23.setTextColor(WHITE);
  display_OLED_23.setCursor(45, 10);
  display_OLED_23.println("23");
  display_OLED_23.display();

tcaselect3(7);
  display_OLED_24.setTextSize(2);
  display_OLED_24.setTextColor(WHITE);
  display_OLED_24.setCursor(45, 10);
  display_OLED_24.println("24");
  display_OLED_24.display();

tcaselect3_DISABLE();

tcaselect4(0); 
    if (!display_OLED_25.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("display_OLED_25 allocation failed"));
    //for (;;);
    }
  display_OLED_25.clearDisplay();

tcaselect4(1); 
    if (!display_OLED_26.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("display_OLED_26 allocation failed"));
    //for (;;);
    }
  display_OLED_26.clearDisplay();

tcaselect4(2); 
    if (!display_OLED_27.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("display_OLED_27 allocation failed"));
    //for (;;);
    }
  display_OLED_27.clearDisplay();

tcaselect4(3); 
    if (!display_OLED_28.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("display_OLED_28 allocation failed"));
    //for (;;);
    }
  display_OLED_28.clearDisplay();  
  
tcaselect4(0);
  display_OLED_25.setTextSize(2);
  display_OLED_25.setTextColor(WHITE);
  display_OLED_25.setCursor(45, 10);
  display_OLED_25.println("25");
  display_OLED_25.display();

tcaselect4(1);
  display_OLED_26.setTextSize(2);
  display_OLED_26.setTextColor(WHITE);
  display_OLED_26.setCursor(45, 10);
  display_OLED_26.println("26");
  display_OLED_26.display();

tcaselect4(2);
  display_OLED_27.setTextSize(2);
  display_OLED_27.setTextColor(WHITE);
  display_OLED_27.setCursor(45, 10);
  display_OLED_27.println("27");
  display_OLED_27.display();

tcaselect4(3);
  display_OLED_28.setTextSize(2);
  display_OLED_28.setTextColor(WHITE);
  display_OLED_28.setCursor(45, 10);
  display_OLED_28.println("28");
  display_OLED_28.display();

tcaselect4_DISABLE();

}

void loop() {
  
}

Interesting. 28 instances of Adafruit_SSD1306 means 28K of RAM allocated at runtime. So I assume you're not doing this on an Uno R3, a Nano or the like? I don't see anywhere in this topic where you specify which board you're using.

Have you verified that all the displays work correctly when used individually?

Depending on what you are displaying, you might be able to use one instance of Adafruit_SSD1306 and share the display buffer between all the displays. That does have limitations if you need to retain the previous contents of the display buffer.

You should look into using arrays, that would considerably shorten the code.

your tcaselect4() is not like the others. It never uses the variable i to shift a one during the .write(). It always just shifts it 1 bit.

A much better way would be to have 1 function that figures out which chip to address and which device on that chip to select

// select device 1..28 to match your display_OLED_XX numbering
void tcaselect(uint8_t i) {
  static uint8_t old_addr = 0;  // previous chip so we deselect properly

  uint8_t addr;
  i--;  // put into proper range of 0..27
  if ( i > 27 ) return;

  uint8_t chip = i >> 3;  // integer division by 8 to determine which address to use
  switch ( chip ) {
    case 0: addr = TCAADDR1; break;
    case 1: addr = TCAADDR2; break;
    case 2: addr = TCAADDR3; break;
    case 3: addr = TCAADDR4; break;
  }
  if ( old_addr != addr ) {
    // a different chip was previously addressed, so turn it off
    Wire.beginTransmission(old_addr);
    Wire.write(0);
    Wire.endTransmission();
  }
  i = i % 8;  // 0..7 of chip selected
  Wire.beginTransmission(addr);
  Wire.write(1<<i);
  Wire.endTransmission();

  old_addr = addr;  // remember address for next time
}

This function also remembers which chip was last addressed to avoid unnecessary i2c traffic. Depending on how fast you update all this, the lag can become noticeable if you are doing a lot of writing.

You should also consider learinng how to use arrays. It will vastly improve your life (as far as coding is concerned)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.