Librem5 BatteryJuice measurement

Here’s a little scipt I wrote, you might as well just click down-load:notes:

I wanted to play a bit with my new device and see how changing some settings etc. affects battery life. As I am certainly not patient enough to go through a full charge cycle to measure an effect, I wrote this lil script. It can

  • dump info on battery and charger
  • print charge state (and diff) in intervals

For example, I wanted to see what happens if you disable 3 of 4 cores. (Spoiler: basically nothing)

On the Librem 5, the granularity of the charge level measurements seems to be 3mAh.
Thus when idle, that leads to a changed reading every 30…40s.

In other words, with a 10 second interval, the difference is either 0 or 3mAh.
In a minute, it’s either 3mAh or 6mAh.

Consequently, when measuring an idle device, choose the minute interval ./batteryjuice -w and wait 10 minutes. Every 10 minutes, an accumulated difference is printed.

    Time  remaining    %    °C       mAh  diff mAh  accumulated diff (mAh)
22:41:03   12.47.20   87  28.5  3893.221            
22:42:03   13.46.30   87  28.3  3890.221    -3.000  
22:43:04   13.43.01   87  28.2  3884.223    -5.998  
22:44:04   13.27.56   87  27.9  3878.224    -5.999  
22:45:04   13.22.35   87  28.0  3875.224    -3.000  
22:46:04   13.17.54   87  28.0  3869.226    -5.998  
22:47:04   13.38.26   87  27.9  3866.226    -3.000  
22:48:05   13.23.20   86  27.7  3860.227    -5.999  
22:49:05   13.18.00   86  27.6  3857.228    -2.999  
22:50:05   13.05.37   86  27.7  3851.229    -5.999  
22:51:05   13.18.05   86  27.6  3845.230    -5.999  -47.991
...

So, my idle consumption (display off, WiFi+ssh) is 4.5…4.8mAh per minute
And with screen on, very mild usage (playing 2048)

  • 15mAh at full brightness
  • 10mAh at very low brightness

Which means, at night in your bed you can save about 5mAh per minute :wink:
Also, the display seems to consume 5…10mAh per minute, depending on brightness.

6 Likes

not sure what all those numbers mean, if I leave the phone idle, I lose about 8% charge an hour, its much worse when actually using it as any phone is. Battery draining being idle is an issue, but minor nitpick for me, whats way worse is that charging it takes forever to get to 100%. Basically if one is to make this a daily driver, should really have a power source around at all times or a second battery.

1 Like

The columns are:
Current time (24h format)
Remaining run-time untill battery is empty (according to battery chip)
Charge level in %
Battery temperature
Charge level in mAh
Difference to previous reading in mAh

What that gives you is precise numbers to compare instead of merely having the current percentage.

Well, I’ll have to disagree.
All batteries slow down when approaching 100%. It’s not about this particular device/battery. Other devices might force a somewhat quicker charge, but degrading the battery faster in doing so.

On the contrary, if idle consumption could drop from 5mAh to, say, 2mAh, that would be huge.
Not only would it last a whole day then, it would also not have to recharge as much if you plug it as often as now, thus your point on charging speed would matter less.

I’m not sure, but I think suspend will even reduce consumption while the screen is on. But that is precisely a thing that can be monitored with this script: how updates change these numbers :slight_smile:

3 Likes

Power Delivery protocol slowdown the charger after 80% this is made for to preserve the batt.
As far as I know the Suspend Mode it only for screen off.
I am quite curious why the L5 it eating to much batt with all HKS off, Purism already implemented inactive mode to CPU.

1 Like

This.

If you actually monitor the charging current, you can see this in action. Starts off at around 1.6A (say, when the battery is at 20%). Charging current mostly declines throughout the charge. By the time the battery is getting close to 100% the charging current is tiny.

I’m sure @Caliga could modify the script to demonstrate that. :wink:

I think the bottom line is: If you don’t need to charge to 100% then only charge to 80%. You will be kinder to your battery and you will spend much less time charging.

2 Likes

I did a quick test with all HKS off and screen off, so my L5 is spending 4% per hour.

Yeah but the charge also is affected by the temperature, because the PD monitor the temp too, so the charge under PD is dynamically some times.

1 Like

