PinAlarm for MagTag returns button in use error

Play with it! Please tell us which board you're using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Catbar
 
Posts: 15
Joined: Fri Jul 13, 2018 6:14 pm

PinAlarm for MagTag returns button in use error

Post by Catbar »

I'm working on an event logger which cycles through a worker list, and which displays a time stamp with the worker's name when the worker pushes a specific button on the MagTag to show when the event was completed. Then, it should go into to deep sleep until the next button press, when it would log the next worker's event time and go back to sleep.

On program startup, I get the first worker name to come up with the current timestamp, but within a few seconds I get an error. No button press is involved.

I'm getting a "BUTTON_x in use" error trying to use the PinAlarm with the most recent CircuitPython and libs for MagTag. Pin D14 returns the error below. Pin D15 returns the error "BUTTON_A in use", etc. The error line, 64, is the first line in the code below that sets the PinAlarm.

I import alarm, alarm.pin, board, time and MagTag from adafruit_magtag.magtag.

The demo programs I found for PinAlarm work fine. I can't see any difference in my code other than my imports.

I'm just sharing just a fragment in case this is obvious, or a known issue. I can post all of my code if this isn't sufficient to diagnose.

Code: Select all

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

board.DISPLAY.refresh()

alarm.exit_and_deep_sleep_until_alarms(pin_alarm)

Code: Select all

code.py output:
Connecting to AP ______
Getting time for timezone America/New_York
Traceback (most recent call last):
  File "code.py", line 64, in <module>
ValueError: BUTTON_B in use
Thanks,
Brian

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

Re: PinAlarm for MagTag returns button in use error

Post by Catbar »

Stripping out all of the references to a MagTag object makes the program work. Just creating a MagTag object, without using it for anything, makes the error occur. So it would seem that the way that I'm creating the PinAlarm won't work if there is also a MagTag object in use. So, there's either a bug in implementation, or something I don't understand yet. I'll try to figure out if it is the latter.

Brian

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

Re: PinAlarm for MagTag returns button in use error

Post by Catbar »

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

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)
Thanks,
Brian

User avatar
colinj
 
Posts: 17
Joined: Mon Jun 22, 2015 9:43 pm

Re: PinAlarm for MagTag returns button in use error

Post by colinj »

I wanted to give this a BUMP as I'm just starting with the MagTags and I am seeing the same behavior.

So here's the question is it possible to set up a pin alarm while using the MagTag library? Or do I need to move to a lower layer to be able to setup a wake on button type alarm?

Please and thank you

User avatar
colinj
 
Posts: 17
Joined: Mon Jun 22, 2015 9:43 pm

Re: PinAlarm for MagTag returns button in use error

Post by colinj »

As is usually the case soon after I posted this question I discovered the answer—or at least an answer. So, here it is.

To enable an alarm on and of the magtag.peripherals objects you need to deinit() the object because the magtag instance that you created has already grabbed the peripheral and set it up for itself. Here's what my solution looks like:

Code: Select all

magtag = MagTag()
magtag.peripherals.buttons[0].deinit()
switch_pronoun_alarm = alarm.pin.PinAlarm(pin=board.BUTTON_A, value=False, pull=True)
.
.
.
alarm.exit_and_deep_sleep_until_alarms(switch_pronoun_alarm)
Immediately after creating the magtag instance use the deinit() function on the object that you want to use at a lower level. Here that is the magtag.peripherals.buttons[0] which corresponds to the board.BUTTON_A object. Once you have freed up the object for use you can then use the peripheral to create something at a lower level, like an alarm.

At least that's the easy way that I've figured out how to do this and still have the rest of the fun MagTag library to play with. Comments, corrections, and criticisms are welcome and appreciated.

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

Re: PinAlarm for MagTag returns button in use error

Post by adafruit_support_carter »

Looks like there is an open issue for this here:
https://github.com/adafruit/Adafruit_Ci ... /issues/64

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

Return to “Circuit Playground Classic, Circuit Playground Express, Circuit Playground Bluefruit”