Battery status in micropython

I finally chased down a code snippet for getting the battery status on my picocalc under micropython.

In my particular case, it has an rp2350w board.

code:


from machine import I2C, Pin

i2c = I2C(1, sda={Pin(6), scl=Pin(7), freq=100_000)

def battery_percent():
i2c.writeto(0x1f, b"\x0b")
response = i2c.readfrom(0x1f, 2)
return response[1]

print(“Battery: {}%”.format(battery_percent()))

I presume the { in i2c = I2C(1, sda={Pin(6), scl=Pin(7), freq=100_000) is a typo.

Yes, thank you for catching that. I need to learn how to use github. I assume it would help with that.