Tufty 2350 Battery Status

tufty-v2.0.1-micropython-with-filesystem.uf2
It’s connected via a Data only USB Cable.
Running the following from Thonny.

badge.battery_level()
#Returns an int representing the battery level as a percentage from 0 to 100.
print (badge.battery_level())

badge.battery_voltage()
#Returns a float representing the current battery voltage.
print (badge.battery_voltage())

badge.usb_connected()
#Returns a boolean reflecting whether the USB cable is currently connected.
print(badge.usb_connected())

badge.is_charging()
#Returns a boolean reflecting whether the battery is currently charging.
print(badge.is_charging())

Gets me this.

MPY: soft reboot
100
3.750865
False
False

The 100% doesn’t seem right to me?

Booting the Tufty to the OS Menu, the battery icon is full, is it supposed to show the battery charge state? It does show charging when the battery is charging.

Also, in my app, pressing B gets me
Battery 3.7V 100%

    if badge.held(BUTTON_B):
        screen.pen = color.white
        screen.text ("Battery", 5,9)
        screen.text("{:0.1f}V".format(badge.battery_voltage()), 100, 9)
        screen.text("{:0.0f}%" .format(badge.battery_level()), 160, 9)

And the widget always shows full?

def draw_battery():
    if badge.is_charging():
        battery_level = (badge.ticks / 20) % 100
    else:
        battery_level = badge.battery_level()
    pos = (275, 16)
    size = (32, 16)
    screen.pen = phosphor
    screen.shape(shape.rectangle(*pos, *size))
    screen.shape(shape.rectangle(pos[0] + size[0], pos[1] + 4, 2, 8))
    screen.pen = background
    screen.shape(shape.rectangle(pos[0] + 1, pos[1] + 1, size[0] - 2, size[1] - 2))
    width = ((size[0] - 4) / 100) * battery_level
    screen.pen = phosphor
    screen.shape(shape.rectangle(pos[0] + 2, pos[1] + 2, width, size[1] - 4))

MPY: soft reboot
99
3.6258208
False
False

Isn’t 3.6V your minimum usable LIPO Voltage?

    def test_vbat(self):
        voltage = vbat.read_u16() * (3.3 / 65536) * 2
        print(voltage)
        if voltage > 4.2 or voltage < 3.6:
            raise Exception("E7")

E7 - VBAT SENSE reading was out of range

tufty2350/modules/python/hardware_test.py at main · pimoroni/tufty2350

LiPos freshly charged have 4.2V. They stop working at about 3V. The curve is like this: very fast drop in the beginning, linear after about 4V down to 3.4V, very fast drop thereafter. The Pico buck-boost converter will work all the way down, but the switching regulator of the Tufty probably not. Which is not a problem if you use LiPos. But it should work down to 3.3V.

Pimoroni uses this formula:

level = min(100, max(0, round(123 - (123 / pow((1 + pow((voltage / 3.2), 80)), 0.165)))))

If you replace voltage with your 3.75, you end up at 100. This seems like a polynomial fit that is not perfect.

This post https://electronics.stackexchange.com/questions/435837/calculate-battery-percentage-on-lipo-battery gives a slightly different formula with 3.7 instead of 3.2 in the denominator. I guess this really depends on the use case, because with your measured value this would result in 25% which is a figure far too low.

As a side note: I am not even sure that battery voltage is measured correctly. With my Badger2350, battery unplugged and connected to USB-power, I get VSYS=4.6V, which is far too low. Maybe this is an artifact of my hacky setup. It is still on my todo-list to test VSYS with power fed into the battery connector.

What I’m going to do for now is replace the Battery Widget with Battery Voltage.

For anybody that’s wondering, when the Tufty boots up it shows the Battery state top right corner.

I copied that code so it also shows up when I launch my App. If you let the battery totally run down you lose the day date time stored in the RTC. That. and its not a good idea to run the battery down, is why I wanted a battery state indicator.

The devices have a battery protection chip and the regulator might bail out before anyhow. So I don’t expect any deep-discharge problems. Keeping RTC-state is a problem though so you better start charging again at about 3.4V.

The PCF8523 instead of the PCF85063A would have been an alternative with a coin-cell backup battery. But that would make the design more complicated and of course you also need the physical space for the coin-cell holder.

I have this PCB also on my Tufty2040 (it shares the pins with the Badger2040):

Not very compact, the Tufty2350 is certainly the better choice.