You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/hardware/03.nano/boards/nano-esp32/tutorials/cheat-sheet/cheat-sheet.md
+34-6Lines changed: 34 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -412,12 +412,14 @@ void setup() {
412
412
413
413
## USB Serial & UART
414
414
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.
416
416
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.
419
421
420
-
### Native USB
422
+
### Serial (Native USB)
421
423
422
424
Sending serial data to your computer is done using the standard `Serial` object.
423
425
@@ -428,9 +430,11 @@ Serial.print("hello world");
428
430
429
431
To send and receive data through UART, we will first need to set the baud rate inside `void setup()`.
430
432
431
-
### UART
433
+
### Serial0 (UART)
432
434
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:
434
438
435
439
| Pin | Function | Description |
436
440
| --- | -------- | -------------------- |
@@ -461,6 +465,30 @@ And to write something, we can use the following command:
461
465
Serial0.write("Hello world!");
462
466
```
463
467
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
+
464
492
## I2S
465
493
466
494
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