Skip to content

battery bar + battery profiles + battery calibration#60

Merged
defidude merged 15 commits into
ratspeak:mainfrom
DJ2LS:ls-add-battery-bar
Jul 1, 2026
Merged

battery bar + battery profiles + battery calibration#60
defidude merged 15 commits into
ratspeak:mainfrom
DJ2LS:ls-add-battery-bar

Conversation

@DJ2LS

@DJ2LS DJ2LS commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

This work in progress (WIP) PR adds some more battery monitoring, a battery bar, a small ability of calibrate battery discharge voltage and hopefully a more accurate battery discharge profile .

I opened this PR already, as it needs some more time of testing and I want to avoid things getting broken. Also git commits are not 100% clear, @defidude , as explained on Discord. Contribution and feedback are very welcome, as I'm not an electronical engineer, for sure there are some battery gurus and calibration wizards out there :-)

new battery settings:

  • Battery Display: Switch between Percent and Bar
  • Discharge Curve: Switch between LiPo and Linear
  • Charge Above: Voltage threshold, when indicating we are charging the device
  • Full Battery: Voltage threshold, when we start draining the battery after charging
  • Voltage: Tap to get current battery voltage for calibrating "Full Battery"
  • Charge: Actual charge level.
5BC2854C-658F-4778-922F-396DDE4060B5

Lipo discharge curve:

I tried to simulate discharging better, used this one as reference:
https://www.researchgate.net/figure/Li-ion-battery-discharge-voltage-curve_fig5_363575973
Li-ion-battery-discharge-voltage-curve jpg

At least I tried to manually interpret it, interpolated values between:

static const VoltPct LIPO_CURVE[] = {
    {4.20f, 100}, // manual chart reading
    {4.00f,  95},
    {3.80f,  90}, // manual chart reading
    {3.78f,  85},
    {3.75f,  80}, // manual chart reading
    {3.74f,  75},
    {3.73f,  70},
    {3.71f,  65},
    {3.70f,  60}, // manual chart reading
    {3.69f,  55},
    {3.68f,  50},
    {3.66f,  45},
    {3.65f,  40}, // manual chart reading
    {3.64f,  35},
    {3.63f,  30},
    {3.61f,  25},
    {3.60f,  20}, // manual chart reading
    {3.55f,  15},
    {3.50f,  10}, // manual chart reading
    {3.25f,   5}, // manual chart reading
    {3.00f,   0}, // manual chart reading
};

Those values need to be tested in real world. That's the real "work in progress" part. Challenge is to find the best tradeoff regarding the voltage plateau.

battery calibration instructions:

  • plug in charging cable
  • charge until you think its full, at least several hours
  • keep charging cable plugged in
  • go to battery settings, tap on Voltage for getting current charging voltage
  • set "Charge Above" to a save value, e.g. 4.1V if we have a Voltage of e.g. 4.2V
  • unplug charge cable
  • tap on Voltage again, value should be now at 3.8V or so
  • set Full Battery to the Voltage level

how to help:

Calibrate battery, discharge until device dies and inspect battery levels so we can see if we found a good interpretation of discharge curve.

Comment thread src/main.cpp
@DJ2LS

DJ2LS commented Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

okay, the actual discharge table isn't working reliable. Time for using a battery logger and see how power levels really drop.

@DJ2LS

DJ2LS commented Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

While charging, battery level drops down to 4.05V, so "Charge Above = 4.00" might make sense

@DJ2LS

DJ2LS commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author
battery_discharge

So, this is a plot of a real discharge process. I will adjust the discharge table according to given data

@DJ2LS

DJ2LS commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

percentage suggestion:

{
    {3.90f, 100}, {3.80f, 90}, {3.72f, 80}, {3.65f, 70},
    {3.59f, 60},  {3.53f, 50}, {3.48f, 40}, {3.44f, 30},
    {3.40f, 20},  {3.36f, 15}, {3.30f, 10}, {3.15f, 5},
    {3.00f, 0},
};

Lets see if we can get this working

@DJ2LS

DJ2LS commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

Okay, it seems we're closer to our goal now. Battery bar becomes green when charging, yellow at 20% remaining, red at 10% ... only Charge level has a small offset related bug, lets fix it...

IMG_0108 IMG_0109

@DJ2LS

DJ2LS commented Jun 21, 2026

Copy link
Copy Markdown
Contributor Author

Latest tests looking good to me. Battery curve seems to be more realistic now. Looking forward to some testers results

@DJ2LS

DJ2LS commented Jun 27, 2026

Copy link
Copy Markdown
Contributor Author

@defidude , I merged latest changes into this PR, everything seems to be working so far. So from my side, you can review and merge it if you want.

@DJ2LS DJ2LS changed the title WIP: battery bar + battery profiles + battery calibration battery bar + battery profiles + battery calibration Jun 29, 2026
@defidude
defidude merged commit 752154c into ratspeak:main Jul 1, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants