Tags:
view all tags
---+ Hardware access, the General Purpose Input Output (GPIO) pins. ---+++ Running the programs on the PC Up to now, all programs we have written can be executed on the ESP32 but also on the PC. Make sure you import <i>time </i>and not <i>utime </i>and do not use _sleep_ms_, but use _sleep_ instead. So... instead of sleep_ms(100) use sleep(0.1) and you will be able to run the programs on your PC with <verbatim>python3 name_of_your_program.py</verbatim> Please give it a try. ---+++ Accessing the hardware The connection of digital input or output signals is made through <b>G</b>eneral <b>P</b>urpose <b>I</b>nput <b>O</b>utput pins. These pins can be programmed to output (control) a signal level or to input (acquire) a signal level. The base board and the back of the CPU card look like this (the pins on the ESP32 CPU are mirrored with respect to the base board): | *The triple base board* | *rThe back of the ESP32 CPU board* | | <img alt="tripleBase.png" height="241" src="%ATTACHURL%/tripleBase.png" title="tripleBase.png" width="471" /> | <img alt="esp32_back.png" height="337" src="%ATTACHURL%/esp32_back.png" title="esp32_back.png" width="283" /> | As you can see, the pins on the triple board are marked | *Left Column on triple base* | *Left Column on CPU board (GPIO)* | *Right Column on triple base* | *Right Column on CPU board (GPIO)* | | RST (Reset) | RST | Tx | TXD | | A0 (ADC) | SVP (IO36) | Rx | RXD | | D0 | IO26 | D1 | IO22 | | D5 | IO18 | D2 | IO21 | | D5 | IO19 | D3 | IO17 | | D7 | IO23 | D4 | IO16 | | D8 | IO5 | GND | GND | | 3V3 | 3.3V | 5V | VCC | 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 [[https://docs.micropython.org/en/latest/esp32/quickref.html#pins-and-gpio][ _Pins and GPIO_ ]]. As you can see, !MicroPython supplies a Python module named _Pin_, which is used to program GPIO pins. In order to control a LED the corresponding pin must be programmed to be an output line. <verbatim>from machine import Pin from time import sleep led = Pin(2,Pin.OUT) # the led is connected to GPIO 2 and this is an output line led.on() # switches the LED on sleep(2) # keeps it on for 2 s led.off() # and switches it off again.</verbatim> Instead of the on() and off() functions, you may also use <verbatim>led.value(1) # switches the LED on led.value(0) # switches it off</verbatim> ---+++ Reading a switch -- %USERSIG{UliRaich - 2022-10-15}% ---++ Comments %COMMENT%
Attachments
Attachments
Topic attachments
I
Attachment
History
Action
Size
Date
Who
Comment
png
esp32_back.png
r1
manage
165.4 K
2022-10-16 - 10:03
UliRaich
png
tripleBase.png
r1
manage
196.1 K
2022-10-16 - 09:59
UliRaich
Edit
|
Attach
|
Watch
|
P
rint version
|
H
istory
:
r5
<
r4
<
r3
<
r2
<
r1
|
B
acklinks
|
V
iew topic
|
Raw edit
|
More topic actions...
Topic revision: r2 - 2022-10-16
-
UliRaich
Home
Site map
AFNOG web
Embedded_Systems web
IoT_Course_English web
IoT_Course_French web
Main web
Sandbox web
TWiki web
AFNOG Web
Create New Topic
Index
Search
Changes
Notifications
RSS Feed
Statistics
Preferences
P
P
View
Raw View
Print version
Find backlinks
History
More topic actions
Edit
Raw edit
Attach file or image
Edit topic preference settings
Set new parent
More topic actions
Account
Log In
Register User
Edit
Attach
Copyright © 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