read_battery_voltage() Voltage value to Battery Level



  • Hi all, have a FiPy & a Pysense with 2000mAh LiPo battery.
    Found some good info on the forums to get its voltage from the pycoproc.py library.
    Using it as follows:

    from pysense import Pysense
    py = Pysense()
    print(py.read_battery_voltage())
    
    >> 4.656595
    

    What's the best way to convert that into a rough battery level precentage.

    I thought perhaps the 1S chart values from here (https://blog.ampow.com/lipo-voltage-chart) but I imagine its not as simple as just doing the conversion math.

    Screen Shot 2020-11-20 at 3.04.32 PM.png

    Screen Shot 2020-11-20 at 3.03.48 PM.png

    Is there anything I'm missing?



  • @claus and @kjm excellent tips guys thank you.
    I'm going to do both, first with the quick and dirty:

    battery_voltage = read_battery_voltage()
    roughbatt = (battery_voltage - 3.25)*100
    
    print(roughbatt)
    
    >> 92.00001
    

    Whilst also recording raw timestamped voltage from full to empty (last transmission) a few times and basically just dividing that scale and tweaking above.



  • @barryjump A typical lipo discharge curve looks like this

    alt text

    If you want more precise results than a linear interpolation you could easily measure the curve with your device. Write a program with more or less constant power consumption, say sending the voltage every minute via WiFi. Then just record voltage over time. Inverting this curve gives time left until discharge (which you set as a given voltage) over voltage and you can use this result to get a quite precise percentage of charge for your device and ambient conditions for any voltage. The curve changes as the battery degrades, laptops and phones remeasure it over time.



  • @barryjump If you take 4.25v as fully charged and 3.25 as empty then (Vbatt-3.25)*100 is a quick & dirty battery percentage.



  • @jcaron Good info thanks a bunch. Had a hunch that that was the case.

    I think I'd be happy with a 0-25%, 25-50%, 50-75%, 100% scale so I might be able to get close to that as you mentioned. Basically pretty low res estimation would suffice for now.



  • @barryjump no, it’s not that simple.

    First, you should use the chart for the specific battery you are using. Even though batteries with the same chemistry should have similar profiles, it’s not a given that they are identical.

    Next, battery discharge profiles can vary a lot with temperature and with the actual load (though this depends on the battery type – some are very sensitive to either or both, others much less).

    Next, you’ll notice that the curve for LiPo batteries is quite steep when close to full charge and to low charge, and very flat in the middle part. It’s so flat that imprecisions in readings (ADC noise, temperature variations...) can result in wild fluctuations in the result.

    I’m not quite convinced by the values in the table either.

    You can definitely get a sense of the battery state (e.g. over 4 V means the battery is close to being fully charged). But it’s difficult to get an accurate and consistent status all along the discharge curve, especially along the pretty long and flat middle section. So you may end up with 3 states: pretty darn full, somewhere in the middle, nearly empty, but the first and last will be pretty short.

    Of course YMMV depending on the environment (indoors vs outdoors), the specific battery type, the load profile...


Log in to reply
 

Pycom on Twitter