# user138058

Member since Dec 2021 • Last active Jul 2022
• 1 conversations

• ### Bangle.js 2 - Battery always 100%

started
• 7,097 views
• in Bangle.js

@fanoush You're right, only hi should be needed. I'm now experimenting with trying to get getBattery to be more accurate since volts/% is not linear. My daughter noted that her watch was claiming 40% remaining battery shortly before it shut down. Based on a discharge graph shown here https://learn.adafruit.com/li-ion-and-li­poly-batteries/voltages, I've come up with the following:

``````E.getBattery = function () {
const hi = 0.48;
var v = analogRead(D3) / hi * 4.2;
if (v >= 4.2) {
return 100;
} else if (v >= 4.1) {
return Math.round(97 + 30 * (v - 4.1));
} else if (v >= 4.0) {
return Math.round(87 + 100 * (v - 4.0));
} else if (v >= 3.9) {
return Math.round(75 + 120 * (v - 3.9));
} else if (v >= 3.8) {
return Math.round(59 + 160 * (v - 3.8));
} else if (v >= 3.7) {
return Math.round(26 + 330 * (v - 3.7));
} else if (v >= 3.6) {
return Math.round(12 + 140 * (v - 3.6));
} else if (v >= 3.5) {
return Math.round(6 + 60 * (v - 3.5));
} else if (v >= 3.4) {
return Math.round(3 + 30 * (v - 3.4));
} else {
return 0;
}
};
``````
• in Bangle.js

@Gordon What kind of battery is in the Bangle.js 2? I read that that analog input is supposed to read 1/4 of the battery voltage, which means that a full battery is about 1.25V. That sounds about right for a NiMH battery. A lithium battery would be quite a bit higher (3.7V?)

• in Bangle.js

Thanks for the tip!

• in Bangle.js

I've worked around it for now by editing widbatpc.wid.js on the watch, replacing E.getBattery() with a call to a custom getBattery() function:

``````function getBattery() {
var battery = Math.round((analogRead(D3) - 0.375) / .00106);
return battery;
}
``````

That should tide me over until @Gordon returns.

• in Bangle.js

I've done some experimenting and it looks like my watch maxes out around 0.481 on the D3 when fully charged and shuts down around 0.375. These values are about 1.5x the values used to calculate battery percentage (0.246 and 0.3144). Not sure if my watch was built with the wrong value resistors for the voltage divider that feeds D3 or if the ADC is programmed incorrectly for that input.

Fully charged:

=0.48046875
=0.48120117187
=0.48022460937
=0.48095703125

Just prior to shutdown:

0.37524414062
100
0.37451171875
100
0.37377929687
100
0.37548828125

• in Bangle.js

I've already updated the watch firmware to 2v11 last week and unfortunately it didn't help.

• in Bangle.js

Here's what I get for a sequence of E.getBattery() and analogRead(D3) calls:

E.getBattery()
=100

=0.45239257812
=0.451171875
=0.45263671875
=0.45239257812
=0.45190429687
=0.4521484375
=0.4521484375
E.getBattery()
=100
E.getBattery()
=100
=0.45263671875