UART over USB (CDC/VCP)
Describe the problem you have/What new integration you would like
I would like to have the option to use the USB hardware port on selected platforms (R2040, ESP32-C3/S2...) as UART bus. Similar to how the logger component can use the USB_CDC as hardware port but then for the uart component.
Please describe your use case for this integration and alternatives you've tried:
With this functionality it is possible to write new/custom components that require UART over USB. e.g. I could make an AT command component to control the ESPHome device with a host, or the other way around (some solar inverters use ModBus over USB CDC/VCP to communicate).
Additional context
like this one? https://github.com/esphome/esphome/pull/7520
like this one? esphome/esphome#7520
I saw that pr, but I'm not sure it is the same issue. I'm really just looking to do this:
uart:
hardware_uart: USB_CDC
instead of rx/tx_pin or port
should be as for now USB_CDC or USB_SERIAL_JTAG are only for logger. With this you could use it for anything else - as a standard serial port, HID on some never even as USB OTG.
should be as for now USB_CDC or USB_SERIAL_JTAG are only for logger. With this you could use it for anything else - as a standard serial port, HID on some never even as USB OTG.
Yes, thank you. I indeed looked into it a bit, but this also requires changes to the uart component I expect. This features request is still valid in that case (independent from how other USB related things will be implemented).
I don't know the code base that well, but it might be a small change to support UART over USB already for the uart component as it is already implemented for the logger.
With this you could use it for anything else - as a standard serial port, HID on some never even as USB OTG.
Not exactly. USB OTG is a host function, can can't be used at the same time as USB client mode, which is what this request relates to. Using the USB-CDC or JTAG serial as a UART shouldn't be hard since it's built into the microcode and would not need changes to the UART component, just need to implement the UART class in a separate component. HID would need a significant amount of new code.
Sure not with the host one, but would be possible to make similar for otg... - mentioned that how it is with usb in general. And Tom is already working on HID.
Hello, This improvement would be very useful in my case, my heat pump communicates in serial with a gateway in USB CDC. To replace the manufacturer gateway by a DIY one with esphome, I need a bridge USB CDC/TTL. With this new feature the esp32 s2 would be sufficient.
@clydebarrow could you give some pointers on how to implement this. I might be able to implement it with some help 🙂
Depends what "this" is. If it's the subject of this feature request, i.e. a USB client as a UART component, then I have not looked at it.
Depends what "this" is. If it's the subject of this feature request, i.e. a USB client as a UART component, then I have not looked at it.
Oh yes sorry for not being clear. I indeed ment USB client as UART component (what the logger component is using currently).
Just I was looking for this. I have a climate device that uses a USB connector as UART and I have bought a ESP32-C3 to try to use the USB as UART, but I see that for now is not possible.
@Danixu, maybe @clydebarrow's solution will work for you.
ESP32-C3 to try to use the USB as UART, but I see that for now is not possible.
You need an S3 or S2. The C3 does not support USB OTG.
Luckily the ESP32 is a cheap hardware 😅 . I'll try to buy some S3 and I'll test it. For now I have soldered a USB cable to the GPIO1 and GPIO3 pins to use the normal UART, but I prefer a cleaner approach.
Thanks!!
anyone is working on it? I also need this :) It could be implemented using rom firmware or tinyusb.
Isn't this done already?
https://esphome.io/components/usb_uart/
Isn't this done already?
https://esphome.io/components/usb_uart/
This seems OTG host mode where you can connect serial device https://en.wikipedia.org/wiki/USB-to-serial_adapter to esp. I would like to have it the other way around.
Do you want to achieve something like communicating via serial from a computer for example? Computer SerialPort <--> ESP
There is some confusion here. USB host support has been added. This allows you to connect a USB serial device to the ESP, like a USB-TTL adapter. But this is not what the original request was for. What is requested here is to be able to plug the ESP USB port into a computer and have some component be able to communicate with the computer instead of sending logs. This only applies to devices like the S3 and C3 that have native USB. Someone was recently looking at implementing this, but I'm not sure how far he got on it.
I wonder what would be a use case for this.
I was doing something similar here: https://github.com/AzonInc/Doorman/blob/dev/components/tc_bus_serial/tc_bus_serial_component.cpp
Example usecase app: https://dev.doorman.azon.ai/reference/esphome-component-serial
I wonder what would be a use case for this.
In my case there is a Desktop application to configure devices on an intercom bus. They offer a USB interface that communicates via serial.
Now if you want to build your own cheap bus interface for this application, you also need to be able to use the serial connection.
https://github.com/esphome/esphome/pull/11634 I started implementation for nrf52.
There is also work being done here:
https://github.com/esphome/esphome/pull/11687