More precise battery percentage
Closed this issue · 7 comments
I definitely saw it go down at some point in other charging cycles, but as of now it's been stuck at 100% since yesterday night... So about 8 hours of always showing 100%.
Need to debug the battery values being read and what we're doing to produce the battery percentage
Only around now it reached about 95% and now it's hovering there...
So about more than 24 hours of being at 100% 😝
I said "hovering" because sometimes it shows 95% sometimes 96%. It's pretty odd.
@qewer33 do you mind explaining this logic?
Line 10 in a8e3456
I was debugging the values being read but it get about 2.3 volts max when charging, 2 at around max charge... I wonder if it's my battery though, maybe it's quite discharged. I'll leave it plugged in just in case.
Regardless there's something wrong, I'm not sure if this is the correct way to go about it. Does it work well with your battery? Mine stays at 100% for wayyyyyyyy too long.
It's not my battery but the fact that we're not accounting for these resistors
I'm fixing this in the PR, and checking if now the percentage makes more sense @qewer33
Ok so I get the problem, although I don't understand what's going on but after printing on the screen the voltages the max voltage (outside of charging) is about 3.8ish so it sticks at 100% for a while and then it starts dropping down.
The problem is that map(volt * 1000, 1630, 1850, 0, 100)
which is now changed to map(volt * 1000, 3000, 3700, 0, 100)
is assuming that the voltage will be around that but it really doesn't seem that way. I don't know how to solve it so for now I've set it like this map(volt * 1000, 0, 3700, 0, 100)
and we'll see where it stops working (and set the voltage at that value) and maybe I'll raise the max voltage value.
Hmm, I got the first part of the code from LILYGO's examples (it does take the resistors of the voltage divider into account) but found out that it didn't give the correct values so I just measured what I got with full battery and zero battery and constrained + mapped the value between the values I got.
I guess it can depend from battery to battery (no idea how that works, don't have enough electronics knowledge for it lol) so that's probably why you're getting different values. The best "solution" might be just to have them as config variables in os_config.h
.
I think the config might be a good solution but something better would be to dinamically find the maximum value and save it somewhere, the minimum should be pretty constant but I'll definitely let it run until it dies for the minimum, it should be 3000
Added battery charging icon and charging logic