Chapter 1 Serial

Project 1.1 USB_Serial

The Freenove ESP32-S3 Display is equipped with an onboard USB2.0 port, which can be used to upload code to the ESP32-S3.

Meanwhile, it can also abstract the physical USB channel into a virtual COM port based on the USB CDC protocol, enabling the computer host to communicate with the ESP32-S3 through standard serial port tools without requiring additional hardware.

In this section, we will upload code via the USB interface and virtualize it as a serial port (COM) to enable data communication with the computer.

Component List

Freenove ESP32-S3 Display x 1

Chapter01_07

USB cable x1

Chapter01_08

Circuit

Connect Freenove ESP32-S3 Display to the computer with USB cable.

../../../_images/Preface09.png

Configuration

If you have not installed ESP32 SDK in Arduino IDE, please refer to Environment Configuration.

If you have installed it, please continue to proceed.

Select Tools -> Board -> esp32 -> ESP32S3 Dev Module.

../../../_images/Chapter01_09.png

After connecting the Freenove ESP32-S3 Display, the system will assign a serial communication port named in the format ‘COMx’ (where ‘x’ is a numeric ID that may vary across computers). You must select the correct port under Tools → Port.

Note: COM1 is typically NOT the port of the Freenove ESP32-S3 Display.

../../../_images/Chapter01_10.png

Enable the “USB CDC On Boot” feature.

../../../_images/Chapter01_11.png

Please note that when “USB CDC On Boot” is set to “Enable”, the ESP32-S3 will virtualize the onboard USB as a serial port after code upload, enabling serial communication with external devices via the data cable.

../../../_images/Chapter01_12.png

If “USB CDC On Boot” is set to “Disable”, the onboard USB interface can only be used to upload code.

Sketch

Open “Sketch_01.1_SerialRW” folder under “Freenove_ESP32_S3_Display\Tutorial_With_Touch\Sketches” and double-click “Sketch_01.1_SerialRW.ino”.

Sketch_01.1_SerialRW

 1/*
 2* @ File:   Sketch_01.1_SerialRW.ino
 3* @ Author: [Zhentao Lin]
 4* @ Date:   [2025-08-19]
 5*/
 6
 7String inputString = "";      //a String to hold incoming data
 8bool stringComplete = false;  // whether the string is complete
 9
10void setup() {
11  Serial.begin(115200);
12  while (!Serial);
13  Serial.println(String("\nESP32-S3 initialization completed!\n")
14                + String("Please input some characters,\n")
15                + String("select \"Newline\" below and click send button. \n"));
16}
17
18void loop() {
19  if (Serial.available()) {         // judge whether data has been received
20    char inChar = Serial.read();         // read one character
21    inputString += inChar;
22    if (inChar == '\n') {
23      stringComplete = true;
24    }
25  }
26  if (stringComplete) {
27    Serial.printf("InputString: %s", inputString);
28    inputString = "";
29    stringComplete = false;
30  }
31}

Code Explanation

Set the baud rate to 115200.

1Serial.begin(115200);

Determine whether there is data in the serial port buffer.

1+ String("Please input some characters,\n")

Receive serial port data and save it in the inputString string.

1char inChar = Serial.read();         // read one character
2inputString += inChar;

The purpose of this code is to display data on the serial monitor. Click “Upload” to upload the code to Freenove ESP32-S3 Display.

../../../_images/Chapter01_05.png

After downloading the code, open the serial port monitor, and set the baud rate to 115200, input any data in the messages bard and press Enter key, Freenove ESP32-S3 Display will print the received data.

../../../_images/Chapter01_06.png

If your serial monitor remains unresponsive, please verify that “USB CDC On Boot” is set to “Enable”, then recompile and upload the code.

Important notes:

1. When “USB CDC On Boot” is enabled, the USB port serves both for code uploading and as a Serial interface, while the hardware UART port operates as Serial1.

2. When “USB CDC On Boot” is disabled, the USB port is used exclusively for code uploading and cannot function as a Serial interface. In this case, the UART port is Serial.

3. All examples in this tutorial require “USB CDC On Boot” to be enabled by default. To communicate with external devices via the onboard UART, use Serial1 instead, which shares identical usage methods with Serial.

Reference

int available()

Serial.available() checks the number of bytes currently available to read in the Serial receive buffer. It returns the number of bytes available (int type), or 0 if the buffer is empty.

int read()

Serial.read() reads one byte of data from the Serial receive buffer and returns it as an int. If no data is available to read, it returns -1.