How do I detect through code if USB power is plugged in? (Arduino IDE)
I can tell with my own eyes if the USB is plugged in. I can upload and run code fine. I can see the red light.
What I’m trying to do is detect through code if USB power is plugged in, while the XIAO is running. I want to use this to run a different LED animation when the USB power is plugged in, to indicate the battery is charging.
PS. I already know how to read the battery level, that’s not what I’m asking here.
your question is pretty interesting. but since you mention that you already know how to read the battery level I’d be very happy if you can give me a hint. (i’m struggling with that)
kind regards
Arsenio
Hi there,
I have this working NOW on the Xiao Nrf52840 Sense, Tells you if the Device is charging or if unplugged.
Pretty sure the PMI or the BMU is similar in the ESP32 so look at that for starters.
HTH
GL PJ
nice! well done!
i tried to use a similar approach on a ESP32S3, it leads to crashes
Hi there,
I read the WiKi and looked at schematic. not Possible , You can’t do it on the Seeed Xiao ESP32S3 ? which is nutz. imho
HTH
GL PJ
The 5V output is direct from USB, it should only be active when plugged in. Set up the same resistor schematic as with the battery level reading to split the 5v into a digital or analog input.
I’m trying to find the same without needing to use a port, but so far no luck. Hope this helps.