U8g2 OLED multiplexing with TCA9548A

Hi all, I am trying to get 5 u8g2 0.66" OLEDs to work using one TCA9548A board. I can get a single one to print OK but when I come to try and get them to work with the multiplexer I am getting everything to compile OK but get nothing displayed. I know the hardware works because I have tested that out with a known working sketch so I am sure it is down to my poor coding

This is what I have so far, and I have tried it also without the second set of curly brackets between multiplexer instance callouts

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



#define TCA9548A 0x70
void tcaselect(uint8_t i) {
  if (i > 7) return;

  Wire.beginTransmission(TCA9548A);
  Wire.write(1 << i);
  Wire.endTransmission();
}

U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R3, /* clock=*/SCL, /* data=*/SDA, /* reset=*/U8X8_PIN_NONE);  // All Boards without Reset of the Display R3 refers to 270 deg text rotation


void setup() {

  for (int i = 0; i <= 7; i++) {
    tcaselect(i);
    u8g2.begin();
    Wire.begin();
  }

  {
    tcaselect(2);  //multiplex the required OLED
    u8g2.clearBuffer();

    u8g2.setFont(u8g2_font_ncenB08_tr);
    u8g2.drawStr(20, 50, "2");  // 0 left, 0 top max appx 100
    u8g2.sendBuffer();
    delay(1000);
  }
  {
    tcaselect(3);  //multiplex the required OLED
    u8g2.clearBuffer();
    u8g2.setFont(u8g2_font_ncenB08_tr);
    u8g2.drawStr(20, 50, "3");  // 0 left, 0 top max appx 100
    u8g2.sendBuffer();
    delay(1000);
  }
  {
    tcaselect(4);  //multiplex the required OLED
    u8g2.clearBuffer();
    u8g2.setFont(u8g2_font_ncenB08_tr);
    u8g2.drawStr(20, 50, "4");  // 0 left, 0 top max appx 100
    u8g2.sendBuffer();
    delay(1000);
  }
  {
    tcaselect(5);  //multiplex the required OLED
    u8g2.clearBuffer();
    u8g2.setFont(u8g2_font_ncenB08_tr);
    u8g2.drawStr(20, 50, "5");  // 0 left, 0 top max appx 100
    u8g2.sendBuffer();
    delay(1000);
  }
  {
    tcaselect(6);  //multiplex the required OLED
    u8g2.clearBuffer();
    u8g2.setFont(u8g2_font_ncenB08_tr);
    u8g2.drawStr(20, 50, "6");  // 0 left, 0 top max appx 100
    u8g2.sendBuffer();
    delay(1000);
  }
  {
    tcaselect(7);  //multiplex the required OLED
    u8g2.clearBuffer();
    u8g2.setFont(u8g2_font_ncenB08_tr);
    u8g2.drawStr(20, 50, "7");  // 0 left, 0 top max appx 100
    u8g2.sendBuffer();
    delay(1000);
  }
}
void loop(void) {
}

What have I done wrong?

Cheers

Les

Clarify that please. Do you mean you have 5 OLEDs connected and a sketch which selects one of the 5 channels on the mux and displays something on one display? And you have tested that individually in each of the 5 channels/OLEDs?

Also please clarify what you wanted to do with your 5 OLEDs. Do you want them to display different images/text or should all of them display the same image/text at all times?

My suspicion at this point is that the problem could be that your code only creates and uses a single oled object, and it should be creating 5 of them (an array of 5 objects would be sensible).

However, even with the u8g2 library, there might be insufficient ram memory on a small Arduino like Uno/Nano.

My suggestion would be to try to get 2 displays working before you increase that to 3, 4, and finally 5. That way, memory won't be a problem, at least to begin with.

1 Like

Hi there, thanks for helping

To confirm, I have a working array based sketch that will (from a sim game) get data and then select the correct .bmp from the .h file and display it on the correct OLED. It works perfectly, and it is working on the hardware that I am using for the sketch above.

I need a sketch that takes character strings from the game and then sends them to the corresponding OLED (take a look at the attached picture, the working OLEDs are using the sketch described above when outputs are zero) for a VHF panel representation

The sketch attached is just a test sketch, I want the OLED at address 2 to print "2", at address 3 to print "3" etc. I am happy to get just two working and start from there, as the others would simply be repetition with different callouts

As for memory, the u8g2 library is big but the 328 Nano seems to handle it without a problem, it says some 43% of memory used

Cheers

Les

I think the "_F_" in the constructor name may mean that a full frame buffer is used in memory. This will require 1K of memory per display, so if 5 objects are used, an Uno/Nano won't have enough.

Also I think the "_SW_" may mean using software i²c instead of hardware. Was that intentional, and if so, why?

That was it - I changed the SW to HW in the setup and it worked straight away

Many thanks for that, yet another lesson learned!

Cheers

Les

Odd. I would have thought software i²c should have worked, but be slow compared to hardware.

Yes, but only in a normal situation.

When the multiplexer uses a hardware I2C, and the OLED a software I2C on the same pins, then it is in conflict with the hardware I2C.

Ah, yes thanks @Koepel. It appears I am not quite awake yet today!

Hi, all

Just to close this, here is a video of the loosely assembled panel that this sketch was used for for your info

Thanks again for the help

Les

2 Likes

Very nice project. I am impressed. :+1:

Oliver

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