Code Issues Switching I2C Channels; Arduino UNO, Tca9548A and Multiple OLEDs

Hi All,

Long time reader, first time poster. I’m getting into more “above novice” Arduino coding and having troubles. I’ll preface to ask that you please go easy on me :slight_smile: I’m an Engineer, fabricator, and work on electrical systems for a living, but am new to the world of Micro-controllers and coding.

I’m starting the base for a future project that will involve 6 OLED screens, but I’m just trying to understand the Multiplexing first with just two. I can get a single OLED to display text, graphics, etc. no problem via I2C. However, I got a TCA 9548A multiplexer and am trying to get my code to work with poor results. I can make a single OLED turn on by changing all of the addresses to that channel on the TCA9548A, but then all of the text goes to that OLED and is mashed together! I have searched and tried different code for over a week now and am at my wits end. If I put in the code as it is pasted here, usually nothing is displayed at all, unless I try to reset the Arduino several times.

Below is my code, I’m simply trying to get the two OLEDs to display text but am coming up short. Any help? What am I missing? All of the examples I find are for U8GLIB, etc, and I am just trying to stick with the adafruit GFX libraries for now because that’s what I know and it’s easy. I don’t need to introduce more new things into my code before I get multiplexing to work ; )

Thanks in advance!

//Simple code to test the TCA9548A with two OLEDS
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1305.h>
#include <Fonts/FreeSansBold18pt7b.h>
#include <Fonts/FreeSansBold24pt7b.h>
#include <math.h> 

//We then need to define the pins we are using on the Arduino
#define OLED_RESET 9
#define TCAADDR 0x70

void tcaselect(uint8_t i) {
  if (i > 7) return;

  Wire.write(1 << i);

//Initialize the displays
Adafruit_SSD1305 display(OLED_RESET);

void setup(){


  display.clearDisplay(); //Clear the displays and ram
  display.display(); //Show the cleared displays

void loop() {

//-------------Display 0-------------
display.println("OLED 0");

delay (1000);

//-------------Display 1-------------

display.println("OLED 1");

  delay (1000);

Anyone? :slight_smile:

Reading only up until the end of your setup(), it looks like you have only declared one display, and have only initialised one display.

I'm still slogging in the data sheet for the mux, but it seems like your setup should refer to multiple displays between which you switch using tcaselect(…) just like you do in your loop.

Lady Ada

has some example code using two sensors: each gets a declaration and individualised attention in the setup() section.


I'll preface to ask that you please go easy on me :slight_smile:

I will go easy and ask only 10 questions instead of 100 :wink:

  1. Which OLED displays do you use ? Can you give a link to them ? A OLED display has a 3.3V I2C bus unless it has been made compatible with a 5V I2C bus. Some sellers claim their bare OLED display runs at 5V, but that is not true. Some OLED displays are not 100% compatible with the I2C standard, multiplexing them makes everything even worse. Six displays means six times more trouble. You just have bad luck by trying to use six OLED displays. What about six Nextion displays ?

  2. After a while I noticed that you wrote in the title that you use an Arduino Uno. Those Adafruit libraries require a lot of memory. An Arduino Uno with one display makes me already frown. I think that not even two displays is possible. Do you know examples of more than one OLED display ?

  3. How long are the wires ? The total length of SDA and SCL can be 50 cm.

  4. What do you use for the wires for the I2C bus ? I hope it is not a cable. A flat ribbon cable with SDA and SCL next to each other is the worst.

  5. Which TCA9548A module do you use ? Can you give a link to it ?

  6. How is the TCA9548A module powered ? With 5V or 3.3V ? A schematic of your wiring would help.

  7. Do you use pullup resistors ? Where are they located and what is their value ?

  8. Can you show a photo of the project ? So we can see all the wiring.

  9. You create one object with Adafruit_SSD1305 display(OLED_RESET), but you have six displays. How can the library distinguish between those six displays ? Are there examples for multiple displays ?

  10. There is no call to tcaselect() in the setup(). Which displays are you initializing ?