Fix “SSD1306 allocation failed” (OLED stays blank)
Adafruit_SSD1306 could not allocate its frame buffer. On an Uno that means RAM is nearly full; elsewhere it is often the wrong address or begin() call.
Community draft — report a mistake
What you see
Sketch uses 14872 bytes (46%) of program storage space.
Global variables use 1180 bytes (57%) of dynamic memory, leaving 868 bytes for local variables.
...
SSD1306 allocation failedSketch uses 14872 bytes (46%) of program storage space. Global variables use 1180 bytes (57%) of dynamic memory, leaving 868 bytes for local variables. ... SSD1306 allocation failed
The Adafruit SSD1306 library keeps a copy of the whole screen in RAM. If that memory cannot be allocated, begin() fails and the example prints this message and stops.
Quick fix — try in order
- 1
Free RAM on Uno/Nano
The 128×64 buffer needs 1024 bytes at runtime. Keep global variables under about 900 bytes: use F() for strings and smaller buffers.
- 2
Use the right address
Most 0.96″ modules are 0x3C; some are 0x3D. Call display.begin(SSD1306_SWITCHCAPVCC, 0x3C).
- 3
Use 128×32 if that is your module
Declaring 128×64 for a 128×32 module wastes 512 bytes and displays wrongly.
- 4
Check wiring and power
Some clone modules swap VCC and GND — read the labels on your board before powering it.
Why it happens
Why is this not caught at compile time?
The buffer is allocated with malloc() inside begin(), so the compiler’s RAM figure does not include it.
Uno RAM is only 2 KB
With the 1 KB OLED buffer, little remains for anything else. See low memory warning.
Display blank without this message?
Then begin() succeeded and the problem is the address or wiring — see I2C device not found.
Board-specific notes
ESP32: RAM is not an issue; check the address and that you called display.display() after drawing. See SSD1306 with ESP32.
Parts: SSD1306 OLED — pinout, voltage and library notes.
Did this fix it?
Thanks — that helps us keep this page right.