Skip to main content
2 of 2
Removed unverified info and added information about alternative library
Ramast
  • 111
  • 3

I had exact same problem and james's answer helped me realize the problem is related to heap memory.

In addition to what he has already commended, I found here that you should also wrap all your constant strings in F() function.

For example instead of

display.println(" Madgayrah");

You write

display.println(F(" Madgayrah"));

This will store the string in the flash memory instead of SRAM.

Also if you only use OLED display for printing text, I strongly recommend the more lightweight SSD1306Ascii library

It output text to oled display without buffering which causes slight flickering but massively reduce the amount of memory required to drive the OLED.

Another helpful tip is to use arduino's watchdog. Basically after you enable that you need to constantly call wdt_reset(); function and if you failed to call it for certain amount of seconds, arduino will automatically reset.

Ramast
  • 111
  • 3