TCA9548A ESP32-S3 Connection Help

Been trying to connect two OLED screens to an ESP32-S3, however all my Wokwi simulations (both online and in VSCode) seem to keep stalling / hanging when trying to load. I'm not certain what the issue may be at all, as when it does work the 1st OLED (the only one configured atm) is still blank.

Any help would be greatly appreciated, here's the link to the project:
https://wokwi.com/projects/422378501610814465

As well as a link to a solo-OLED reproduction workspace I'm using to try and find the problem
https://wokwi.com/projects/424081868618977281

I moved your topic to a more appropriate forum category @oyavo .

The Nano Family > Nano ESP32 category you chose is only used for discussions directly related to the Arduino Nano ESP32 board.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

This is the second time I've had to ask you this. Please be more careful to behave responsibly. If you won't respond to polite requests then we would have to resort to an account suspension to get your attention, and I'm sure neither of us wants that.

Thanks in advance for your cooperation.

You need Wire.begin() before calling the TCA9548A() function.

Wire.begin() placed before each function call and Wire.begin(0x3C) at any point give me the following error:

Build server failure: SyntaxError: Failed to execute 'json' on 'Response': Unexpected end of JSON input

Wire.begin() once prior to any function call gives no error (and is already present in the example I've been working on here), but the screen still displays nothing.

I'm not sure how accurate the wokwi simulation is, the TCA9548A should be powered by 3.3V since the ESP32 and the displays should both operate at that voltage.

The Wire.begin() is only needed before the first use of the TCA9548A in setup(). Without the multiplexer, the Adafruit display library calls Wire.begin() internally, but you need I2C to communicate with the multiplexer before initialing the display.

Oh I have no idea if the simulation is fully accurate, I put it together myself from some other examples to try and focus the issue. That being said, swapping all voltages to 3.3V (which my main project is using) still does not resolve the issue unfortunately even in conjunction with Wire.begin() once at the beginning of setup

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

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

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

There appear to be some TCA9548A libraries available, but when including them I get the "Failed to execute 'json' on 'Response' error once more.

Is there perhaps an issue with the data in tca9548a.chip.c? I'm not too experienced with these types of connections.

I'm not familiar with the wokwi simulation of the TCA9548A, so no knowledge of the chip.c file.

The following sketch runs successfully on a Wemos D1 R32 with four SSD1306 displays, so the basics of your code looks ok. (the BIN0_x.h files only contain arrays definitions for bitmap images, no executable code):

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "BIN0_1.h"
#include "BIN0_2.h"
#include "BIN0_3.h"
#include "BIN0_4.h"
#define larguraDisplay 128
#define alturaDisplay 64
#define OLED_reset -1
#define FRAME_DELAY (42)
#define FRAME_WIDTH (64)
#define FRAME_HEIGHT (64)
#define FRAME_COUNT (sizeof(frames) / sizeof(frames[0]))
Adafruit_SSD1306 display(larguraDisplay, alturaDisplay, &Wire, OLED_reset);

const int frame_count_1 = sizeof(BIN0_1) / sizeof(BIN0_1[0]);
const int frame_count_2 = sizeof(BIN0_2) / sizeof(BIN0_2[0]);
const int frame_count_3 = sizeof(BIN0_3) / sizeof(BIN0_3[0]);
const int frame_count_4 = sizeof(BIN0_4) / sizeof(BIN0_4[0]);

int frame_1 = 0;
int frame_2 = 0;
int frame_3 = 0;
int frame_4 = 0;

void TCA9548A(uint8_t bus) { //activate particular channel
  Wire.beginTransmission(0x70);  // TCA9548A address is 0x70
  Wire.write(1 << bus);          // send byte to select bus
  Wire.endTransmission();
}

void setup() {
  Serial.begin(115200);
  Wire.begin();
  Wire.setClock(400000);
  TCA9548A(0);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  TCA9548A(1);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  TCA9548A(2);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  TCA9548A(3);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
}

void loop() {
  uint32_t startMillis = millis();
  TCA9548A(0);
  display.clearDisplay();
  display.drawBitmap(0, 0, BIN0_1[frame_1], 64, 64, WHITE);
  display.display();
  frame_1 = (frame_1 + 1) % frame_count_1;

  TCA9548A(1);
  display.clearDisplay();
  display.drawBitmap(0, 0, BIN0_2[frame_2], 64, 64, WHITE);
  display.display();
  frame_2 = (frame_2 + 1) % frame_count_2;

  TCA9548A(2);
  display.clearDisplay();
  display.drawBitmap(0, 0, BIN0_3[frame_3], 64, 64, WHITE);
  display.display();
  frame_3 = (frame_3 + 1) % frame_count_3;

  TCA9548A(3);
  display.clearDisplay();
  display.drawBitmap(0, 0, BIN0_4[frame_4], 64, 64, WHITE);
  display.display();
  frame_4 = (frame_4 + 1) % frame_count_4;

  uint32_t stopMillis = millis();
  Serial.println(stopMillis - startMillis);
}

I see, thank you for letting me know. Do you happen to know of any other similar schematic testing environments besides wokwi worth trying my sketch on? This project is my first time soldering so I'm hoping to be absolutely certain everything should work prior to going ahead and putting things together.

Wokwi has a built in multiplexer (HP4067) but I don't get the impression it would be a straight 1-to-1 conversion of code implemented for TCA9548A.

I'm not familiar with any other simulators, there is TinkerCad but I've never used it.

If you only need two displays, the multiplexer is not needed if the display has the option to change the I2C address from 0x3C to 0x3D. That lets you run one display at 0x3C and the other at 0x3D, with separate instances of Adafruit_SSD1306 for each display.

There is no guarantee that a sketch that works in wokwi will actually work in the real world. Those simulators basically only test functionality.

This sketch works on physical hardware (Wimos D1 R32), with the problem that you did not clear the buffer between displays, so the 2nd display shows the '1' and '2' overlaid on each other.

Have not tested the first sketch, I don't have time at the moment to strip out all the USBHIDKeyboard code since my board does not have a direct USB connection.

That's very good to hear, thanks for letting me know. Does the buff need to cleared each time you swap between displays? The buffer is cleared after each display initialization, but not after being written to at the moment

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

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

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

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

Generally the buffer needs to be cleared when changing displays, most of the fonts are transparent, so they are written on top of whatever is already in the display buffer. The exception is the default font, which has an option to specify the background color to overwrite the previous display image with.

After adding Wire.begin() at the start of setup(), this sketch displays properly on real hardware, and works in Wokwi if the multiplexer is removed and the display is connected directly to the I2C pins of the ESP32. I've search on google for other Wokwi simulations using the ESP32 with a TCA9548A, and all that I have found will not display anything on the OLED, so it may be a problem with the Wokwi code for the TCA9548A.

Great to know, thanks really appreciate it. I'll go ahead and proceed with soldering and work from there, thanks! If I had to guess, probably has to do with it being a custom chip on Wokwi rather than built in.

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