ESP32-S2 connect to and USB-Serial device?

Hi,
I've an ESP32-S2 with built in USB-C connector.
I'm looking on some pointers for a personal DIY hobby project.
I've a device that when is connected to the PC, the PC recognizes it as a Serial (COM port) device, and the device software uses that "virtual" COM port to communicate.
This device is an electricity sensor, the only information that is sending through the usb is a few of configs and electricity status values, like voltage.

Now, instead of a PC I want to use my ESP32 board, and connect the USB-C in OTG mode, to the device.

My Questions here are, how to handle this? Since, somehow my esp32 needs to understand that on the USB port, there is an USB to UART (I guess) device, and data is sent as serial through that...

I'm not sure if this would be possible or not, and how to approach it.
Would somebody help me with ideas?

Thanks

Hello, @fgampel
Let’s explore how you can achieve USB communication with your ESP32-S2 in OTG mode.

USB OTG Console (CDC):
The ESP32-S2 has an integrated USB peripheral that supports the USB Communication Device Class (CDC).
Instead of using an external USB-UART bridge, you can implement a serial console directly via USB.
This allows bidirectional communication, similar to a virtual COM port.
The ROM code in ESP32-S2 already includes a basic USB CDC implementation for console access, flashing, and device firmware updates.
Hardware Connection:
Connect your ESP32-S2 to the USB port as follows:
GPIO 20 (D+) to USB green wire
GPIO 19 (D-) to USB white wire
GND (black) to USB GND
+5V (red) if needed (some development boards provide this internally)
If your development board has an internal USB connector, no extra connections are required.
Software Configuration:
Enable the USB console feature using CONFIG_ESP_CONSOLE_USB_CDC in the menuconfig tool.
Build your project with this option enabled.
Once uploaded, a USB CDC port will appear in the system, allowing communication with your device.
Initial Upload:
If your ESP32-S2 is not yet flashed with a program enabling the USB console:
Use the ROM Download Mode over USB CDC:
Place ESP32-S2 into download mode (GPIO0 low while toggling reset).
Find the serial port name (e.g., /dev/ttyACM* on Linux).
Run idf.py flash -p PORT to upload the application.
Alternatively, use UART upload if your board has a USB-UART bridge.
Subsequent Usage:
After the initial upload, run idf.py flash and idf.py monitor as usual.
Remember to adapt the code to handle your electricity sensor data once the USB console is set up.

Hope this will help you.
Best regards,
thomas945

@fgampel
I'm not sure how to do it but @thomas945 response seem like a bunch of gibberish and is probably spam.

message #2 refers to USB DEVICE but USB HOST is required to work with a USB serial device.

Connecting a USB serial device might be possible but it is complex. I suggest searching esp32.com for "USB host" and github.com for "ESP32 USB host". And espressif.com for "USB host".

I managed to get some USB HID devices working (keyboard and mouse) but have never tried USB serial. You may need to use ESP-IDF instead of Arduino.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.