Difference: HardwareAccessGPIO (3 vs. 4)

Revision 42022-10-16 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="MinimalLectures"

Hardware access, the General Purpose Input Output (GPIO) pins.

Running the programs on the PC

Line: 25 to 25
 
D7 IO23 D4 IO16
D8 IO5 GND GND
3V3 3.3V 5V VCC
Changed:
<
<
In the table above, the IO numbers correspond to the GPIO numbers. As you can see, there are 10 such GPIO lines at your disposal. Most of these lines can be reallocated to different functions. They can be used as serial line (3 serial ports) as I2C ports (2 hardware interfaces) or as SPI ports or mapped to Analogue to Digital (ADC) or Digital to Analog Converters (DAC). During the course, we will see how to reprogram GPIO 36 (SVP) to use the ADC. The CPU has a user programmable LED connected to GPIO 2.
>
>
In the table above, the IO numbers correspond to the GPIO numbers. As you can see, there are 10 such GPIO lines at your disposal. Most of these lines can be reallocated to different functions. They can be used as serial line (3 serial ports) as I2C ports (2 hardware interfaces) or as SPI ports or mapped to Analogue to Digital (ADC) or Digital to Analog Converters (DAC). During the course, we will see how to reprogram GPIO 36 (SVP) to use the ADC. The CPU has a user programmable LED connected to GPIO 2.
 

Accessing the user programmable LED

In order to understand how to access GPIO line we must look up the MicroPython documentation. Select Quick reference for the ESP32 and search for Pins and GPIO .

Line: 50 to 50
 led.value(0) # switches it off

Reading a switch

Added:
>
>
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
push_button.png push_button_back.png
The circuit diagram for s push button switch connection to the ESP32 GPIO line should look like this:

switch.png

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

 -- Uli Raich - 2022-10-15

Comments

Line: 59 to 83
 
META FILEATTACHMENT attachment="tripleBase.png" attr="" comment="" date="1665914356" name="tripleBase.png" path="tripleBase.png" size="200805" user="UliRaich" version="1"
META FILEATTACHMENT attachment="esp32_back.png" attr="" comment="" date="1665914587" name="esp32_back.png" path="esp32_back.png" size="169353" user="UliRaich" version="1"
META FILEATTACHMENT attachment="led.png" attr="" comment="" date="1665938650" name="led.png" path="led.png" size="5815" user="UliRaich" version="1"
Changed:
<
<
META FILEATTACHMENT attachment="switch.png" attr="" comment="" date="1665938650" name="switch.png" path="switch.png" size="5608" user="UliRaich" version="1"
>
>
META FILEATTACHMENT attachment="switch.png" attr="" comment="" date="1665950964" name="switch.png" path="switch.png" size="6579" user="UliRaich" version="4"
META FILEATTACHMENT attachment="push_button.png" attr="" comment="" date="1665948808" name="push_button.png" path="push_button.png" size="276700" user="UliRaich" version="1"
META FILEATTACHMENT attachment="push_button_back.png" attr="" comment="" date="1665948810" name="push_button_back.png" path="push_button_back.png" size="266089" user="UliRaich" version="1"
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback