Rob's garden / notes / note

Note

2 days of infuriating debugging solved in 1 line of code changed 😅 #Notes #ProgrammableThings.

undefined

Changing an LED pin from 17 to 27

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 đŸ˜©