Issue using Adafruit_SSD1306.h with FastLED.h

In short:
As soon as #define NUM_LEDS is greater than 50, nothing works anymore.

In detail:
#include <Adafruit_SSD1306.h>
and
#include <FastLED.h>
do not work well together :frowning:

It does not appear as a memory issue.
Sketch uses 17622 bytes (54%) of program storage space. Maximum is 32256 bytes.
Global variables use 1034 bytes (50%) of dynamic memory, leaving 1014 bytes for local variables. Maximum is 2048 bytes.“

I have a LED strip with 144 LEDs (I'll use around 70) and an OLED SSD1306 128x64 connected to Arduino UNO.
OLED specs = 0.96" I2C IIC Serial 128X64 White OLED LCD.

If I run only the LED code, commenting the OLED part, the LEDs are working fine.
If I run only the OLED code, commenting the LED part, the OLED is working fine.

But as soon as I run the FastLED with the OLED code (no matter what the OLED show display, a text or a bitmap), then nothing works anymore.

No code error, just the OLED does not display anything anymore, nor any LED is working.
No matter where I place
FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS)
in my setup(), as soon as the FastLED line is uncommented, nothing worked anymore.

After spending hours on it, I found out that the amount of LEDs (NUM_LEDS) is the issue:
#define NUM_LEDS 50
works fine, while any amount greater than 50 won't. So 50 seems to be the limit.

I can’t explain why and most of all I need a solution cause I need to work with more than 50 LEDs.

Do you think I should buy an OLED using SPI instead of I2C?
Or any advice on a different library than the Adafruit one which would work?
Any advice very much appreciated as I'm stucked.

The source code is here:

And there's a Bitmap.h also with my logo. Not useful here as not related to the issue.

This is most likely a memory problem, as the OLED library reserves another 1024 bytes for the screen buffer, IN ADDITION to those 1034 indicated in the compiler output.
To use more than 50 leds you need to take another oled library or use an arduino with more memory like mega or nano every

Thank you very much for your help.
I was not aware of the "nano every".
I'm gonna check online if I can find a different oled library than the Adafruit for I2C 128X64 White OLED.

I am going to try the U8glib to replace the Adafruit and will report back.
I found the library by reading this: light library for OLED 128x64 - #9 by WebDweller

UPDATE:
I installed the U8glib library .
I don't use the Adafruit libraries anymore (Adafruit_SSD1306.h and Adafruit_GFX.h), but instead I am using the U8glib library and everything works fine now, even if NUM_LEDS is 100 (not limited to 50 anymore).
Of course it means I can't display a bitmap, but it's ok.

I ordered a Arduino Mega, so I'll also be able to test the Adafruit library with more RAM.

EDIT: displaying bitmaps with u8glib might work. I'll check that asap.

1 Like

Thanks for your feedback

The u8g library uses a page buffer, which is much smaller than the full buffer used by the Adafruit library. With u8g, the buffer memory is included in the total dynamic memory shown by the compiler, so is it easier to see how much memory is actually needed.

If you need some feature not supported by u8g, look at the u8g2 library, that has the option to use a page buffer or full buffer, as well as a limited text version that does not use a buffer at all.

Cool. Thanx for the advice. I'll check u8g2 if needed.

I tried btw using the u8glib to display the logo bitmap with my 100 LEDs strip and all works fine.
I lost some time in gimp with the xbm format that was awaited by u8glib as the bitmap was ok, but finally got it to work.

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