Really struggling with OLED SD1306

Hi folks, so I have some working code using adafruit drivers (U8G2 too big it seems)
But when trying to add new function the display just fails to initialise and doesn't work!
What's weird is that it also simulates the same on Wokwi, but I might add a line that doesn't even directly affect the display, like println for serial out, and it will still kill the display!
Arduino IDE reports enough space, but I can't hep feeling there is a conflict, and I am not sure how I can resolve this!

Here is the example Wokwi - Online ESP32, STM32, Arduino Simulator

Now I had to remove the init BME as I cannot find model for that. Anyway, we get display, and on real hardware everything works

But If I add the line:
delay(100);
Serial.println("SSD1306 allocation ok");
After display init, display fails and I get weird output...

This applies to all sorts of other additions I want to make which on the face of it should not effect I2C or display, but just break the code...

I am new to C, and arduino environment so hoping someone can guide me in right direction!

I can code in assembly (PICS), and right now I feel like going back, but I really need to move forward with C to make life easier LOL!

Has it not occurred to you that without seeing your full sketch it is impossible to provide any help ?

Is it not in the link I have provided?

Sounds like you are running short of ram. A quick look at the sketch shows you do not use the F() macro for text literals, those can eat up a lot of ram.

I really find that hard to believe, unless you are talking about the dynamic memory. The adafruit library uses the same 1024 bytes of memory for a display buffer, but allocates it at run-time so the compiler does not see it.

< edit > U8g2 also has an option to use a page buffer instead of a full buffer, that reduces the display buffer to about 1/8 the size on an SSD1306, but does require a slight modification to how you print to the display.

Big in what way, exactly? Flash (program) memory or RAM (dynamic) memory?

One difference between those two libraries is that U8G2 reserves the RAM memory it needs at compile time, so the IDE is able to tell you if it will not fit. The Adafruit library reserves the memory it needs at run time, so the IDE thinks it will fit and uploads it but once the code is running on the Arduino and tries to initialise the display, it finds out there is not enough memory after all and fails.

My apologies. I missed the link

No problem!

Ok folks so this must be a memory issue then, that does make sense! So I could go back to the U8G2 code and see more clearly how far over I am, and try putting the text into program memory if the dynamic is running short?
Although when I remove the headers it makes no difference. I will compile again with U8 and then report back if I cannot sort this out...

Out of interest are there any Atmel processors that would require minimal code change but offer greater scope?

Probably not. Your code is doing a lot of direct manipulation of timers, and that code will be unique to ATMEGA328. Everything else looks pretty standard Arduino code and should run on any Arduino or Arduino compatible board. Many of these boards have far more RAM and Flash memory.

It would be really helpful to us, in order to help you, if you could answer any questions we have asked before asking any further questions if your own. Just look for the "?" symbol. If you don't know the answer, please say so, rather than ignoring a question.

1 Like

Yes, assuming it is the dynamic memory which is running short.

As @david_2018 mentioned, U8G2 has the ability to use far less, but it will require some code changes.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.