adafruit / Adafruit_SSD1306

Arduino library for SSD1306 monochrome 128x64 and 128x32 OLEDs
http://www.adafruit.com/category/63_98
Other
1.74k stars 963 forks source link

display.begin() always true #251

Open NuclearPhoenixx opened 1 year ago

NuclearPhoenixx commented 1 year ago

Hi there! I have an issue where the display.begin() function will always return true regardless if there is an actual display plugged in or not. It works fine if there is a display, of course, but if there is none it doesn't register that and thinks there still is one.

Maybe it's got something to do with the Raspberry Pi Pico? I don't think so tbh, because everything else works fine, so there must be an issue here.

nyckidryan commented 1 year ago

I can confirm this is the case on ESP32-WROOM-32 38 pin dev module as well, in Arduino IDE 1.8.19 and 2.0.1.

PitHerm commented 8 months ago

Yes, i display.begin returns always TRUE on Pi Pico , ESP8266 , ESP32

PitHerm commented 8 months ago

Well, i digged around within the source code of the lib and found NO return of FALSE if the display is not avaiable !

I thought about a workaround and here is the tested and working result: Wire.begin(); Wire.beginTransmission (SCREEN_ADDRESS); if (Wire.endTransmission () > 0){ Serial.println("SSD1306 allocation failed"); for(;;); // Don't proceed, loop forever } Wire.end(); if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { Serial.println(F("SSD1306 FAIL: Buffer allocation error, not enough memory")); for(;;); // Don't proceed, loop forever }

instead of: if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { Serial.println(F("SSD1306 allocation failed")); for(;;); // Don't proceed, loop forever }

Additional Info:

if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { Serial.println(F("SSD1306 allocation failed")); for(;;); // Don't proceed, loop forever }

works but NOT as expected , it only returns FALSE if not enough memory for display buffer is avaiable. so it would be better to change the phrase " Serial.println(F("SSD1306 allocation failed")); " to " Serial.println(F("SSD1306 FAIL: Buffer allocation error, not enough memory")); "