Magtag Simple Project Selector

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
User avatar
egomez4
 
Posts: 2
Joined: Mon Sep 28, 2020 5:02 pm

Magtag Simple Project Selector

Post by egomez4 »

Hello,

I'm a bit stuck with my Magtag project. I wanted to make a simple project selector based on the Adafruit selector (https://learn.adafruit.com/adafruit-mag ... t-selector).

I just want a home screen to come up (cody.py) and then if I hit the first button it goes to the Weather.py project and if I hit the second button it goes to my Display.py project.

I am getting an error that says:
Traceback (most recent call last):
File "code.py", line 40, in <module>
File "weather.py", line 50, in <module>
File "adafruit_magtag/magtag.py", line 86, in __init__
File "adafruit_magtag/peripherals.py", line 53, in __init__
File "neopixel.py", line 141, in __init__
ValueError: NEOPIXEL in use
I did try to use magtag.deinit() but of course that's not working.

Here's the code.py. The two other codes (weather, display) are working:

Code: Select all

import time
import alarm
import displayio
import board
from adafruit_magtag.magtag import MagTag
from digitalio import DigitalInOut, Direction, Pull 

BACKGROUND_BMP = "/bmps/Select.bmp"

magtag = MagTag() 

magtag.graphics.set_background(BACKGROUND_BMP)
magtag.set_text('')

projects = [
    "weather",
    "display",
]

while True:
    for i, b in enumerate(magtag.peripherals.buttons):
        if not b.value:
            if(i==0):                           ##If First button D15 is pressed
                selector = projects[0]
                print("Starting project ", selector)
                __import__(selector)
            if(i==1):                           ##If First button D15 is pressed
                selector = projects[1]
                print("Starting project ", selector)
                __import__(selector)
                
            
        else:
            None
        time.sleep(0.01)
I really appreciate the help!

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

Re: Magtag Simple Project Selector

Post by adafruit_support_carter »

There's no line 40 in the attached code.py.

But in general, it seems like what's happening is that Weather.py and Display.py are trying to also create a MagTag instance. Since there's already one created in code.py, this is a second instance and it runs into a conflict when it tries to initialize resources already in use - like the NEOPIXEL pin.

User avatar
egomez4
 
Posts: 2
Joined: Mon Sep 28, 2020 5:02 pm

Re: Magtag Simple Project Selector

Post by egomez4 »

Line 40 would have been __import__(selector).

That's what I'm trying to do, I'm trying to call another instance e.g. __import__(weather.py). This is how I thought the Magtag project selector calls other programs. Is there a way then to call weather.py and close code.py?

I want code.py to effectively be a start menu where I can open up other programs when I press the different buttons. I would then get back to the code.py program by hitting restart, and then I could select another program.

How would this be done? I tried to mimic the Magtag Project Selector Tutorial to no avail.

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

Re: Magtag Simple Project Selector

Post by adafruit_support_carter »

Note how the selector code in the guide does not create an instance of the magtag helper, i.e. this line in your code.py:

Code: Select all

magtag = MagTag() 
Instead, it's reading the buttons by manually creating digital in pins, like this:

Code: Select all

btnA = DigitalInOut(board.D15)
btnA.direction = Direction.INPUT
btnA.pull = Pull.UP
You would need to do something similar in your code.

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

Return to “Adafruit CircuitPython”