Maxing out the ESP8266 pins
14.2.2025In a recent project, I maxed out on available pins of the ESP 8266 (Wemos/Lolin D1 mini). A few pins did not work as input pins for me. In the end, I had to resort to the analog pin for the last input.
For future me and anyone who cares, I note here which pins I was able to use. (I use the Wemos D1 mini names - other packaging of the ESP chip might use different names, but also might has different behaviour.)
The ESP is running I2S to drive a digital-analog converter, plus a WS2801 LED strip, and has to read from 4 switch sensors.
I2S is fixed to use D4 for LRC, D8 for BCLK and RX for DIN. I have configured FastLED to use D5 for clock and D7 for data.
For the switches, I activated the internal pullup of the ESP, connecting the switches to ground and looking for the pins to go to 0 to detect a switch press. I tried all remaining pins and found that D6 seemed to always be low. D0 was high initially, but only went to low but never was pulled up again. That left me with D1, D2 and D3 which worked fine.
For the last switch, I went with the analog input A0. Contrary to the digital inputs that return 0 or 1 when reading, the analog input returns a value between 0 and 1023. I added a 10 kilo ohm resistor between A0 and the 3.3 volt to pull up A0. The switch connects A0 to ground. In each read cycle, I check if the analog value on A0 is below 500. This works reliable.
For the digital pins, I use the FTDebouncer library to avoid glitches when the input is not quite stable. I duplicated the FTDebouncer code - which is of course only written for digital pins - for the analog pin to also debounce that pin.
If you need even more pins, the way to go is either multiplexers (like 74HC4051) or shift registers (like 74HC595).