ESP-WROOM-32: UART1 and UART2 pins - Page 1
Forum section: electronics / general

author: Holup
author_rank: Newbie
timestamp: June 10, 2024, 06:50:24 am
content: Hi,I want to use an ESP32 for the first time in a project, but am a bit confused about UART1 and UART2 pins and multiple versions of the ESP32 and modules.I bought a few of these modules:https://www.aliexpress.com/item/1005004268911484.htmlI eventually want to use a bare ESP32 instead of the module, probably this one, as it seems to be only one available at LCSC:https://www.lcsc.com/product-detail/WiFi-Modules_Espressif-Systems-ESP32-WROOM-32-N4_C82899.htmlI am attaching a pinout image I found on the internet, that mostly resembles my modules.It says U2_TXD is GPIO17, and U1 is not shown at all.When I uploaded this code and scoped all the pins...Code:Serial.println( "UART0 - PC" );Serial1.println( "UART1" );Serial2.println( "UART2" );... I found out that Serial1 (U1_TXD) is my GPIO27, and Serial2 (U2_TXD) is my GPIO25.(I did not specify any pins when initializing the connection.)I could not find any information online when this could be happening.I am uploading the code via Arduino IDE. I downloaded esp32 boards definitions by Espressif. Selected board is "ESP32 Dev Module".Maybe something wrong with my board selection?Can UART1 and UART2 be mapped to different pins in case my modules use pin incompatible ESP32 with the one from LCSC?

author: elektryk
author_rank: Regular Contributor
timestamp: June 10, 2024, 08:10:35 am
content: Look at the begin() method.https://microcontrollerslab.com/esp32-uart-communication-pins-example/

author: selcuk
author_rank: Frequent Contributor
timestamp: June 10, 2024, 08:41:52 am
content: You can reassign the UART pins to any GPIO. But I recommend to keep UART0 as is and reassign UART1 & UART2 to keep things simple.By the way, that one is a module as well. Bare ESP32 is this one:https://www.lcsc.com/product-detail/RF-Transceiver-ICs_Espressif-Systems-ESP32-D0WD-V3_C967021.html

author: Holup
author_rank: Newbie
timestamp: June 10, 2024, 01:16:52 pm
content: Thanks for the responses.I took a look at `HardwareSerial.h` file located at `C:\Users\holup\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.1`I got the file location from verbose compile output of Arduino IDE.Here I found my default pin definitions...Code:#if CONFIG_IDF_TARGET_ESP32#define RX1 (gpio_num_t)26...#if CONFIG_IDF_TARGET_ESP32#define TX1 (gpio_num_t)27...#if CONFIG_IDF_TARGET_ESP32#define RX2 (gpio_num_t)4...#if CONFIG_IDF_TARGET_ESP32#define TX2 (gpio_num_t)25It seems that in my case:RX1 = GPIO26TX1 = GPIO27RX2 = GPIO4TX2 = GPIO25(I did not verify the RX pins on my board yet)There are different pins defined for `CONFIG_IDF_TARGET_`: `ESP32`, `ESP32S2`, `ESP32C2`, `ESP32C3`, `ESP32S3`, `ESP32C6`, `ESP32H2`I found definition for these constants in `C:\Users\holup\AppData\Local\Arduino15\packages\esp32\tools\esp32-arduino-libs\idf-release_v5.1-442a798083\`Here are directories: `esp32`, `esp32c3`, `esp32c6`, `esp32h2`, `esp32s2`, `esp32s3`Is one of these folders set by selecting the board in the Arduino IDE?How would I notice if I had wrong board/config location selected? Would it fail completely, or would I, for example, have pins in unexpected places?Each folder contains two files `sdkconfig.h` in dirs `dio_qspi` and `qio_qspi`. They define constants like `CONFIG_IDF_TARGET_ESP32`.What are `dio_qspi` and `qio_qspi` and how to find out which one am I using or should use?Where does the discrepancy between my config and most pinouts I found online come from?

author: tooki
author_rank: Super Contributor
timestamp: June 15, 2024, 12:06:50 pm
content: Quote from: Holup on June 10, 2024, 06:50:24 amYes, you can remap.But let’s clear up ESP32 terminology, because you’re using it exactly wrong.The thing you’re calling a “module” is known as adev kit, or board, in the ESP32 world.The thing you’re calling a “bare chip” is actually called amodule.An actual bare chip ESP32 exists, and is literally the MCU IC itself, and won’t function until you add a crystal, caps, and in most cases flash memory. If you use one with WiFi or Bluetooth, you have to then get it certified.A module contains the bare chip and all necessary support components, with a metal shield can, on a small, thin PCB with edge castellations, which needs to be soldered to a bigger PCB. An ESP32 module is certified for its radios and is ready to use.A dev kit contains a module, plus USB bridge chip and a voltage regulator, on a PCB with pins.