Detect if USB is connected

Posts: 1
Joined: Mon Apr 06, 2020 3:03 pm

Detect if USB is connected

Postby CtnAdrian » Mon Apr 06, 2020 3:27 pm


I am using ESP32 WEMOS LOLIN32 board.
The project I am developing is using an external battery to run. I am trying to use USB connection only for charging the battery, and to stop the program execution when it is connected.
Is there any solution to detect (pin, register, interrupt, etc) if USB is connected without changing the hardware (soldering wires to VBUS)?

I can't find anywhere on the internet this information.
Thank you!

Posts: 1656
Joined: Tue Dec 01, 2015 8:37 am

Re: Detect if USB is connected

Postby ESP_igrr » Mon Apr 06, 2020 7:47 pm

Hi CtnAdrian,

On the ESP32 development boards, USB is provided by an external component, usually a CP2102, CP2104 or FT223H chip. These chips do have outputs to indicate whether USB is connected (check respective datasheets). However on all the boards I know these outputs are not wired to the ESP32. You might be able to solder a wire from the respective USB-UART chip pad to one of the ESP32 inputs.

Who is online

Users browsing this forum: No registered users and 10 guests