Struggling with SSD1306 OLED display

Thread Starter

Torbek

Joined Apr 19, 2019
83
Hi folks, so hoping there is something that I am missing, I have made a program to display humidity and temp on an OLED display, and have a working splash screen (two in fact) but I want to briefly display software version on the display before the splash so I can keep up with things...

However, When I add the following bit of code, I lose the display functionality!

Not sure why, I seem to be ok with memory.... I have tried adding a couple more functions and again the code refuses to work...

Is there something about these displays that make them a bit finicky? Is there something happening when I compile which kills the display?

Happy to leave full code if required, but for now will show the small bit I am working on>>

Working code:


Working code:
    // Initialize display first
    if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {  // Use 0x3C or 0x3D based on your display
        Serial.println("SSD1306 allocation failed");
        while(1); // Don't proceed if display fails
    }
 
    if (!bme.begin(0x76)) {
        displaySensorError();
        while(1); // Don't proceed if Sensor fails
    }

    // Initial display

    display.clearDisplay();
    delay(200);
    display.drawBitmap(0, 0, epd_bitmap_BUN, 128, 64, WHITE);
    display.display();
    delay(3000);
    display.clearDisplay();
    delay(100);
    display.drawBitmap(0, 0, epd_bitmap_ME3, 128, 64, WHITE);
    display.display();
    delay(1600);
     display.clearDisplay();
Now the none working code

Non-working code:
    // Initialize display first
    if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {  // Use 0x3C or 0x3D based on your display
        Serial.println("SSD1306 allocation failed");
        while(1); // Don't proceed if display fails
    }
 
    if (!bme.begin(0x76)) {
        displaySensorError();
        while(1); // Don't proceed if Sensor fails
    }
    // Initial display
    display.clearDisplay();
    display.setTextSize(1);
    display.setTextColor(SSD1306_WHITE);
    display.setCursor(0, 0);
    display.print("V10153H1");
    delay(1500);

    display.clearDisplay();
    delay(200);
    display.drawBitmap(0, 0, epd_bitmap_BUN, 128, 64, WHITE);
    display.display();
    delay(3000);
    display.clearDisplay();
    delay(100);
    display.drawBitmap(0, 0, epd_bitmap_ME3, 128, 64, WHITE);
    display.display();
    delay(1600);
     display.clearDisplay();
I cannot for the life of me understand why there would be an issue, especially given memory is 80% program 42% dynamic?
 

seanstevens

Joined Sep 22, 2009
323
Just a pure guess, looking at your working and non-working, are you giving the display enough time to initialise, i.e. the delays that you have in your working vs the no delay in non-working. Try putting some delay in just to debug.
 

Thread Starter

Torbek

Joined Apr 19, 2019
83
Thanks for the replies, I think something else odd is going on here, because when I add a simple line "Serial.println("SSD1306 allocation Successful");" underneath the display initialisation I once again get no display AND all of a sudden I get "SSD1306 allocation failed":oops:
It doesn't make any sense to me, but I wonder if I have done something that the compiler is getting confused over?
Still got 20% prog memory and 58% dynamic still available!

So simply remming [Serial.println("SSD1306 allocation Successful");] out returns the display to it's working state. I also tried slowing WIRE down too!
 

Thread Starter

Torbek

Joined Apr 19, 2019
83
So removed the splash screens and made sure the display works, yep.

Add the following line Serial.println("SSD1306 allocation Successful");


Code:
// Initialize display first
    if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
        Serial.println("SSD1306 allocation failed");
        while(1); // Don't proceed if display fails
    }

    Serial.println("SSD1306 allocation Successful");
And I get "SSD1306 allocation failed" along with no display LOL
 

panic mode

Joined Oct 10, 2011
4,929
you do not understand the process...
you need to send data to display, then you need to have to tell it to show what you were sending... because things you were sending ends up in some memory, rather than going to display.

and if you tried to add display.display(); in line 19 you would not see the version screen. display would be clear (line 12), then data would be loaded to display memory, then it would wait 1.5sec. then it would display content but not for long since line 20 clears it again.

1744722803273.png
 
Last edited:

Ya’akov

Joined Jan 27, 2019
10,226
So removed the splash screens and made sure the display works, yep.

Add the following line Serial.println("SSD1306 allocation Successful");


Code:
// Initialize display first
    if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
        Serial.println("SSD1306 allocation failed");
        while(1); // Don't proceed if display fails
    }

    Serial.println("SSD1306 allocation Successful");
And I get "SSD1306 allocation failed" along with no display LOL
Welcome to AAC.

What if you try assigning the return of display.begin outside the if block, then test that variable?

Also, be careful about your error messages ”display.begin() returned displayBeginReturn” or something like that is true, your message may or may not be true.
 

Thread Starter

Torbek

Joined Apr 19, 2019
83
you do not understand the process...
you need to send data to display, then you need to have to tell it to show what you were sending... because things you were sending ends up in some memory, rather than going to display.

View attachment 347052
Ah sorry forgot to add I tried that... Hang on I will repost the code...

Code:
    display.clearDisplay();
    display.display();
    delay(100);
    display.setTextSize(1);
    display.setTextColor(SSD1306_WHITE);
    display.setCursor(0, 0);
    delay(100);
    display.print("V10153H1");
    display.display();
    delay(100);*/
    display.clearDisplay();
    display.display();
    delay(200);
    display.drawBitmap(0, 0, epd_bitmap_BUN, 128, 64, WHITE);
    display.display();
    delay(3000);
    display.clearDisplay();
    display.display();
    delay(100);
    display.drawBitmap(0, 0, epd_bitmap_ME3, 128, 64, WHITE);
    display.display();
    delay(1600);
    display.clearDisplay();
The above leaves the display blank AND I get an display error from initialising!
 

Thread Starter

Torbek

Joined Apr 19, 2019
83
Welcome to AAC.

What if you try assigning the return of display.begin outside the if block, then test that variable?

Also, be careful about your error messages ”display.begin() returned displayBeginReturn” or something like that is true, your message may or may not be true.
Thanks Ya’akov, can you help out with an example here please? I am new to C!
 

Ya’akov

Joined Jan 27, 2019
10,226
Thanks Ya’akov, can you help out with an example here please? I am new to C!
Sure—all I wanted you to test is putting the display.begin() outside the if(){}.


Testing display.begin() Success:
...
 bool displayBeginReturn = display.begin(SSD1306_SWITCHCAPVCC, 0x3C);

 if (displayBeginReturn) {
    Serial.println("display.begin() returned success"
 } else {
    Serial.println("display.begin() returned failure. Halting.");
    while (true);
 }
...
 

Thread Starter

Torbek

Joined Apr 19, 2019
83
Sure—all I wanted you to test is putting the display.begin() outside the if(){}.


Testing display.begin() Success:
...
bool displayBeginReturn = display.begin(SSD1306_SWITCHCAPVCC, 0x3C);

if (displayBeginReturn) {
    Serial.println("display.begin() returned success"
} else {
    Serial.println("display.begin() returned failure. Halting.");
    while (true);
}
...
Ta, sadly, just the act of adding
bool displayBeginReturn = display.begin(SSD1306_SWITCHCAPVCC, 0x3C);

is enough to prevent the display initialising! This doesn't make a lot of sense to me! Unless the compiler is doing something strange?
 
Top