NANO ESP32 ONBOARD UART and PIN NUMBERING ISSUES

I searched a lot around concerning how UARTS on NANO ESP32 are working, but still have a lot of doubts. Tech specifications report that there are three UARTS on board: SERIAL0, SERIAL1 and SERIAL2.


a. the term "pin" make me crazy, what do they mean? According what? The schematic of the board the "pins" are two headers connectors numbered from 1 to 15. KIKAD as as first "pin" the D1/TX0. "Pin" 0 and "pin" 1 showed above are D1 and D0 but, according to the schematic board are GPIO44 and GPIO43.Different tables from ardino web site state different things.See below


b. SERIAL0 is used by the core to dirive the USB port. If I want to use it for monitoring I just have to add the following lines to my sketch:
Serial.begin(9600);
Serial.println("HELLO");
but shall refer to that UART in this way?
Serial0.begin(9600);
Serial0.println("HELLO");
c. How I can use the other two UARTS? For instance if I want (actually I have to use them, no others "pins" left) to use the D0/RX0 and D1/TX0 "pin" what I have to do? Something like this?
const byte RXD0 = 0; //D0/RX0
const byte TXD1 = 1; // D1/TX0
Serial1.begin(9600, SERIAL_8N1, RXD0, TXD1);
It doesn'work!
d. What about then Serial2? How I can use it?

Serial0 i on RX/TX pins. Serial is the native USB peripheral of the MCU. it is not an UART

Hi @zamparduino.

The I/O pins on the Arduino board.

We assign an arbitrary number to each of the I/O pin. These numbers are used to refer to a pin in the Arduino sketch code.

Those are the low level pin names. The low level pin names are mapped to the arbitrary Arduino pin numbers:

It is not a UART at all. The ESP32-S3 microcontroller produces a USB CDC port which is used to communicate with your PC via the Serial object.

Use the Serial0 object.

For example:

void setup() {
  Serial0.begin(9600);
}

void loop() {
  Serial0.println("hello");
  delay(1000);
}

By default, Serial2 is configured to use GPIO19 and GPIO20. These microcontroller pins are not broken out on the Nano ESP32, so it is necessary to configure the pins in the sketch code. For example, if you wanted to use Arduino pin 9 as RX and pin 10 as TX, you would use it like this:

void setup() {
  Serial2.begin(9600);
  // Configure Serial2 to use pins 9 and 10 as RX and TX
  Serial2.setPins(9, 10);
}
void loop() {
  Serial2.println("hello");
  delay(1000);
}
1 Like

Fig-1 is the pin out diagram of generic ESP32. Locate the DPin numbers for UART0 which is connected with PC, UART1 is not useable and is not shown, UART2 is avilable to user.


Figure-1

Include this line in your sketch:

Serial2.begin(9600, SERIAL_8N1, 4, 5);  //RX2 = GPIO-4, TX2 = GPIO-5

Why do you throw another board in the mix? OP uses a Nano ESP32.

I have brought that generic board to show the DPin locations of the UART0 and UART2 Ports.

When ESP32 and NANO ESP32 boards are compared, the RX2-pin (GPIO-16) is not seen on NANO ESP32 Board.

So, the OP has to re-route the output signals of the UART2 Port of NANO ESP32 into free available Dpins.

This also confuse me a lot, ESP 32 is not NANO ESP 32, pins are diffferent ...

I do thanks all for the support, but if I do the following:


do I need to declare the D0/RX0 and D1/TX0 pins?

You have to look at both NANO ESP32 and ESP32 boards simultaneously to see what is going on with respect to the GPIO pin signal signatures:


Figure-1:


Figure-2:

(1) Arduino NANO ESP32 is of the same form factor of classic NANO.
(2) In Fig-1, D8 correspond to GPIO-17 which is TX2 pin of UART2
(3) In Fig-2, GPIO-16 is the RX2 pin of UART2, and it not available with Fig-1.
(4) etc.

The software name for UART0 is Serial. So, the correct code is:
Seria1.begin(9600);

Guys, so much confusion here. Let me try to clear up the air.

Facts on Arduino Nano ESP32

  • The Arduino Nano ESP32 contains an ESP32-S3 CPU, not an ESP32, so the replies above mentioning an ESP32 are off-topic.
    Yes, it is confusing. Sorry :slight_smile:

Facts on Arduino Nano ESP32 serial ports

  • Serial0, Serial1 and Serial2 are physical UARTs provided by the ESP32-S3 CPU. They can be used as all other UARTs in Arduino.

    • For compatibility with the original Arduino Nano board, the names of the Serial0 I/Os are D0 (aka RX) and D1 (aka TX), and they are in a strange sequence on the side of the board: 1, then 0, then 2, 3, and so on.

    • Serial0 is used by the bootloader and is the "debug UART", therefore there are some "unavoidable" messages being output there at boot and when a critical issue is detected. If you use Serial0, do remember that.

    • The I/Os associated with Serial1 and Serial2 aren't defined. You can use any (otherwise unused) GPIO signal.

  • Serial on the other hand is the "Arduino console", and on the Nano ESP32 it is a virtual UART implemented via USB CDC.

    • The board's USB port is directly connected to the ESP32-S3, which provides this virtual UART emulation. There are no external USB/serial converter chips.

    • Via the Tools -> USB Mode menu of the IDE, you can choose if you want a software CDC implementation (via TinyUSB, provides DFU and ease of use) or a hardware CDC (limited, but allows debugging). Serial remains on the virtual USB port in either case; this is just choosing the "USB driver" on the CPU.

Facts on Arduino Nano ESP32 pin numbers

We want to keep compatibility with all the other boards in the Nano family, so that it is possible to use a sketch made for a different board mentioned there on the Nano ESP32. This has created a conflict, since the ESP32-S3 CPU numbers GPIOs differently.

We have a guide on this subject. What is meant by "pin" depends on how you configure the Tools -> Pin Numbering menu in the IDE:

  • The default choice, By Arduino number, makes the pin numbers in your sketch match the original Nano layout (the orange ones in the first picture). With this option, to access Serial0's TX you need to use 1.

    • This compatibility is however limited to the Arduino API and the simplest libraries. Libraries that use advanced hardware features of the CPU will get confused and you will have all sorts of errors or weird behaviors.
  • If you choose By GPIO number (legacy), the pin numbers in your sketch are interpreted as the hardware GPIO numbers (the green ones in the same picture). With this option, to access Serial0's TX you need to use 43.

    • This is the safe choice for maximum compatibility with libraries. However, you need to use the GPIO (green) numbers in the sketch.

That said, there's an easy way to avoid this confusion and be able to use the same sketch on both pin mappings:

Please, please, please use pin names in your sketch and not numbers. If you write D12 instead of 12, it is obvious you are referring to the pin in the top right of the picture, and the core will transparently map that to 12 (by default) or 47 (in GPIO mode). No headaches!


Hope this is helpful to clean up some misconceptions! Let me know if there's something I've missed.

2 Likes

I want to highlight the recommendation to use the Dx names.
and I recommend to use the "By GPIO number (legacy)" option

@zamparduino Serial0 is configured for pins D0 and D1