Using a second Serial Port

On the ESP32 UART0 is normally reserved for interactive use with REPL. Sometimes we need a UART to communicate with external devices. Typical examples are:
  • fingerprint readers using a serial communication protocol
  • GPS modules
The ESP32 has 3 UARTs of which however UART1 is reserved for use with flash memory. However, UART2 is free.
Normally Rx is connected to GPIO 16 and Tx to GPIO 17 but these are forbidden on the CPU card we use (see The hardware). It is possible however to remap these signals to different GPIO pins, in our case to GPIO 21 and 22.

Connect the USB to Serial adapter to the ESP32 as shown in the table below

USB to Serial Adapter ESP32 pins
Rx GPIO 21
Tx GPIO 22
Gnd Gnd
As a first quick test, we can try to write "Hello World to UART2 to which we connect a minicom virtual terminal.

thonny is connected to UART0 on /dev/ttvUSB0 (connect this first). minicom is connected to UART2 on /dev/ttyUSB1. Start minicom with:

minicom -D /dev/ttyUSB1

Here is the screen dump of the REPL session

uart2-v2.png

And this is what we see on minicom:

uart2-minicom.png

... if you are too lazy to type, here is the corresponding script:

https://iotworkshop.africa/pub/IoT_Course_English/SerialPorts/uart.py.txt

-- %USERSIG{UliRaich - 2020-05-09}%

Comments

 

I Attachment Action Size Date Who Comment
uart.py.txttxt uart.py.txt manage 237 bytes 09 May 2020 - 20:01 UnknownUser  
uart2-minicom.pngpng uart2-minicom.png manage 23 K 09 May 2020 - 19:57 UnknownUser  
uart2-v2.pngpng uart2-v2.png manage 26 K 12 Oct 2020 - 15:42 UnknownUser  
uart2.pngpng uart2.png manage 26 K 12 Oct 2020 - 15:40 UnknownUser  
This topic: IoT_Course_English > WebHome > SerialPorts
Topic revision: 12 Oct 2020, UliRaich