Nice script. Bug report and change request:

  1. The abort with any key does not seem to be implemented.
  2. CR: as idea print also the CPU idle value, like 98%, to raise attention if this is not around 98%
  3. CR: print the top CPU consumer(s), don’t have an idea how to implement this without draining to much energy by the script itself
1 Like

Yeah, kinda forgot that, because with ssh Ctrl+C is sufficient.
Fixed :slight_smile:

Also new:

  • (dis)charge rate
  • should work on Librem Laptops now, too

I didn’t immediately find where to get that value (I guess one in /proc/stat ?)
Anyway, like with the second request, I feel like this might be beyond the scope of this this tool.

It’s supposed to show the power draw in different scenarios, e.g. screen on/off, WiFi on/off, etc.
It’s not intended to point out what the scenario is.
As most of the power (in idle-to-moderate-usage scenarios) goes to the system, pointing at a process is also somewhat misleading.

There are better tools for finding offending processes, so I included them in the updated description.
For example, I assume that once we have a proper suspend, it might be (much more) interesting to see which processes wake up how often (see interrupts in powerstat)

1 Like

now that you have an Librem 5, have you tested this? https://codeberg.org/caliga/DownStream

Never got to it sorry

2 Likes

Well, yes, but…

no! I mean, yes there’s a slowdown but that has nothing to do with the USB Power Delivery protocol.

In the following output you can see a short pause where the battery reached ~55°C, at which point I also quickly unplugged it to place it on a cool stone surface.

But in general the charging current goes back linearly. And if my rusty electrics knowledge serves me well, that should be because of good old I = U/R, where battery internal resistance increases during charging.

Click to see: batteryjuice output during charging from 38-98%
purism@pureos:~$ ./batteryjuice -w
    Time  remaining    °C  charge mA    %       mAh  diff mAh  accumulated diff (mAh)
