How to know when USB power is connected?

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Gambalunga
 
Posts: 63
Joined: Thu Apr 30, 2020 10:45 am

How to know when USB power is connected?

Post by Gambalunga »

I have a clock project using a Feather M0 Express which has a LiPo battery attached.
I have written a section in my code which senses when the battery is at or below 3.5v and then sounds a beep. In this case I ran a test and when the battery arrived at a certain point the voltage dropped to the point where the system stopped. I then reattached the USB power but the beep continued to sound until the battery power was over 3.5v.
Is there any way that I can know that the Feather is now being powered by USB power and the battery is being charged?

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: How to know when USB power is connected?

Post by adafruit_support_bill »

You can monitor the USB pin with an analog pin to measure the bus voltage. You will need to use a voltage divider as is done on the battery monitoring circuit to scale the bus voltage to a safe level for the M0 analog pin.
https://learn.adafruit.com/adafruit-fea ... ry-3122383

User avatar
Gambalunga
 
Posts: 63
Joined: Thu Apr 30, 2020 10:45 am

Re: How to know when USB power is connected?

Post by Gambalunga »

Thanks for the reply.
Just to make sure I understand I would more or less duplicate the voltage divider used for the battery. The resistors could be mounted on the prototyping section. It would be as the image below:
Image

The code to control whether or not the USB power is connected would not even have to double the measured voltage because we are only interested to know if the USB power is active so any voltage greater than, say 2.3 V (to allow for some possible variation) should tell me that USB power is attached (or if doubled > 4.6 V).
Have I understood correctly?
Thanks
Peter

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: How to know when USB power is connected?

Post by adafruit_support_bill »

Yes. That should do it.

User avatar
alpierce
 
Posts: 207
Joined: Mon May 13, 2013 2:44 am

Re: How to know when USB power is connected?

Post by alpierce »

You might think about using 100k resistors if power consumption is at all a concern, and the divider voltage is also a logic high level if you want to use digital input and avoid voltage comparisons.

User avatar
Gambalunga
 
Posts: 63
Joined: Thu Apr 30, 2020 10:45 am

Re: How to know when USB power is connected?

Post by Gambalunga »

alpierce wrote: Thu Mar 16, 2023 6:52 pm You might think about using 100k resistors if power consumption is at all a concern, and the divider voltage is also a logic high level if you want to use digital input and avoid voltage comparisons.
I am not worried about power consumption. I really only want to know if the USB power is connected or, more correctly, if the LiPo battery is being charged. However it was my intention to use 100k resistors. The 1k in the design was one of those midnight lapses in concentration. :-(
The idea of using the divider output as a digital input is a good one, I will see if I can get that working. Thanks.
Peter

Locked
Please be positive and constructive with your questions and comments.

Return to “Feather - Adafruit's lightweight platform”