Measuring battery percentage
Posted: Fri Mar 22, 2019 3:13 pm
Hi everyone!
I am currently working with a Pycom device, Sipy more precisely and am trying to read some battery level and display its percentage. Concerning the cabling, the black wire is linked to the ground and the red one (which usually corresponds to the supply I gues) is connected to the pin I'd like to measure the values on. I am using a 12 bits ADC to read the voltage then I use some mathematics to convert it into percentage. However, the results I get don't seem right which is why I am wondering if my code is correct. Does somebody have any clue ? You can find below the code programmed, which is actually very simple. I apologize in advance for my poor knowledge on electronics. I put below the Python code I wrote, which is very simple.
Thanks a lot for your help
def battery_level():
adc=machine.ADC()
apin=adc.channel(pin='P20')
b=(apin()/4095)*100
return(b)
I am currently working with a Pycom device, Sipy more precisely and am trying to read some battery level and display its percentage. Concerning the cabling, the black wire is linked to the ground and the red one (which usually corresponds to the supply I gues) is connected to the pin I'd like to measure the values on. I am using a 12 bits ADC to read the voltage then I use some mathematics to convert it into percentage. However, the results I get don't seem right which is why I am wondering if my code is correct. Does somebody have any clue ? You can find below the code programmed, which is actually very simple. I apologize in advance for my poor knowledge on electronics. I put below the Python code I wrote, which is very simple.
Thanks a lot for your help
def battery_level():
adc=machine.ADC()
apin=adc.channel(pin='P20')
b=(apin()/4095)*100
return(b)