21:52:20  102.23.54  35.0       1640   38  1688.662            
21:53:20  102.23.54  35.8       1659   39  1715.656   +26.994  
21:54:20  102.23.54  36.3       1646   39  1742.651   +26.995  
21:55:20  102.23.54  36.7       1644   40  1772.645   +29.994  
21:56:21  102.23.54  37.1       1620   41  1799.640   +26.995  
21:57:21  102.23.54  37.3       1655   41  1829.634   +29.994  
21:58:21  102.23.54  37.4       1652   42  1856.628   +26.994  
21:59:21  102.23.54  37.9       1632   42  1886.622   +29.994  
22:00:21  102.23.54  38.0       1668   43  1913.617   +26.995  
22:01:22  102.23.54  38.2       1627   44  1940.611   +26.994  
22:02:22  102.23.54  38.6       1614   44  1970.605   +29.994  +281.943
22:03:22  102.23.54  38.7       1617   45  1997.600   +26.995  
22:04:22  102.23.54  38.6       1659   46  2027.594   +29.994  
22:05:23  102.23.54  39.0       1640   46  2054.589   +26.995  
22:06:23  102.23.54  39.0       1652   47  2084.583   +29.994  
22:07:23  102.23.54  39.4       1623   48  2111.577   +26.994  
22:08:23  102.23.54  39.6       1658   48  2138.572   +26.995  
22:09:23  102.23.54  39.6       1617   49  2168.566   +29.994  
22:10:24  102.23.54  39.9       1670   50  2195.560   +26.994  
22:11:24  102.23.54  40.0       1638   50  2225.554   +29.994  
22:12:24  102.23.54  40.2       1627   51  2252.549   +26.995  +281.944
22:13:24  102.23.54  40.3       1630   52  2279.544   +26.995  
22:14:24  102.23.54  43.1       1601   52  2309.538   +29.994  
22:15:24  102.23.54  45.5       1666   53  2339.532   +29.994  
22:16:24  102.23.54  46.5       1812   53  2366.526   +26.994  
22:17:24  102.23.54  47.8       1640   54  2393.521   +26.995  
22:18:24  102.23.54  48.8       1599   55  2423.515   +29.994  
22:19:25  102.23.54  49.5       1689   55  2453.509   +29.994  
22:20:25  102.23.54  50.4       1627   56  2480.503   +26.994  
22:21:25  102.23.54  51.2       1569   57  2507.498   +26.995  
22:22:25  102.23.54  51.9       1664   57  2537.492   +29.994  +284.943
22:23:25  102.23.54  52.5       1726   58  2564.487   +26.995  
22:24:25  102.23.54  53.0       1554   59  2594.481   +29.994  
22:25:25  102.23.54  53.6       1622   59  2621.475   +26.994  
22:26:25  102.23.54  54.0       1701   60  2651.469   +29.994  
22:27:25  102.23.54  54.4       1637   61  2678.464   +26.995  
22:28:25  102.23.54  54.8       1652   61  2708.458   +29.994  
22:29:25  102.23.54  55.1       1664   62  2735.452   +26.994  
22:30:25  102.23.54  54.8       1579   63  2765.446   +29.994  
22:31:25  102.23.54  54.8       1650   63  2792.441   +26.995  
22:32:25  102.23.54  55.1       1583   64  2819.436   +26.995  +281.944
22:33:25  102.23.54  55.1       1573   64  2849.430   +29.994  
22:34:25  102.23.54  50.4         17   64  2849.430     0.000  
22:35:25    2.41.54  48.0      -1038   64  2834.433   -14.997  
22:36:25   14.11.20  47.8         23   64  2822.435   -11.998  
22:37:25  102.23.54  47.3         26   64  2822.435     0.000  
22:38:25  102.23.54  46.8         22   64  2825.434    +2.999  
22:39:25  102.23.54  46.1         15   64  2825.434     0.000  
22:40:26  102.23.54  49.7       1525   64  2846.430   +20.996  
22:41:26  102.23.54  50.5       1490   65  2873.425   +26.995  
22:42:26  102.23.54  50.4       1570   66  2903.419   +29.994  +83.983
22:43:26  102.23.54  50.3       1642   66  2930.413   +26.994  
22:44:26  102.23.54  50.6       1625   67  2957.408   +26.995  
22:45:26  102.23.54  50.2       1569   68  2984.403   +26.995  
22:46:26  102.23.54  50.1       1487   68  3011.397   +26.994  
22:47:26  102.23.54  50.0       1456   69  3035.392   +23.995  
22:48:26  102.23.54  49.8       1502   69  3062.387   +26.995  
22:49:26  102.23.54  49.7       1421   70  3086.382   +23.995  
22:50:26  102.23.54  49.5       1523   70  3110.377   +23.995  
22:51:26  102.23.54  49.4       1429   71  3137.372   +26.995  
22:52:26  102.23.54  49.5       1331   72  3161.367   +23.995  +257.948
22:53:26  102.23.54  49.3       1389   72  3182.363   +20.996  
22:54:26  102.23.54  49.3       1337   73  3206.358   +23.995  
22:55:26  102.23.54  49.2       1296   73  3230.353   +23.995  
22:56:26  102.23.54  49.2       1327   74  3254.349   +23.996  
22:57:26  102.23.54  49.0       1279   74  3275.344   +20.995  
22:58:26  102.23.54  49.3       1226   75  3296.340   +20.996  
22:59:26  102.23.54  49.1       1244   75  3320.335   +23.995  
23:00:27  102.23.54  48.7       1210   76  3341.331   +20.996  
23:01:27  102.23.54  48.6       1241   76  3362.327   +20.996  
23:02:27  102.23.54  48.3       1202   77  3383.323   +20.996  +221.956
23:03:27  102.23.54  48.2       1153   77  3404.319   +20.996  
23:04:27  102.23.54  48.2       1143   78  3422.315   +17.996  
23:05:27  102.23.54  47.9       1126   78  3443.311   +20.996  
23:06:27  102.23.54  47.6       1121   78  3461.307   +17.996  
23:07:27  102.23.54  47.7       1094   79  3482.303   +20.996  
23:08:27  102.23.54  47.4       1030   79  3500.299   +17.996  
23:09:27  102.23.54  47.3       1074   80  3518.296   +17.997  
23:10:27  102.23.54  47.1       1048   80  3536.292   +17.996  
23:11:27  102.23.54  47.1        994   81  3554.289   +17.997  
23:12:27  102.23.54  46.9        989   81  3572.285   +17.996  +188.962
23:13:27  102.23.54  47.0       1013   81  3590.281   +17.996  
23:14:27  102.23.54  47.0       1014   82  3608.278   +17.997  
23:15:27  102.23.54  46.9        991   82  3623.275   +14.997  
23:16:27  102.23.54  46.8        967   83  3641.271   +17.996  
23:17:27  102.23.54  46.4        919   83  3656.268   +14.997  
23:18:27  102.23.54  46.2        943   83  3674.265   +17.997  
23:19:27  102.23.54  46.2        881   84  3689.262   +14.997  
23:20:27  102.23.54  46.5        912   84  3704.259   +14.997  
23:21:28  102.23.54  46.5        905   84  3722.255   +17.996  
23:22:28  102.23.54  46.4        852   85  3737.252   +14.997  +164.967
23:23:28  102.23.54  46.5        870   85  3752.249   +14.997  
23:24:28  102.23.54  46.4        849   85  3767.246   +14.997  
23:25:28  102.23.54  46.4        824   86  3782.243   +14.997  
23:26:28  102.23.54  46.2        818   86  3794.241   +11.998  
23:27:28  102.23.54  46.4        813   86  3809.238   +14.997  
23:28:28  102.23.54  46.4        752   87  3824.235   +14.997  
23:29:28  102.23.54  46.3        782   87  3836.232   +11.997  
23:30:28  102.23.54  46.4        767   87  3851.229   +14.997  
23:31:28  102.23.54  46.3        742   88  3863.227   +11.998  
23:32:28  102.23.54  46.3        708   88  3878.224   +14.997  +140.972
23:33:28  102.23.54  46.2        726   88  3890.221   +11.997  
23:34:28  102.23.54  46.2        702   88  3902.219   +11.998  
23:35:28  102.23.54  46.2        673   89  3917.216   +14.997  
23:36:28  102.23.54  46.2        660   89  3929.214   +11.998  
23:37:28  102.23.54  46.1        665   89  3941.211   +11.997  
23:38:28  102.23.54  46.1        702   90  3953.209   +11.998  
23:39:28  102.23.54  45.9        672   90  3965.206   +11.997  
23:40:28  102.23.54  45.9        628   90  3974.205    +8.999  
23:41:29  102.23.54  46.0        611   90  3986.202   +11.997  
23:42:29  102.23.54  45.3        609   91  3998.200   +11.998  +119.976
23:43:29  102.23.54  45.1        628   91  4007.198    +8.998  
23:44:29  102.23.54  45.3        582   91  4019.196   +11.998  
23:45:29  102.23.54  45.5        649   91  4031.193   +11.997  
23:46:29  102.23.54  45.5        552   92  4040.191    +8.998  
23:47:29  102.23.54  45.3        582   92  4052.189   +11.998  
23:48:29  102.23.54  45.6        568   92  4061.187    +8.998  
23:49:29  102.23.54  45.4        604   92  4070.185    +8.998  
23:50:29  102.23.54  45.3        528   93  4082.183   +11.998  
23:51:29  102.23.54  44.3        556   93  4091.181    +8.998  
23:52:29  102.23.54  43.0        584   93  4100.179    +8.998  +101.979
23:53:29  102.23.54  42.3        542   93  4109.178    +8.999  
23:54:29  102.23.54  42.1        504   93  4118.176    +8.998  
23:55:29  102.23.54  41.8        538   94  4127.174    +8.998  
23:56:29  102.23.54  41.5        513   94  4136.172    +8.998  
23:57:29  102.23.54  41.5        500   94  4145.170    +8.998  
23:58:29  102.23.54  41.4        502   94  4154.169    +8.999  
23:59:29  102.23.54  41.2        523   94  4163.167    +8.998  
00:00:29  102.23.54  41.1        472   95  4172.165    +8.998  
00:01:29  102.23.54  41.4        448   95  4178.164    +5.999  
00:02:30  102.23.54  41.3        462   95  4187.162    +8.998  +86.983
00:03:30  102.23.54  41.1        467   95  4196.160    +8.998  
00:04:30  102.23.54  41.0        419   95  4202.159    +5.999  
00:05:30  102.23.54  40.8        415   95  4211.157    +8.998  
00:06:30  102.23.54  40.9        430   96  4217.156    +5.999  
00:07:30  102.23.54  40.6        454   96  4226.154    +8.998  
00:08:30  102.23.54  40.5        423   96  4232.153    +5.999  
00:09:30  102.23.54  40.3        421   96  4241.151    +8.998  
00:10:30  102.23.54  40.4        394   96  4247.150    +5.999  
00:11:30  102.23.54  40.6        379   96  4253.149    +5.999  
00:12:30  102.23.54  40.7        429   97  4262.147    +8.998  +74.985
00:13:30  102.23.54  40.5        405   97  4268.146    +5.999  
00:14:30  102.23.54  40.4        377   97  4274.145    +5.999  
00:15:30  102.23.54  40.1        379   97  4280.143    +5.998  
00:16:30  102.23.54  40.1        384   97  4286.142    +5.999  
00:17:30  102.23.54  40.0        380   97  4295.140    +8.998  
00:18:30  102.23.54  39.9        370   98  4301.139    +5.999  
00:19:30  102.23.54  39.9        344   98  4307.138    +5.999  
00:20:30  102.23.54  40.1        366   98  4313.137    +5.999  
00:21:30  102.23.54  41.5        386   98  4319.136    +5.999  
00:22:30  102.23.54  40.8        326   98  4325.134    +5.998  +62.987
00:23:30  102.23.54  41.6        322   98  4331.133    +5.999  
00:24:31  102.23.54  41.4        319   98  4337.132    +5.999  
00:25:31  102.23.54  42.8        324   98  4340.131    +2.999  
00:26:31  102.23.54  43.5        335   99  4346.130    +5.999  
00:27:31  102.23.54  43.6        356   99  4352.129    +5.999  
00:28:31  102.23.54  44.3        295   99  4358.128    +5.999  
00:29:31    6.14.20  43.1      -1081   99  4358.128     0.000  
00:30:31    4.35.48  42.5       -976   98  4343.131   -14.997  
00:31:31    4.31.13  42.0      -1064   98  4325.134   -17.997  
00:32:31    4.35.43  41.7       -814   98  4310.137   -14.997  -14.997

