A recent question for me from a reader of my ESP32 book (thanks Richard) was:
how do I find out which pin the built-in LED (if there is one) is connected to?
You'd think this would be a simple matter of consulting the documentation, but the documentation is very hard to find because there are so many different ESP32 development boards. They are often not even identified by a consistent name.
Pinout diagrams are fairly easy to find, but they do not usually identify the pin used for a built-in LED.
To help Richard out, I've come up with this test program to help in the search for the pin.
The code
from time import sleep
pins = [x for x in range(0, 36)] # end of range last pin no. + 1
ignore_pins = [0, 1, 6, 7, 8, 11] # exclusions
print(pins)
for pin in pins:
try:
print(f"Trying Pin {pin}")
led = Pin(pin, Pin.OUT)
led.on()
sleep(0.5)
led.off()
sleep(0.5)
except:
print(f"Pin {pin} not allowed")
Usage
To use the program, hold your board up in front of Thonny (or whatever you are running the code in) so that you will be able to see when the LED lights.
WARNING: This program will attempt to set every pin to be an output, so do NOT attach any extra electronics, and reset the board once you've finished testing it.
Run the program, and when the LED blinks, make a note of the pin that was being tested.
When you try and set a pin to be an output, this will either cause an exception (which we can catch) or cause the whole board to crash, or USB communication to fail (which we can't catch). So, if a certain pin seems to be causing a crash, add it to ignore_pins and try again.
Results
I tried this on a couple of boards, with these results.
- ESP32 Lite - 22
- ESP32 Dev Kit 1 - 2
If you try this out and identify the pins used on a board, send a comment (comments moderated, so it may take a while) or @simonmonk2 on X and I'll keep updating this list.
No comments:
Post a Comment