While for the previous exercises as well as for programming the user LED we only needed the CPU card, the push button is located on a second card (sometimes also called shield). If you look at the backside of the card very, very attentively, you may see that there is a bridge from the D3 pad (GPIO 17) to the middle pad. This means that the push button is connected to GPIO 17 by default. Cutting this bridge and creating a solder bridge from D1 .. D7 to a middle pad allows reconfiguring the push button and use it on a different GPIO line
The circuit diagram for s push button switch connection to the ESP32 GPIO line should look like this:
You can see, however, that there is no (pull-up) resistor on the pushbutton card. In fact, we can connect such a pull-up resistor by program on the ESP32 GPIO line.
Here is a script that reads the state of the pushbutton switch every 100 ms and prints the result:
from machine import Pin
from time import sleep_ms
pb = Pin(17, Pin.IN, Pin.Pin.PULL_UP) # set the GPIO line 0 to input and add a pull-up resistor
while True:
if pb.value() : # if we read a high state, the switch is not pressed
print("Push button is released")
else:
print("Push button is pressed")
sleep_ms(100)
I think we are ready for another exercise session ExerciseSheets#ThirdSession
In the next step, we will read analogue signal levels: AnalogSignals |