Mojo board - How to calculate battery percentage left

I have a question on calculating the battery percent used for the mojo board.

I am using it with a 3.7V 2000mAh lipo battery

I take a reading every 15 minutes ({“req”:“card.power”}) and it has been very consistent, around 20-22 milliamps, then I reset that value: (req, “reset”, true)

Here is an example of the latest reading:
“batterypercent”: 98.88758103,
“chargemilliamps”: 22.2483794,
“voltage”: 3.552389526367187

I want to calculate a battery percentage value and found two ways people have done it.

  1. Based on a table of fixed voltage readings:

float voltagePercentageTable[21][2] = {
{4200, 100}, {4150, 95}, {4110, 90}, {4080, 85}, {4040, 80},
{4010, 75}, {3970, 70}, {3930, 65}, {3890, 60}, {3850, 55},
{3810, 50}, {3760, 45}, {3710, 40}, {3660, 35}, {3610, 30},
{3550, 25}, {3490, 20}, {3430, 15}, {3370, 10}, {3320, 5},
{3000, 0}
}

  1. A calculation of mAh based on battery size: (from what I read this is more accurate to predict capacity left in the battery)

const double TOTAL_BATTERY_CAPACITY = 2000.0;
double remaining_mAh = TOTAL_BATTERY_CAPACITY - consumed_mAh;
double percentage = (remaining_mAh / TOTAL_BATTERY_CAPACITY) * 100.0;

Since I am taking a reading every 15 mins and resetting it, I assumed I need to multiply that by 4 to get an hourly discharge rate of 88.99 mAh ?

e.g. “chargemilliamps”: 22.2483794 * 4 = 88.9935176 mAh
2000 - 88.99 = 1,911
(1911 /2000) * 100 = 95.5 %

BUT at the current voltage of 3.55v that percentage left on the battery seems high to me ? The voltage table seems a little more realistic at around 25%
thoughts ?

Hi @JimK,

Mathematically it sounds like what you are doing is correct (the formula at least) - although is your chargemilliamps a mA (current) reading and not mAh? I ask because if you drop from 100% to 98.887%, that’s about 1.1113% of a 2000 mAh LiPo…which is ~22.26 mAh (for 1 hour, not 15 minutes).

However, I would not trust this in a critical production scenario primarily because:

  1. Your TOTAL_BATTERY_CAPACITY constant is not really a constant. This will decrease as the battery ages.
  2. The deployment temperature is going to significantly impact battery capacity with a LiPo.
  3. Even if your calculations show that, say 30% of the battery’s capacity remains, it still may output too low of a voltage to be usable (especially under load of creating a cellular connection etc).

Rob

Hi @jimk,

It seems to me that if the mojo gives a maH reading, even with a 15 minute readings, it is calculating the total current used for 1 hour, otherwise it shouldn’t be labeled a maH reading. You can check this if you know the average current draw during the fifteen minute interval. Perhaps Rob can comment on this.

If this is the case, your formula doesn’t need to multiply by 4.

Also, the LiPo batteries I use have a fully charged voltage of around 4.1 or 4.2 volts and a voltage of 3.55 volts in my case is already significantly discharged.

When I estimate battery life, I use 80% of the rated battery capacity in my calculations because after a number of charge/discharge cycles that is what the actual capacity will be.

In our equipment, we monitor battery voltage instead of trying to calculate battery life with each reading. Once the battery voltage drops below 3.5 volts experience has shown that we will soon run into problems connecting to the Notehub (battery may not be able to supply sufficient current, especially if it takes longer to connect).

Hope this is of some value.
Karl

thanks you for the replies and suggestions. It sounds like I should take the first approach and try and calculate battery precentage based on voltage

e.g. battery voltage table in milli volts

{4200, 100}, {4150, 95}, {4110, 90}, {4080, 85}, {4040, 80},
{4010, 75}, {3970, 70}, {3930, 65}, {3890, 60}, {3850, 55},
{3810, 50}, {3760, 45}, {3710, 40}, {3660, 35}, {3610, 30},
{3550, 25}, {3490, 20}, {3430, 15}, {3370, 10}, {3320, 5},
{3000, 0}

