2 days of infuriating debugging solved in 1 line of code changed đ #Notes #ProgrammableThings.
The symptom was a random glitch when setting LEDs where the wrong ones were set or not set at all. With absolutely no pattern whatever. Even weirder the problem persisted over hardware resets but not a full power cycle.
Today we took the whole program apart and ran each line of code separately with an LED âdebugâ statement in between to work out which bit of it was causing the LEDs to malfunction. Turns out the glitching started after connecting to the SD card.
I couldnât get ESP debugging working so stepping into the SD card library was not pleasant. Each change added a console output or stubbed out some functionality and required an entire firmware rebuild and a flash onto the device to see if it fixed it.
After an afternoon of those we found that disabling the SD cardâs SPI bus stopped the glitching! More delving into how the SD card library made us finally think to try to connect the LEDs on a different data pin.
Now was time for an oscilloscope! What was being sent down that previous data pin, it wasnât meant to be used at all. Our first thought was it was an alternative serial out pin to listen for program output. We hooked the ESP up to the scope and it seemed to be that, there were signal spikes when there was supposed to be text output!
So I guess the moral here is to RTFM and know what GPIO pins are used for before arbitrarily choosing ones that âlookâ free. Time for a long walk đ©