Multiplex 4053 and two OLED I2C displays.

Hi.

My first post. So please be gentle. :)

I am trying to multiplex two OLED I2C displays on an Uno. I'm running a 4053 chip to switch the SCL and SDA lines between the two displays.

Litterally my code is: Set digital pin Low,( to change the switch on the 4053 ) write and display to selected screen (1). Set digital pin High ( to change the switch on the 4053 ) write and display to selected screen (2).

That's it.

However, I suspect I'm missing some additional hardware somewhere in the way of resistors perhaps. My reasoning being that Screen1 seems to always work. But when interrupting some of the wires, screen2 jumps to into life. But it doesn't do it all the time. So I'm guessing perhaps something is floating somewhere.

Any help would be appreciated as I'm from a programming background rather than an electronics background.

I can provide details of the circuit if necessary.

Thanks.

Jason.

Yes show the schematic. You need to switch two lines, data and clock and you need pull up resistors on each line. Also post your real code, the code tag icon is to the left of the quote one.

I suspect it’s the resistors I need, as I have none in my circuit.

Hope this works…

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

#define OLED_RESET 4
#define OLED_SELECT 5

int analogPin = 0;
Adafruit_SSD1306 display(OLED_RESET);


void setup()
{                

 display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
 display.clearDisplay();
 pinMode (OLED_SELECT, OUTPUT);
 pinMode(13, OUTPUT);

}

void loop()
{  
 
  digitalWrite (OLED_SELECT, LOW );
 digitalWrite (13, LOW );
 
  printOLED0();
  display.display();
  delay(500);
  
 digitalWrite (OLED_SELECT, HIGH );
 digitalWrite (13, HIGH );
  
  printOLED1();
  display.display();

  delay(500);


}


void printOLED0()
{
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(22,0);
  display.println("Screen 1");
}

void printOLED1()
{
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(22,0);
  display.println("Screen 2");
}

Thanks.

Jason.

Sorry that is not a schematic is a physical layout diagram and as such totally useless for seeing if a circuit is designed correctly. I would have to turn that into a schematic, but it is your project so you must have a schematic somewhere even if it is only hand drawn.

Does your bread board have a break in the middle of the two long horizontal tracks top and bottom? If so then half the circuit is not getting power. I told you that you need pull up resistors, there is no argument about that, so why are they not on this diagram. You also have no supply decoupling on the 4053 chip, 0.1uF ceramic.

Hi.

Ah. In that case, I don't have a schematic.

I designed the circuit using a pin out for a 4053 chip and simply went from there. I'm sure I could sort one out for you though.

No. The breadboard doesn't have a break in it. I've read that some do in the middle. Luckily, mine does not.

No, there are no pull up resistors or ceramic cap. The diagram shows you what I have built.

If I understand it correctly, I'd connect a resistor from the SDA line on screen1 to 5v. One for SCL line on screen1 to 5v. Then duplicate this for screen 2. Is that all I'd need? - Just the 4? How do I work out what value resistor I'd need for the pull up?

The cap would go between pin 16 ( vdd 5v ) and ground. - Is that correct?

Again, thanks for any help and advice.

Jason.

The normal value for a 5V I2C bus is 4K7. You should have one on each bus you have so that would be one set on each display.

Yes the ceramic capacitor should go between the power pins of the chip as close as you can get them with the leads of the chip as short as possible.

The problem with bread board is that it is not good at making reliable contact so you never know if it is your connections that are causing you problems or something else.

Thank you very much for your help mike. I will try the 4k7 resistors tonight. I tried some 2k2's last night along with a 102 ceramic. It worked... To a point. Less flakey than it was.

If it's better, I'll solder it on a board.

I'll update this later. Thank you.

Jason.

Hi.

Just an update on this. I tried the 4k7 resistors. Two per display. Still had issues with it, so left it a while and I had a think about it...... The issue was only ever with screen 2.....

A quick change to the code sorted the problem out.

The "display.begin" needs to be sent to EACH display. The code above only sends it to the first screen. :) So, adding a section in setup to send the display.begin to each screen sorted the issue out.

I can get on with the rest of the project now.

Thanks!

Jason.