Two I2C OLED displays in parallel (with Adafruit_SSD1306)

Has anyone already operated 2 OLED displays in parallel with the Adafruit_SSD1306 lib? It doesn’t seem to work. Only the 1st OLED is addressed, the 2nd receives no data via the bus. If I comment out the 1st OLED, the 2nd OLED also works. Can the lib run in parallel? Yes, the modules have different addresses 3c, 3d.

#include <Wire.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)
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)

Adafruit_SSD1306 display1(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
Adafruit_SSD1306 display2(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

void setup() { 
/*
  display1.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Default OLED address, usually
  display1.clearDisplay();
*/
  display2.begin(SSD1306_SWITCHCAPVCC, 0x3D); // Second OLED address, via onboard jumper
  display2.clearDisplay();

  delay(200);
/*
  display1.setTextSize(1);
  display1.setTextColor(WHITE);
  display1.setCursor(0,0);
  display1.print("Display A");
  display1.display();
*/
  display2.setTextSize(1);
  display2.setTextColor(WHITE);
  display2.setCursor(0,0);
  display2.print("Display B");
  display2.display();
}

void loop() {
  }

Output from BUS scanner:
Scanning…
I2C device found at address 0x3C !
I2C device found at address 0x3D !
I2C device found at address 0x60 !
done

Two OLEDs should work fine if you have different I2C addresses.
Note that each OLED will require 1024 bytes of SRAM. Which means that it will not work with a Uno.

If you want two OLEDs with a Uno, use U8g2lib with the small buffer 1 constructors.

U8g2lib can do most things that Adafruit_SSD1306 can do (and more)
However the methods have different names and calling arguments.

David.

david_prentice:
Note that each OLED will require 1024 bytes of SRAM. Which means that it will not work with a Uno.

You mean additionally? Is it allocated dynamically?

Yes.

Okay, that is maybe the explanation for the malfunction.

I2C device found at address 0x3C !
I2C device found at address 0x3D !

Remember that device I2C addresses comes in pair. There's the WRITE_ADDRESS and READ_ADDRESS. It's possible the two addresses above are the write and read addresses of a single I2C device

0x3C - 0011 1100 (WRITE ADDRESS)
0x3D - 0011 1101 (READ ADDRESS)

hzrnbgy:
I2C device found at address 0x3C !
I2C device found at address 0x3D !

Remember that device I2C addresses comes in pair. There's the WRITE_ADDRESS and READ_ADDRESS. It's possible the two addresses above are the write and read addresses of a single I2C device

0x3C - 0011 1100 (WRITE ADDRESS)
0x3D - 0011 1101 (READ ADDRESS)

No, they are NOT.

SSD1306 has 7-bit I2C Slave Address of 0x3C or 0x3D
SSD1306 has 8-bit I2C Slave Address of 0x78/79 or 0x7A/7B

Arduino Wire.h library always uses the 7-bit Slave Address.

The OP could have just revealed which particular Arduino board she was using. In which case there could be a simple unequivocal answer regarding Adafruit_SSD1306 dynamic allocation of SRAM at runtime.

David.

I don't use the Wire.h library or any Arduino libraries for that matter so that tidbit of information is new to me. I did put this qualifier on my statement

It's possible the two addresses...

so don't be hatin'

I am not hating anyone.

It has been a long standing Gotcha for anything I2C. Some datasheets and libraries use 8-bit address others use 7-bit.

What really irritates me. Hardware datasheets seldom put the Slave address on the front page.
The very first thing that you want to know about some fancy new chip is the Slave Address.
You have to search for this information. And then compare the text value with any timing diagram to see whether the text refers to 7-bit or 8-bit value.

David.