Read input voltage via code?
-
Hi! I have a GPy with the Makr board and a battery connected on the battery +/- 2-pin connector on the board. I want to be able to read how much input voltage I am getting from the battery on the GPy so that I can notify myself in advance before the battery runs out of power.
So, I am wondering if there is there any way I can read how much power the PyCom are receiving from the battery connector in my code? If not, is there anything else I can do?
-
@techykermit If the BAT jumper of the expansion board (pymakr, as you call it) is on place, the battery is connected by a voltage divider to P16. You can get it e.g. with this little script:
import machine adc = machine.ADC() # create an ADC object apin = adc.channel(pin='P16', attn=adc.ATTN_11DB) # create an analog pin on P16 val = apin.voltage() # read the value from ADC print(val * 2) # compensate for the voltage dividerPlease note, that the voltage only allows to estimate the charge. For a LiPo battery, you can assume the battery as almost empty when the voltage is below 3.3V.
-
@robert-hh Thanks! :)
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login