How to Make a USB Virtual COM Port
In this article
Yes, you can create a USB virtual COM port by using a microcontroller or USB-to-serial chip that supports CDC (Communication Device Class) mode, allowing your computer to recognize the device as a serial port over USB. This is commonly used for embedded development, debugging microcontrollers, or connecting legacy software that relies on serial communication. You’ll need compatible hardware and proper drivers, but no additional software is required if the device follows USB standards.
What You'll Need
- A microcontroller or development board that supports USB CDC (e.g., Arduino Leonardo, Teensy, STM32, ESP32)
- USB A-to-B, A-to-Micro, or A-to-C cable (depending on your board)
- Computer with available USB port (Windows, macOS, or Linux)
- Appropriate IDE and board drivers (e.g., Arduino IDE, STM32CubeIDE)
- Basic knowledge of embedded programming (C/C++)
Step-by-Step
- Choose a microcontroller that supports native USB CDC functionality. Boards like the Arduino Leonardo (ATmega32U4), Teensy series, STM32F103, or ESP32-S2/S3 are ideal because they can emulate a USB serial device without external chips.
- Install the necessary development environment. For Arduino-compatible boards, install the Arduino IDE and add support for your board via the Board Manager (e.g., install Teensyduino for Teensy, or ESP32 package for ESP32).
- Connect your microcontroller to the computer using a USB cable. Ensure the board powers on — the built-in LED should light up.
- Open your IDE and select the correct board and port. In Arduino IDE, go to Tools > Board and choose your model (e.g., Arduino Leonardo). Then, under Tools > Port, look for a new COM port (Windows) or /dev/cu.usbmodem or /dev/ttyACM (macOS/Linux).
- Write or upload a sketch that enables the virtual COM port. For Arduino, use Serial.begin() and Serial.print() functions. The Leonardo and similar boards use Serial for the virtual COM; avoid using Serial1 if it refers to hardware UART.
- Upload the sketch. After upload completes, the board will reset and reconnect as a USB CDC device. Your computer will recognize it as a serial port.
- Test the connection using a terminal program like PuTTY (Windows), screen (macOS/Linux), or the Arduino Serial Monitor. Open the correct COM or tty port at the baud rate used in your code (e.g., 115200).
- Send and receive data. If you see output from the board or can send input that triggers a response, the virtual COM port is working.
Common Mistakes
- Using a board without native USB CDC support (e.g., Arduino Uno with CH340 or FTDI chip): these use external USB-to-serial converters and do not create a true virtual COM port via CDC.
- Selecting the wrong board type in the IDE, which prevents proper USB enumeration.
- Uploading code that doesn’t initialize Serial, or using Serial1 instead of Serial on CDC-capable boards.
- Using a charging-only USB cable that doesn’t transfer data.
- Not waiting long enough for the OS to install drivers — Windows may take 10–30 seconds to recognize the device.
Tips
- Use boards with native USB like the Teensy or ESP32-S2 for reliable CDC support.
- In Arduino IDE, check the verbose output during upload to confirm the correct port is being used.
- On Windows, open Device Manager to verify the COM port appears under Ports (COM & LPT).
- Use screen /dev/cu.usbmodemXXXX 115200 on macOS or screen /dev/ttyACM0 115200 on Linux to test quickly.
- If the port disappears after upload, ensure your sketch starts Serial in setup() and doesn’t hang before it initializes.
Troubleshooting
If the virtual COM port does not appear:
- Restart the board and computer — sometimes USB enumeration fails on first connection.
- Try a different USB cable — some cables only charge and lack data lines.
- Check Device Manager (Windows) or dmesg (Linux/macOS) for USB detection. On Linux, run dmesg | grep -i usb after plugging in to see if the device is recognized.
- Reinstall board drivers — for Teensy, reinstall Teensyduino; for STM32, reinstall ST’s drivers.
- Ensure no other application is holding the port open. Close all serial monitors or terminal programs.
- Verify the board is programmed correctly — upload a basic blink + Serial print sketch to test both functions.
- If using ESP32, ensure USB CDC is enabled in menuconfig if using ESP-IDF; in Arduino, use #include <USB.h> and USBSerial.begin() for some models.
Frequently Asked Questions
Can I make a virtual COM port with an Arduino Uno?
No, the Arduino Uno uses an external USB-to-serial chip (like ATmega16U2 or CH340) to provide COM functionality. It does not act as a native USB CDC device, so it’s not a true virtual COM port in the CDC sense.
Do I need drivers for the virtual COM port?
Most modern operating systems support USB CDC natively. Windows 10/11, macOS, and Linux typically install drivers automatically. Some boards (like older Teensy models) may require a custom driver, available from the manufacturer.
Why doesn’t my computer detect the COM port?
This can happen due to a faulty cable, incorrect board selection, or the sketch not initializing Serial. Check connections, use a known-good data cable, and verify your code calls Serial.begin() in setup().
Can I have multiple virtual COM ports on one device?
Generally, no. A single microcontroller can only present one CDC serial interface unless it supports multiple USB configurations, which is rare and requires advanced firmware.
Is a virtual COM port the same as USB-to-serial?
No. A virtual COM port uses USB CDC to emulate a serial port directly over USB. USB-to-serial involves a physical chip converting USB signals to UART, appearing as a COM port but not using CDC mode.
Can I use this with Raspberry Pi?
Yes, but only if the Pi acts as a USB device (not host). Models like Raspberry Pi Pico have native USB CDC support and can act as a virtual COM port when programmed with the correct SDK.