Skip to content

Commit 3cd3327

Browse files
authored
Merge pull request #1759 from arduino/karlsoderby/nano-esp32-uart
[Nano ESP32] Serial Ports update
2 parents 1836bec + 543c7fe commit 3cd3327

File tree

1 file changed

+34
-6
lines changed
  • content/hardware/03.nano/boards/nano-esp32/tutorials/cheat-sheet

1 file changed

+34
-6
lines changed

content/hardware/03.nano/boards/nano-esp32/tutorials/cheat-sheet/cheat-sheet.md

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -412,12 +412,14 @@ void setup() {
412412

413413
## USB Serial & UART
414414

415-
The Nano ESP32 board features 2 separate hardware serial ports.
415+
The Nano ESP32 board features 3 hardware serial ports, as well as a port exposed via USB.
416416

417-
One port is exposed via USB-C®, and
418-
One is exposed via RX/TX pins.
417+
- `Serial` refers to the USB port.
418+
- `Serial0` refers to the first hardware serial port (UART), accessible via the board's RX/TX pins (D0, D1).
419+
- `Serial1` is the second UART port, which can be assigned to any free GPIOs.
420+
- `Serial2` is the third UART port, which can also be assigned to any free GPIOs.
419421

420-
### Native USB
422+
### Serial (Native USB)
421423

422424
Sending serial data to your computer is done using the standard `Serial` object.
423425

@@ -428,9 +430,11 @@ Serial.print("hello world");
428430

429431
To send and receive data through UART, we will first need to set the baud rate inside `void setup()`.
430432

431-
### UART
433+
### Serial0 (UART)
432434

433-
The pins used for UART on the Nano ESP32 are the following:
435+
***Please note: `Serial0` is shared with the bootloader/kernel, which prints a few messages at boot/reset, and in the event of a crash, the crash dumps is printed via FreeRTOS on this serial port. For these reasons, you may want to use the `Serial1` or `Serial2` ports to avoid any interference ([read more](#serial1--serial2-uart)).***
436+
437+
The default pins for UART communication on the Nano ESP32 are the following:
434438

435439
| Pin | Function | Description |
436440
| --- | -------- | -------------------- |
@@ -461,6 +465,30 @@ And to write something, we can use the following command:
461465
Serial0.write("Hello world!");
462466
```
463467

468+
### Serial1 & Serial2 (UART)
469+
470+
The Nano ESP32 features 2 additional hardware serial ports that have no pre-defined pins, and can be connected to any free GPIO. Therefore, to use them, their TX and RX pins need to be manually assigned.
471+
472+
To use `Serial1` and `Serial2`, you need to initialize them in your program's `setup()` function:
473+
474+
```arduino
475+
//initialization
476+
Serial1.begin(9600, SERIAL_8N1, RX1PIN, TX1PIN);
477+
Serial2.begin(9600, SERIAL_8N1, RX2PIN, TX2PIN);
478+
479+
//usage
480+
Serial1.write("Hello world!");
481+
Serial2.write("Hello world!");
482+
```
483+
484+
- Replace `RXPIN` and `TXPIN` with the GPIOs you want to assign (e.g. `D4`, `D5`).
485+
- You can then use commands such as `Serial1.write()` and `Serial1.read()`.
486+
487+
The `SERIAL_8N1` parameter is the configuration for serial communication.
488+
- `8` = data word length (8-bit). Can be changed to 5,6,7-bits.
489+
- `N` = parity, in this case "none". Can be changed to "even" (E) or "odd" (O).
490+
- `1` = stop bit, other option available is 2.
491+
464492
## I2S
465493

466494
The Inter-IC Sound (I2S or IIS) protocol is used for connecting digital audio devices with a variety of configurations (Philips mode, PDM, ADC/DAC).

0 commit comments

Comments
 (0)