Measuring battery is almost always constant

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
lichard49
 
Posts: 2
Joined: Fri Dec 03, 2021 8:38 pm

Measuring battery is almost always constant

Post by lichard49 »

Hi!

I'm using an Adafruit Feather 32u4 Bluefruit LE with LiPo batteries of varying capacities. I'm using the code on the Power Management page of the board to make the measurement (basically reading pin A9) and then setting the battery value BLE characteristic using the Adafruit_BLEBattery class. Across multiple runs, the values generally just sit at 94%; when it's full, sometimes the value will start at 97%, but more importantly, there is no decline or indication of low power before it dies. However, if the battery is empty and I start charging it, the reported value will start at around 65% and increase. Are there any tricks that I'm missing to get a more accurate reading (or at least a low battery warning)?

Thanks!

Richard

User avatar
User_UMjT7KxnxP8YN8
 
Posts: 323
Joined: Tue Jul 17, 2018 1:28 pm

Re: Measuring battery is almost always constant

Post by User_UMjT7KxnxP8YN8 »

If you're coding in C or C++, try declaring the variable to which your voltage reading is stored as "volatile" to prevent the compiler from optimizing out the pin read. E.g.,

Code: Select all

volatile int batVoltage; 

User avatar
lichard49
 
Posts: 2
Joined: Fri Dec 03, 2021 8:38 pm

Re: Measuring battery is almost always constant

Post by lichard49 »

Thanks for the suggestion! Since the value does increase when it is charging, do you still think it's an optimization issue? (I will try it nonetheless!)

User avatar
User_UMjT7KxnxP8YN8
 
Posts: 323
Joined: Tue Jul 17, 2018 1:28 pm

Re: Measuring battery is almost always constant

Post by User_UMjT7KxnxP8YN8 »

I'd have to see the assembly code the compiler generates to answer that. But I have had similar problems myself on other boards that I solved this way, so it's worth a try.

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: Measuring battery is almost always constant

Post by adafruit_support_mike »

Step back to simpler code for the sake of testing.

Instead of calculating a voltage, just print the raw ADC reading from the battery voltage divider. Do those decrease in a reasonable way as the battery discharges?

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

Return to “Feather - Adafruit's lightweight platform”