At the end I stopped charging and you can see how it then settles on a remaining runtime of ~4h 30m

4 Likes

Do you see that is slowdown after 72%? i guess it is because it getting hot mostly or PD Technologies. But why you never get 3000mA charge in? What charge do you use?

@dos why powesupply app does not work on Librem 5 it need a patch?

Last time I checked, powersupply was simply hardcoding PinePhone paths and drivers, so it couldn’t really work on any other device without modification.

4 Likes

Sure your electronics knowledge serves you well (we need you). Nice to have you here!

Going out on a limb here…

I am currently researching Lithium batteries for a stealth camping van I am building. These batteries have a very different charging profile requirement than other chemistries, makes sense, right?

In any case, what I’m reading, especially the 80% point, is exactly the requirement after <80 charge rate.

There are some voices saying it is not a good idea to charge to 100%.

A device called a Battery Management System (BMS) is critical to charge Lithium prudently. Another hurtle PURISM takes on, these folks have no fear, me thinks.

More at:

TL;DR: Neither the battery, the charge circuit or the phone behaves like a resistance.

Regardless if internal resistance changes during charging or not, let’s hope you’re seeing something different - because if the internal resistance was what determines the charge current at full charge, then this would also be the (maximum) current available to the phone when discharging. Additionally, that maximum current would be delivered at a voltage close to 0, which would not be enough for the phone to operate.

