0

PinAlarm for MagTag returns "Button in use" error
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

PinAlarm for MagTag returns "Button in use" error

by Catbar on Thu Jan 07, 2021 7:02 pm

This is a repost from another forum. This is the more appropriate place to get a response, I think.

Here's a stripped down version of the program. If I comment out the "magtag = MagTag()" line, it doesn't fail. Leaving it active generates the "Value error: BUTTON_B in use".

I've not figured out if I'm doing something wrong as of yet, but at least I have a simple representation of the issue.

Code: Select all | TOGGLE FULL SIZE
import alarm
import alarm.pin
import board
from adafruit_magtag.magtag import MagTag

magtag = MagTag()

names_cycle = ("Catherine", "  Brian  ")

if not alarm.wake_alarm:
    alarm.sleep_memory[0] = 0
else:
    if alarm.sleep_memory[0] == 0:
        alarm.sleep_memory[0] = 1
    else:
        alarm.sleep_memory[0] = 0

out = names_cycle[alarm.sleep_memory[0]]

print(out)

pin_alarm = alarm.pin.PinAlarm(pin=board.D14, value=False, pull=True)

board.DISPLAY.refresh()

alarm.exit_and_deep_sleep_until_alarms(pin_alarm)

Catbar
 
Posts: 15
Joined: Fri Jul 13, 2018 6:14 pm

Re: PinAlarm for MagTag returns "Button in use" error

by tannewt on Fri Jan 08, 2021 2:19 pm

Hi Catbar, I suspect this is due to the MagTag class automatically initializing the button. That would "use" it and prevent it from being used with PinAlarm.

Can you achieve your goal without the MagTag class? I'm not sure how we expect folks to use it with pin wakeup. This code is very new.

tannewt
 
Posts: 2034
Joined: Thu Oct 06, 2016 8:48 pm

Re: PinAlarm for MagTag returns "Button in use" error

by Catbar on Fri Jan 08, 2021 6:20 pm

I'm using the MagTag class to access set_text and add_text - a variation of the cat feeder program, but this will log an event when the button is pressed (tagging when someone cleaned the cat litter box - another cat app). The need for deep sleep is the wrinkle, since the battery runs out too soon for this to be practical unless deep sleep is used.

My two options would then be to either get display capability akin to that provided to the MagTag class or to somehow "unhook" the button from the MagTag class to be able to use PinAlarm. I guess a third option would exist if there is some way to tell PinAlarm to use the MagTag button definition.

Just knowing what you've told me gives me some clues to other approaches, like other ways to get nice text formatting without the MagTag class, but if you can suggest something, it would save me trial and error that might not work out.

Then again, trial and error teaches us, too.

Thanks for your reply,
Brian

Catbar
 
Posts: 15
Joined: Fri Jul 13, 2018 6:14 pm

Re: PinAlarm for MagTag returns "Button in use" error

by tannewt on Mon Jan 11, 2021 6:41 pm

Catbar wrote:or to somehow "unhook" the button from the MagTag class to be able to use PinAlarm.


This might be pretty easy actually. All you need to do is call `deinit` on the DigitalInOut created by the library for the button. Just look at the library source to find the name of the variable internally.

tannewt
 
Posts: 2034
Joined: Thu Oct 06, 2016 8:48 pm

Re: PinAlarm for MagTag returns "Button in use" error

by Catbar on Mon Jan 11, 2021 8:57 pm

I'll give it a try when I can get back to it. Thanks!

Brian

Catbar
 
Posts: 15
Joined: Fri Jul 13, 2018 6:14 pm

Re: PinAlarm for MagTag returns "Button in use" error

by nealdt on Tue Jan 12, 2021 2:15 pm

I was able to get this working by calling
Code: Select all | TOGGLE FULL SIZE
magtag.peripherals.buttons[0].deinit()
and then using
Code: Select all | TOGGLE FULL SIZE
board.BUTTON_A
for a PinAlarm.

nealdt
 
Posts: 18
Joined: Mon Feb 10, 2020 5:31 pm

Re: PinAlarm for MagTag returns "Button in use" error

by Catbar on Tue Jan 12, 2021 8:51 pm

That works on the simple program. I'll have to fold it into the full version. Thanks!

Brian

Catbar
 
Posts: 15
Joined: Fri Jul 13, 2018 6:14 pm

Please be positive and constructive with your questions and comments.