Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error when several ssd1306 128x64 #268

Open
Qu4zar opened this issue Aug 29, 2023 · 1 comment
Open

error when several ssd1306 128x64 #268

Qu4zar opened this issue Aug 29, 2023 · 1 comment

Comments

@Qu4zar
Copy link

Qu4zar commented Aug 29, 2023

  • Arduino board: ARDUINO UNO

  • Arduino IDE version (found in Arduino -> About Arduino menu): 2.1.1

  • List the steps to reproduce the problem below (if possible attach a sketch or
    copy the sketch code in too):
    My problem
    I can't use 2 SSD1306 at the same time.
    I have 2 SSD1306 128x64 but when I define SSD1306_128_64 in the Adafruit_SSD1306.h program, it doesn't work (only on 1 screen).
    I only can define 1 screen if I use the "new way", display(w,h,wire,-1) and I didn't find a solution in the forum.

I can define SSD1306_128_32, it works, but the words size is too big for my application.

My Sketch :
#include <Wire.h>
#include <Adafruit_SSD1306.h>

//Adafruit_SSD1306 ecranOLED0(128, 64, &Wire, -1);
//Adafruit_SSD1306 ecranOLED1(128, 64, &Wire, -1);

Adafruit_SSD1306 display1(0);
Adafruit_SSD1306 display2(1);

void setup() {
// Initialisation des écrans avec leurs adresses I2C
display1.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display2.begin(SSD1306_SWITCHCAPVCC, 0x3D);

// Le reste de votre configuration
}

void loop() {
// Contrôlez les écrans individuellement ici

// Exemple : Afficher du texte sur le premier écran
display1.clearDisplay();
display1.setTextColor(SSD1306_WHITE);
display1.setCursor(0, 0);
display1.println("Oh");
display1.display();

// Exemple : Afficher du texte sur le deuxième écran
display2.clearDisplay();
display2.setTextColor(SSD1306_WHITE);
display2.setCursor(0, 0);
display2.println("mince");
display2.display();

// Le reste de votre code loop
}

@todbot
Copy link

todbot commented Jul 12, 2024

You should check the return value from display.begin() to see if the memory allocation is failing. The Uno has little RAM and may not be able to support multiple OLEDs. A version of the above code does work on the RP2040 (Raspberry Pi Pico). I verified this code does work with two displays on the same I2C bus:

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

Adafruit_SSD1306 display0(128, 64, &Wire);
Adafruit_SSD1306 display1(128, 64, &Wire);

void setup() {
  Serial.begin(115200);  
  while(!Serial) {} // wait for USB serial monitor to connect

  Wire.setSCL(17);
  Wire.setSDA(16);

  display0.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display1.begin(SSD1306_SWITCHCAPVCC, 0x3D);

  display0.display();
  display1.display();
  delay(2000); // Pause for 2 seconds
}

void loop() { 
  Serial.printf("time:%ld\n", millis());
  delay(100);
  display0.clearDisplay();
  display0.setTextColor(SSD1306_WHITE);
  display0.setCursor(0, 10);
  display0.println("Hello");
  display0.printf("time0:%ld", millis());
  display0.display();
  display1.clearDisplay();
  display1.setTextColor(SSD1306_WHITE);
  display1.setCursor(0, 10);
  display1.println("World");
  display1.printf("time1:%ld", millis());
  display1.display();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants