I am using esp32c3-super mini. Using esp as I want to scroll the bitmap banner which is massive so Arduino would not handle it. Anyway for a simple test . I tried this with two libraries
Adafruit
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_DC 2
#define OLED_RST 3
#define OLED_CS1 7
#define OLED_CS2 9
Adafruit_SSD1306 oled1(SCREEN_WIDTH, SCREEN_HEIGHT, &SPI, OLED_DC, OLED_RST, OLED_CS1);
Adafruit_SSD1306 oled2(SCREEN_WIDTH, SCREEN_HEIGHT, &SPI, OLED_DC, OLED_RST, OLED_CS2);
void setup() {
delay(100);
// Explicitly control CS pins (IMPORTANT)
pinMode(OLED_CS1, OUTPUT);
pinMode(OLED_CS2, OUTPUT);
digitalWrite(OLED_CS1, HIGH);
digitalWrite(OLED_CS2, HIGH);
// Reset OLEDs cleanly
pinMode(OLED_RST, OUTPUT);
digitalWrite(OLED_RST, LOW);
delay(20);
digitalWrite(OLED_RST, HIGH);
delay(20);
SPI.begin(4, -1, 6); // SCK, MISO(not used), MOSI
SPI.setFrequency(4000000); // Safe SPI speed
if (!oled1.begin(SSD1306_SWITCHCAPVCC)) {
while (1);
}
if (!oled2.begin(SSD1306_SWITCHCAPVCC)) {
while (1);
}
oled1.clearDisplay();
oled2.clearDisplay();
oled1.display();
oled2.display();
}
void loop() {
// OLED #1 test
oled1.clearDisplay();
oled1.setTextSize(2);
oled1.setTextColor(SSD1306_WHITE);
oled1.setCursor(0, 0);
oled1.println("OLED 1");
oled1.display();
// OLED #2 test
oled2.clearDisplay();
oled2.setTextSize(2);
oled2.setTextColor(SSD1306_WHITE);
oled2.setCursor(0, 0);
oled2.println("OLED 2");
oled2.display();
delay(2000);
}
And for U8G2
#include <U8g2lib.h>
#include <SPI.h>
// -------------------- Pins --------------------
#define OLED_MOSI 6
#define OLED_CLK 4
#define OLED_DC 2
#define OLED_RST 3
#define OLED_CS1 7
#define OLED_CS2 9
// -------------------- Displays --------------------
U8G2_SSD1306_128X64_NONAME_F_4W_HW_SPI oled1(U8G2_R0, OLED_CS1, OLED_DC, OLED_RST);
U8G2_SSD1306_128X64_NONAME_F_4W_HW_SPI oled2(U8G2_R0, OLED_CS2, OLED_DC, OLED_RST);
void setup() {
SPI.begin(OLED_CLK, -1, OLED_MOSI, -1); // SCK, MISO (none), MOSI, SS (ignored by U8g2)
oled1.begin();
oled2.begin();
// Display IDs
oled1.clearBuffer();
oled1.setFont(u8g2_font_ncenB08_tr);
oled1.drawStr(0, 20, "OLED 1");
oled1.sendBuffer();
oled2.clearBuffer();
oled2.setFont(u8g2_font_ncenB08_tr);
oled2.drawStr(0, 20, "OLED 2");
oled2.sendBuffer();
}
void loop() {
// Nothing needed for test
}
This displays sometimes OLED2 on one of the displays and when I swap CS cables then the other display is displaying OLED 2. When disconnecting jumper wires sometimes I see OLED1 display for a brief monent as well. But only one display works at any given time