The big change is battery voltage going up, so if you charge from a fixed voltage through a fixed resistance that will cause charging current to go down linearly:
I = (Ucharge-Ubatt)/R (edit to add formula)
This fixed resistance would be the internal resistance (small) in series with a current-limiting resistance. (Think lead-acid batteries and older chargers.)

But this is not how charging the phone works. The current and the charging voltage applied to the battery terminals are determined by the (programmable) charge controller IC, using battery voltage and temperature as inputs. And then there’s USB-C Power Delivery, with different modes available to the phone.

PCB traces, the USB cable, and the internal resistance of the battery are resistive components, i.e. components that follow Ohm’s Law. The battery, the charge circuit, and the phone are not, and I think it’s more confusing than helpful to view them as resistors.

1 Like

If anyone wants to know more about how battery charging works on the Librem 5, you can find that information in the charging controller’s datasheets: https://www.ti.com/product/BQ25895

4 Likes

If anyone wants to see battery charging in operation, I got me a USB multimeter, and that shows the voltage and current and power … relating to the USB. However, for the current e.g., that is showing the entire current being drawn by the Librem 5 (battery charging + operation) and hence depends on the state of the Librem 5 (screen on/off, power saving, HKS, …) and the numbers will not equal what is being reported by the charging hardware.

2 Likes