Due to high demand expect some shipping delays at this time, orders may not ship for 3-4 business days. On MLK Day no orders will be shipped.
0

Measuring battery is almost always constant
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Measuring battery is almost always constant

by lichard49 on Fri Dec 03, 2021 8:47 pm

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

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

Re: Measuring battery is almost always constant

by User_UMjT7KxnxP8YN8 on Sat Dec 04, 2021 12:48 am

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 | TOGGLE FULL SIZE
volatile int batVoltage;

User_UMjT7KxnxP8YN8
 
Posts: 284
Joined: Tue Jul 17, 2018 1:28 pm

Re: Measuring battery is almost always constant

by lichard49 on Sat Dec 04, 2021 12:55 am

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!)

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

Re: Measuring battery is almost always constant

by User_UMjT7KxnxP8YN8 on Sat Dec 04, 2021 3:38 pm

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_UMjT7KxnxP8YN8
 
Posts: 284
Joined: Tue Jul 17, 2018 1:28 pm

Re: Measuring battery is almost always constant

by adafruit_support_mike on Sun Dec 05, 2021 9:32 pm

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?

adafruit_support_mike
 
Posts: 63921
Joined: Thu Feb 11, 2010 2:51 pm

Please be positive and constructive with your questions and comments.