Hi Rob, I just wanted to clarify your comment on mAh vs mA. The mojo page Mojo Quickstart - IoT Connectivity at Blues says it is the number of milliamp hours (mAh) consumed by your device since it was last reset which is why I was resetting it every 15 minutes to try and get an understanding of how much current it draws. (I think my calc would be wrong if it is mAh, I should not multiply it by 4) I used 15 mins as an arbitrary time since I did not want to wait a full hour to get a reading.

It also says it could be a negative or positive number depending if it is charging or discharging which makes sense.

After re-reading Karl’s comments and yours I have since re-coded it to use a voltage table to estimate battery percentage left and agree with his comments since the doc says mAh not mA, so it should not matter if I check the property “milliamp_hours” every 15 minutes or once an hour it should be roughly the same assuming a equal current usage during that time period ? I will do some more testing to try and confirm.

thanks guys

1 Like

Hi @JimK,

The reason I mentioned the milliamps vs milliamphours issue is you referenced two field that are not from Mojo directly:

“batterypercent”: 98.88758103,
“chargemilliamps”: 22.2483794,

Those must both be derived in your code and I wanted to make sure we were talking the same language :slight_smile:

Rob

Hi @JimK,

To make sure I’m understanding how the mojo board works, I ran the following test. I connected the battery input on our custom Notecard to the output of the mojo. The input of the mojo was connected to the output of a Nordic PPK2 power profiler, and the input of the PPK2 was connect to a LiPo battery. So with the PPK2 I measure current flowing from the battery and with the mojo I measure maHrs of power flowing from the battery.

I collected data for 10 minutes. The mojo read 0.23 maHr at the beginning and 7.83 maHr at the end of the 10 minutes. The PPK2 showed an average current flow of 45.28 ma for the 10 minutes. If I run the test for 1 hour and the average current was 45.28 ma, then according to the PPK2, the current consumption would have been 45.28 maHr, but since the test was only for 10 minutes, the current consumption was 1/6 of 45.28 maHr or 7.55 maHr, which effectively matches 7.6 maHr reported by the mojo.

Jim, your original calculations seem to be correct, and using mojo reading we can determine the hourly power consumption (or any other time interval). But as has been pointed out in this thread, I would be uncomfortable calculating remaining battery life as a percentage of rated battery capacity for a number of reasons:

  1. Battery capacity degrades with charge/discharge cycles and temperature
  2. The battery voltage drops at the end of the discharge life and may not be able to supply enough current to the Notecard so we can never use 100% of battery capacity.
  3. In our application (use solar to charge the battery) I can’t assume the battery is 100% charged.

Your original calculations would probably give you a useful estimate of remaining battery life kept a running total of maHrs consumed and use a batter capacity of say 60 or 70% of rated capacity. (Lose 20% of capacity of battery ages and you can never use the last 10 or 20% of capacity because batter won’t generate enough current for the Notecard).

Here is a graph of the 10 minutes of current measured by the PPK2. The spikes are variations are mostly from the Notecard (in continuous mode).

Hope this didn’t bore anyone, I just had to made sure it was straight in my mind.

Karl

2 Likes

Hi Karl/Rob

I agree for the reasons you mentioned that trying to predict battery percent left using the battery capacity and millamps will not be useful, instead I am now using a table of voltage values to determine percentage which seems to work much better.

I do have a question, how does the mojo board know who to calculate milliampHours ? I thought you had to measure the time period to get such a value ?

e.g. multiply the current in milliamps (mA) by the time in hours (h) the device operates

Does the mojo board have a clock or is getting the time from someplace ?

Rob - My bad on the original post of milliamps vs milliamp hours. I was using this arduino library I found on your web site Recently released a Library for direct interface with blues Mojo. I have since dropped that code and only using the mojo notecard command JObject *req = notecard.newRequest(“card.power”) to get consumed_mAh = JGetNumber(rsp, “milliamp_hours”);

So should I be resetting the mojo card at certain intervals JAddBoolToObject(req, “reset”, true); e.g. if I reset it hourly that should give me a true mAh value ?

btw Karl I saw that device Nordic PPK2 power profiler a few weeks ago and was thinking of getting it for another project but it would come in handy here also :slight_smile:

thank you

Hi, I’ve been an avid fan of the PPK2 for a while, especially as it seemed to be scriptable. Unfortunately, the existing python library from IRNAS hasn’t been updated in a while and has a number of other issues, so I went ahead and created a new one, with the intent of including power profiling reports in CI runs.

It’s still early days, and I’m yet to use it “for real”, but invite you to take a look if you’re curious.