ESP32_BAT detect USB connection
ESP32_BAT detect USB connection
Is there a way to detect when the USB cable is connected and powering the board? I would like to keep the board awake, when that is the case, to allow for setting up Wi-Fi credentials.
Re: ESP32_BAT detect USB connection
I have very similar goals, and it can be done. I'm a little surprised there is not a way to do this natively with the hardware. However, the USB-UART bridge drives its TX line high when the USB is connected. When it is disconnected, the bridge makes it high impedance. I'm using the ESP-IDF library, which sets up this signal to pull high within the ESP. I override this and pull it down using:
gpio_set_pull_mode(GPIO3, GPIO_PULLDOWN_ONLY);
Then you can use software to detect when this line goes low (e.g. using a BREAK character interrupt) indicating the USB is no longer plugged in. Likewise you could use a rising interrupt to indicate the USB is re-plugged.
gpio_set_pull_mode(GPIO3, GPIO_PULLDOWN_ONLY);
Then you can use software to detect when this line goes low (e.g. using a BREAK character interrupt) indicating the USB is no longer plugged in. Likewise you could use a rising interrupt to indicate the USB is re-plugged.
Re: ESP32_BAT detect USB connection
I have seen this thread and some other users emailed me. There isn't a way of detecting if the USB power is present. It is an oversight in the design of the board. There's a way that will work if you are prepared to add external resistors.
The Vin pin will have voltage on it only if the USB connector has power applied to it. You can connect a voltage divider from Vin and ground and tie the junction to an ADC pin. This will allow you to measure the Vin voltage and decide if there's good power available.
The Vin pin will have voltage on it only if the USB connector has power applied to it. You can connect a voltage divider from Vin and ground and tie the junction to an ADC pin. This will allow you to measure the Vin voltage and decide if there's good power available.