0

MagTag Battery Monitor
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

MagTag Battery Monitor

by DastFrucht on Sun May 08, 2022 11:33 am

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?

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

Re: MagTag Battery Monitor

by dastels on Sun May 08, 2022 1:49 pm

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

Dave

dastels
 
Posts: 10131
Joined: Tue Oct 20, 2015 3:22 pm

Re: MagTag Battery Monitor

by DastFrucht on Sun May 22, 2022 8:38 am

Thanks Dave

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

Any other ideas?

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

Re: MagTag Battery Monitor

by dastels on Sun May 22, 2022 1:21 pm

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

Dave

dastels
 
Posts: 10131
Joined: Tue Oct 20, 2015 3:22 pm

Re: MagTag Battery Monitor

by DastFrucht on Thu Jun 16, 2022 9:38 am

This is the code I am executing

Code: Select all | TOGGLE FULL SIZE
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

by DastFrucht on Thu Jun 16, 2022 9:53 am

I have added this part

Code: Select all | TOGGLE FULL SIZE
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 | TOGGLE FULL SIZE
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

by DastFrucht on Thu Jun 16, 2022 9:56 am

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

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

Re: MagTag Battery Monitor

by dastels on Thu Jun 16, 2022 11:32 am

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

Dave

dastels
 
Posts: 10131
Joined: Tue Oct 20, 2015 3:22 pm

Re: MagTag Battery Monitor

by adafruit_support_carter on Thu Jun 16, 2022 7:06 pm

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 | TOGGLE FULL SIZE
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)

adafruit_support_carter
 
Posts: 23686
Joined: Tue Nov 29, 2016 2:45 pm

Re: MagTag Battery Monitor

by DastFrucht on Sat Jun 18, 2022 6:44 am

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

by DastFrucht on Sat Jun 18, 2022 6:57 am

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 !

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

Please be positive and constructive with your questions and comments.