Segments - what's the real maximum #

I would like to have 15 segments, and perhaps more in certain cases.
What is the max # of segments for a Wemos D1 Mini binary? How can it be increased?

Hi @huggy-d1, the maximum amount of segments is defined in FX.h line 49:

#define MAX_NUM_SEGMENTS 10

One segment uses about 2100 bytes of heap (53 bytes for the segment itself and up to 2048 byte for segment data), so using more than 10 segments can lead to reboots.

So, you can change the line and try. Most of the effects do not use a lot of segment data, but if you have a lot of segments and start effects that use segment data on all of hem, then your ESP will probably reboot.

But if my d1 mini has 4MB of flash why would it reboot?

…because it has only 80 kB of RAM for data.

Guess I will disable some features to get enough space for more segments.

@Def3nder is right that this is a memory related limit.
While the usage of the segment itself (about 50 bytes each) is low enough for supporting more, and the 2048bytes of dynamic segment data are shared between all segments, the sending buffer may not be large enough to send JSON API responses for more segments. In my testing, 10 was about the maximum that reliably works. You can try increasing the count, but be aware it can lead to issues.

If the segments are created and manipulated in code rather than UI or via API, what then might cause problems?

That will probably be less problematic indeed. The only issue this could cause is buffer exhaustion when requesting LED state from /json. It’s worth a try though, even if that happens WLED probably won’t crash, you’ll just see a red error message in the UI.

I have set MAX_NUM_SEGMENTS = 15, actually only need 11 or 12, and it is no problem to set them up and have them running after a fresh OTA update

But unfortunately when I reboot (my LEDs are on the main light switch), the settings are lost / not displayed.

The UI will only show 9 segments, and the strips reflect that - I have to set up the segments again…

I guess this is somehow due to the UI not taking MAX_NUM_SEGMENTS into account correctly, but can’t find the right place to change this - can anybody shed some light on this?

Right now the EEPROM only has storage capacity for 10 segments in preset 16.
The limit is not 10 segments because I’d like to limit things arbitrarily :slight_smile: It is the max that works reliably with all features. But maybe we’ll be able to raise it soon with filesystem support, at least on ESP32!

wow, thanks for the fast reply - and also thanks for your great work!!

1 Like