USB Serial Control (CDC)
The Type-C USB port of the Beetle S1 integrates both MSC (Mass Storage Class) and USB-CDC (Communication Device Class) by default, enabling U-disk storage and serial communication at the same time. When you connect the device to your computer with a data cable, the system automatically recognizes it and creates both a U-disk device and a serial device.
Introduction
This article focuses on the USB-CDC feature, i.e. USB serial communication capability. With this feature, you do not need to install any driver or extra component. Simply connect the Beetle S1 to your computer with a USB data cable and the two can communicate directly — simple and efficient.

Use Cases
- Command control: Run a "serial assistant" tool on your computer to send data or control commands to the Beetle S1, enabling real-time control of the device.
- Data transfer: Data collected by the Beetle S1 can be uploaded directly to the computer via serial communication for further analysis and processing.
Usage Examples
1. Computer Sends Commands to Beetle S1
API:
import sys
cmd = sys.stdin.readline().strip()
Explanation:
- The computer (serial assistant) sends one line of data, and the ESP32-S3 reads it via
sys.stdin.readline(). - The read
cmdis a string with the newline character removed.
Example:
import sys
while True:
cmd = sys.stdin.readline().strip()
print("Received command:", cmd)
2. Beetle S1 Uploads Data to Computer
API:
import sys
sys.stdout.write("data content\n")
# or more simply
print("data content")
Explanation:
- The ESP32-S3 sends data to the computer via
sys.stdout.write()orprint(). - The computer's serial assistant will receive this data.
Example:
import sys
import time
for i in range(5):
sys.stdout.write("upload data: {}\n".format(i))
time.sleep(1)
AI Programming
Because USB-CDC is a standard feature, you don't need to learn it specially. Just let AI generate the functionality you want, then make a few adjustments and start debugging!
Generic Prompt Template
Help me write a MicroPython code that runs on the ESP32-S3 and implements the following via USB-CDC serial communication:
- Function requirements:
- The computer sends commands through serial (e.g. LED ON, LED OFF)
- The device receives the commands and controls the GPIO (e.g. GPIO2 controls the LED)
- The device periodically (every second) uploads simulated sensor data to the computer
- Extra requirements (optional):
- The code should handle exceptions to prevent crashes when the serial connection is interrupted
- The logic should be clear and easy to extend
- Provide complete code, not pseudocode