MagTag Battery Monitor

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
DastFrucht
 
Posts: 7
Joined: Sun Mar 06, 2022 11:39 am

MagTag Battery Monitor

Post by DastFrucht »

I have several MagTag devices, They show me the data from my ecowitt sensors. Everything is working nicely. But I like to know in advance, when the time has come to load again the 3.7V 2000mAH LiPo (LP803860). I am using the often proposed function from the magtag library “magtag.peripherals.battery” it always shows something above 5 Volt on all MagTag devices. The value does not change over the time, after weeks of running the display remains blank, as the power needed for the next refresh of the display is no more available. Then I am going to use the USB-C connector to charge the LiPo and as soon a the yellow charging LED switches off, I distribute the device again in the house. I am pretty sure there is some bug within the library, as also the documentation explains how the value will change and how to recognize a soon power outage. Could someone explain what is going wrong?

User avatar
dastels
 
Posts: 15653
Joined: Tue Oct 20, 2015 3:22 pm

Re: MagTag Battery Monitor

Post by dastels »

The first thing is to ensure that CircuitPython and all libraries are up to date.

Dave

DastFrucht
 
Posts: 7
Joined: Sun Mar 06, 2022 11:39 am

Re: MagTag Battery Monitor

Post by DastFrucht »

Thanks Dave

It was and it is adafruit-circuitpython-adafruit_magtag_2.9_grayscale-en_US-7.2.5

Any other ideas?

User avatar
dastels
 
Posts: 15653
Joined: Tue Oct 20, 2015 3:22 pm

Re: MagTag Battery Monitor

Post by dastels »

What do you see in terms of data if you read AnalogIn(board.BATTERY) over time?

Dave

DastFrucht
 
Posts: 7
Joined: Sun Mar 06, 2022 11:39 am

Re: MagTag Battery Monitor

Post by DastFrucht »

This is the code I am executing

Code: Select all

from adafruit_magtag.magtag import MagTag
.. .. ..
magtag = MagTag(
    url=...,
    json_path=...,
)
.. .. ..
voltage = magtag.peripherals.battery
print(f'battery: {voltage:.2f} V')
I do have 5 magtag devices, so the result varies a little bit, I do see 5.11 or 5.35
The point is this value never changes over the time, where the real battery voltage gets lower and lower

Thanks for support

DastFrucht
 
Posts: 7
Joined: Sun Mar 06, 2022 11:39 am

Re: MagTag Battery Monitor

Post by DastFrucht »

I have added this part

Code: Select all

from analogio import AnalogIn
batt_Monitor = AnalogIn(board.BATTERY)
battV = (batt_Monitor.value / 65535.0) * 3.3 * 2
batt_Monitor.deinit()
print(f'battery: {battV:.2f} V')
The result over the serial line is

Code: Select all

code.py output:
battery: 5.11 V
battery: 5.11 V
magtag.peripherals.battery and AnalogIn(board.BATTERY)
return a similar value

DastFrucht
 
Posts: 7
Joined: Sun Mar 06, 2022 11:39 am

Re: MagTag Battery Monitor

Post by DastFrucht »

And if I do not do the "mathematics" it look like this

code.py output:
battery: 50739.00 V
battery: 5.11 V

so AnalogIn(board.BATTERY) returns 50739

User avatar
dastels
 
Posts: 15653
Joined: Tue Oct 20, 2015 3:22 pm

Re: MagTag Battery Monitor

Post by dastels »

I've asked internally to get some more eyes on it.

Dave

User avatar
adafruit_support_carter
 
Posts: 29150
Joined: Tue Nov 29, 2016 2:45 pm

Re: MagTag Battery Monitor

Post by adafruit_support_carter »

This may be related to this:
https://github.com/adafruit/circuitpython/pull/6246

Try updating to the 7.3.0 release which *should* fix that behavior:
https://circuitpython.org/board/adafrui ... grayscale/

Here's a simple battery voltage monitor program you can try testing with:

Code: Select all

import time
from adafruit_magtag.magtag import MagTag

magtag = MagTag()

magtag.add_text(
    text_position=(
        10,
        (magtag.graphics.display.height // 2) - 1,
    ),
    text_scale=3,
)

while True:
    magtag.set_text("Battery = {:4.2f}V".format(magtag.peripherals.battery))
    time.sleep(60)

DastFrucht
 
Posts: 7
Joined: Sun Mar 06, 2022 11:39 am

Re: MagTag Battery Monitor

Post by DastFrucht »

Yes, this is more or less what I doing, getting some Information from web services AND add the battery status and display everything
Update every 5 minutes
As far as I understood, I should do not grap the battery voltage at the beginning but after log into WIFI and web queries

DastFrucht
 
Posts: 7
Joined: Sun Mar 06, 2022 11:39 am

Re: MagTag Battery Monitor

Post by DastFrucht »

The approach to read out the battery voltage as late as possible, while still running on version 7.2.5 returns a reasonable result.
After updating to 7.3.0, both readings, the one at the beginning and the one after web access return the same good result
Thank you !

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”