Closed
Description
What happened?
The ability to have more than 2 buttons has introduced a bug in WLED's pin handling.
- The
WLED_MAX_BUTTONSdefault array length is dynamic and is2for ESP8266 and4for ESP32. It can also be edited by the compiler flag to become even larger if wanted. - WLED only gives 2 default values for
BTNPINandBTNTYPE. Which means there's some unspecified values in the array on ESP32:
#define BTNPIN 0,-1
#define BTNTYPE BTN_TYPE_PUSH,BTN_TYPE_NONE- C++ arrays default all unspecified values to 0. So
btnPin[4] = {2,3}becomes{2,3,0,0}automatically. So for example, WLED's default values for an ESP32 binary will look like this:
int8_t btnPin[4] = {0, -1, 0, 0};
byte buttonType[4] = {2, 0, 0, 0};- Bug 1: The WLED code that is supposed to fix this at the first launch in
cfg.cpp: if (fromFS) {never executes. That code is supposed to setGPIO = -1 and Type = NONEfor every button pin whose pre-defined firmware setting for the GPIO was either -1 or the type was NONE. Basically a "reset all unused pins". But that code never executes! - This means that all of the unused/unspecified button pins all stay defined as "GPIO 0 type NONE (0)".
- Bug 2: There's a second bug in the button initialization code: It activates and takes over ownership of ALL "defined" (
>= 0) button GPIO pins even if their type is set to NONE (Disabled). So it steals/allocates all "disabled" button pins too. If a button setting is "disabled", it should not steal ownership of them! - And because the button initialization code runs after the LED initialization, it means that GPIO 0 is always overwritten to become a button pin instead of an LED pin on all ESP32 devices.
- The most important bug is that the settings cleanup code never executes. But the "pins are taken over by the button handler even if their type is set to NONE (Disabled)" is a nasty bug too.
There is a temporary workaround via compiler flags: By manually specifying every array index on ESP32 builds:
-D WLED_MAX_BUTTONS=4
-D BTNPIN=0,-1,-1,-1
-D BTNTYPE=2,0,0,0To Reproduce Bug
x
Expected Behavior
x
Install Method
Binary from WLED.me
What version of WLED?
0.15 and newer
Which microcontroller/board are you seeing the problem on?
ESP32
Relevant log/trace output
Anything else?
No response
Code of Conduct
- I agree to follow this project's Code of Conduct
Reacted by Johnny Arcitec
Activity
Arcitec commentedon Apr 2, 2025
I've been digging around the issue tracker now. There has been previous discussion of this and some talks about fixes, but it didn't have a good summary of the actual bugs this causes, so it got lost in the noise.
-1values, which was not a good solution since the length of the button array can be changed dynamically. Fix default button pin assignment for esp32 #4074The last pull request above actually talks about the
cfg.cppsolution.However, if we start digging into v0.15.1.beta2, we see some interesting changes in WLED:
https://github.com/wled/WLED/tree/v0.15.1.beta2
WLED/wled00/cfg.cpp
Lines 292 to 299 in 6572efb
There's newly added code which is supposed to set the buttons to
GPIO = -1, Type = NONE (0)if either GPIO was -1 or Type was NONE (0).Edit: I see that the fix was added 7 months ago in this commit: da6d64e
@PaoloTK told me on Discord that the new code doesn't run. He said that if we add a debug print statement to the highlighted
fromFScode block, it actually never runs, so maybe the fix doesn't work?Here's what to do next:
PaoloTK commentedon Apr 5, 2025
To clarify, this was my experience when testing while working on the previous 2 PRs. It could have been fixed since then, but I have been unable to test.
blazoncek commentedon Apr 17, 2025
I've finally identified the issue. It is an early return from EEPROM handling code (that's since become obsolete).
blazoncek commentedon Apr 17, 2025
@Arcitec how familiar are you with git patches? I can provide a patch for testing but is unfortunately based on my fork's
stablebranch.You'll need to add remote to your local git repo, checkout my branch and apply patch on top of that. Then do the testing.
github-actions commentedon Aug 16, 2025
Hey! This issue has been open for quite some time without any new comments now. It will be closed automatically in a week if no further activity occurs.
Thank you for using WLED! ✨
netmindz commentedon Aug 16, 2025
Has this been resolved now @blazoncek ?
blazoncek commentedon Aug 16, 2025
Once #4757 is merged.
However I have not received any confirmation or other feedback on the PR. Neither form @Arcitec nor @PaoloTK or anyone else.
DrTHC commentedon Mar 2, 2026
This is happening again in latest version
DedeHai commentedon Mar 2, 2026
@DrTHC not for me. can you detail out on how to reproduce it?
netmindz commentedon Mar 3, 2026
0.15.3 or the nightly builds of 16?