Reading battery level from mmbasic

Has anyone managed to use the i2c commands in PicoMite to get that battery register value? Or is that really not possible in MMBasic? I’ve tried a few things, but I’m not sure I really understand how to use the i2c commands properly.

If it’s not possible with MMBasic itself, maybe I could look into adding a custom command to PicoMite (for PicoCalc only) to get the battery value and pass it through based on guu’s code here. I imagine the same could be done for setting the backlight as well. Actually, that’s something I’d personally use more, as I find it annoying to have to always turn the keyboard backlight on and it would be nice if it was saved (as an OPTION?) and always used the last saved value on startup. I’ll add it to my todo/wish list. :wink:

Just to follow up… Forgot about this thread, but saw it linked from discord today.

It’s possible to get battery info from MMBasic now, with the most recent releases. (It went in for RC21, but is still there for RC23 and whatever I end up releasing next.) :slight_smile: A number of other bugs have been fixed (like keyboard handling), and this contains the latest from the mainline MMBasic releases as well.

You’ll need to update your keyboard firmware though, but more information on that is provided in the release notes. Here’s a screenshot showing the new commands, for reference.

3 Likes

I defined F9 key to show the batt info, very practical !

1 Like

I put a battery bar/line on the right side. Extra practical :laughing:
Though it’s micropython…

4 Likes

how did you do this?

option f9 "? "+chr$(34)+"Battery level"+chr$(34)+"mm.info(battery)"+chr$(34)+"%"+chr$(10)+chr$(13)

as a MMBasic file, would this always work, or does it have to be flash saved?

Just have to type it once and it stays as long as you don’t modify the F9 key again. Try it.

Any idea why it spams that?

Which version of MMBasic are you running? Older versions had a bug with the I2C timing, but as far as I know this has been fixed in recent builds.

1 Like

when I try to run the code it comes up with an error

You need to update the keyboard firmware. I had the exact same issue before updating

2 Likes