0

Macropad source code for ADABOX019?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Macropad source code for ADABOX019?

by rgm on Thu Jul 22, 2021 9:46 pm

Hello! I think it'd be quite instructional to be able to see the source code for the firmware that shipped with the ADABOX019 macro-pad (which I love, BTW) since it demonstrates so many cool effects, hardware interactions, and event handling. Is this available anywhere?

Also, I believe "MACROPAD" could deserve its own top-level forum since I think it'll be very popular for a long time, but that could just be recency bias on my part.

rgm
 
Posts: 35
Joined: Thu Jan 22, 2009 12:31 pm
Location: Austin, TX

Re: Macropad source code for ADABOX019?

by collene on Fri Jul 23, 2021 11:56 pm

This isn't an answer to your question, but rather a +1 to the request...I came here to find the source code for adabox019 as well.

collene
 
Posts: 26
Joined: Thu Oct 05, 2017 8:38 pm

Re: Macropad source code for ADABOX019?

by CrashGoBoom on Sat Jul 24, 2021 1:46 am


CrashGoBoom
 
Posts: 1
Joined: Wed Sep 23, 2020 3:03 pm

Re: Macropad source code for ADABOX019?

by collene on Sat Jul 24, 2021 2:26 pm

Hmm..was hoping to see a circuitpython equivalent. One of the examples gives the button layout and I think I can figure out the rotary dial...but does anyone have the circuitpython code to make the keys go all rainbow glowy?

collene
 
Posts: 26
Joined: Thu Oct 05, 2017 8:38 pm

Re: Macropad source code for ADABOX019?

by franklin97355 on Sat Jul 24, 2021 3:17 pm


franklin97355
 
Posts: 22144
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: Macropad source code for ADABOX019?

by collene on Sat Jul 24, 2021 6:24 pm

So I'm almost there:

Code: Select all | TOGGLE FULL SIZE
import displayio
import terminalio
import board
import neopixel
from adafruit_display_text import bitmap_label as label
from adafruit_displayio_layout.layouts.grid_layout import GridLayout
from adafruit_macropad import MacroPad
from adafruit_led_animation.animation.rainbow import Rainbow
from adafruit_led_animation.animation.blink import Blink
from adafruit_led_animation.color import BLUE

macropad = MacroPad()

main_group = displayio.Group()
macropad.display.show(main_group)
layout = GridLayout(x=0, y=4, width=128, height=66, grid_size=(3, 5), cell_padding=0)
labels = []
for _ in range(12):
    labels.append(label.Label(terminalio.FONT, text="", max_glyphs=10))

for index in range(12):
    x = index % 3
    y = index // 3
    layout.add_content(labels[index], grid_position=(x, y), cell_size=(1, 1))

rotary_label = label.Label(
    terminalio.FONT,
    text="",
    max_glyphs=10
)
layout.add_content(rotary_label, grid_position=(0, 4), cell_size=(2, 1))

rotary_switch_label = label.Label(
    terminalio.FONT,
    text="",
    max_glyphs=10
)
layout.add_content(rotary_switch_label, grid_position=(2, 4), cell_size=(1, 1))

main_group.append(layout)

rainbow = Rainbow(macropad.pixels, speed=0.1, period=2)
blink = Blink(macropad.pixels, speed=0.5, color=BLUE)

while True:
    rainbow.animate()
    key_event = macropad.keys.events.get()
    if key_event:
        if key_event.pressed:
            labels[key_event.key_number].text = "KEY{}".format(key_event.key_number)
        else:
            labels[key_event.key_number].text = ""
    rotary_label.text = "Encoder: {}".format(macropad.encoder)
    if macropad.encoder_switch:
        rotary_switch_label.text = "ENCODER"
    else:
        rotary_switch_label.text = ""


But I'm getting the error:
TypeError object of type '_PixelMapLite' has no len()

If you change the line
rainbow.animate()

to
blink.animate()

It works fine, but it's kinda boring :) I'd like to get one of the rainbow animations to work. I'm using the circuitpython libraries from July 2nd (the newest version had an error with gridlayout). Any suggestions?

collene
 
Posts: 26
Joined: Thu Oct 05, 2017 8:38 pm

Re: Macropad source code for ADABOX019?

by wegunterjr on Sat Jul 24, 2021 8:13 pm

I am also trying to get this to work. Using cricuit python, I would love c++ or similar eventually, but for now it;ll be great.

I am having issues with GridLayout when I try to add content similar to the example:
Code: Select all | TOGGLE FULL SIZE
  layout.add_content(labels[index], grid_position=(x, y), cell_size=(1, 1))


With error:
Code: Select all | TOGGLE FULL SIZE
>>> for index in range(12):                                                                                                     
...     x = index % 3                                                                                                           
...     y = index // 3                                                                                                         
...     layout.add_content(labels[index], grid_position=(x,y), cell_size=(1,1))                                                 
...                                                                                                                             
...                                                                                                                             
...                                                                                                                             
Traceback (most recent call last):                                                                                             
  File "<stdin>", line 4, in <module>                                                                                           
  File "adafruit_displayio_layout/layouts/grid_layout.py", line 118, in add_content                                             
  File "adafruit_displayio_layout/layouts/grid_layout.py", line 85, in _layout_cells                                           
AttributeError: 'Label' object has no attribute 'width'


Seems like some of the libraries were updated, which is nice, but only one of them with an errors that indicated what to change. GridLayout doesn't say what to ignore or leave out.

wegunterjr
 
Posts: 3
Joined: Thu Dec 05, 2013 4:45 pm

Re: Macropad source code for ADABOX019?

by collene on Sat Jul 24, 2021 10:11 pm

That was the same error I got...if you switch to using the adafruit_display_text library from July 2nd, then the error goes away. Specifically, I used the version in this bundle: https://github.com/adafruit/Adafruit_Ci ... g/20210702

It was this commit that broke the gridlayout: https://github.com/adafruit/Adafruit_Ci ... c684527f44

I love circuitpython, but I have to say, every time I get an Adabox and try the examples, they almost never work right out of the box (haha, punny). There is almost always a library that you have to switch out to use an older version, and either you have to find on the forums someone else with the same error or dig through code until you find which library caused the break, both of which are time consuming. Dependency management is a nightmare, but I wish there was a better solution than "go and get an older version of the library that still works". There are dependency management techniques even for python. This is keeping me from adopting circuitpython over Arduino because it's frustrating to spend my time fixing libraries rather than working on my own code.

And, um, that being said, have I mentioned that the gridlayout library is *wonderful*? Thank you for making that available :)

collene
 
Posts: 26
Joined: Thu Oct 05, 2017 8:38 pm

Re: Macropad source code for ADABOX019?

by wegunterjr on Sun Jul 25, 2021 12:05 am

Ah..that's the one. I tried the alpha4 i think, but it still had similar issues. thanks for that!

Also, are you using REPL or doing the code.py in the folder (I am using VSCode as my editor - When I press save, it typically shows on the macropad, but not always. )
I am wondering if the examples work as is in REPL and also in code.py.

How do i force it to use these libraries, just manually place them in the lib folder? don't use circup right?

wegunterjr
 
Posts: 3
Joined: Thu Dec 05, 2013 4:45 pm

Re: Macropad source code for ADABOX019?

by collene on Sun Jul 25, 2021 12:27 am

I'm just editing code.py in VSCode and then copying the required libraries over into /lib...that's the only way I've seen on the tutorials how to edit circuitpython code. I haven't used circup, but from what I can tell it just updates to the most recent version of the library, not a specific version of the library, which is what's needed here.

collene
 
Posts: 26
Joined: Thu Oct 05, 2017 8:38 pm

Re: Macropad source code for ADABOX019?

by adafruit2 on Sun Jul 25, 2021 2:01 pm

how about this?

Code: Select all | TOGGLE FULL SIZE
# SPDX-FileCopyrightText: Copyright (c) 2021 Kattni Rembor for Adafruit Industries
#
# SPDX-License-Identifier: Unlicense
"""
Grid layout demo for MacroPad. Displays the key pressed in a grid matching the key layout on the
built-in display.
"""
import displayio
import terminalio
from adafruit_display_text import bitmap_label as label
from adafruit_displayio_layout.layouts.grid_layout import GridLayout
from adafruit_macropad import MacroPad
from rainbowio import colorwheel

macropad = MacroPad()

main_group = displayio.Group()
macropad.display.show(main_group)
title = label.Label(
    y=4,
    font=terminalio.FONT,
    color=0x0,
    text="      KEYPRESSES      ",
    background_color=0xFFFFFF,
)
layout = GridLayout(x=0, y=10, width=128, height=54, grid_size=(3, 4), cell_padding=5)
labels = []
for _ in range(12):
    labels.append(label.Label(terminalio.FONT, text=""))

for index in range(12):
    x = index % 3
    y = index // 3
    layout.add_content(labels[index], grid_position=(x, y), cell_size=(1, 1))

main_group.append(title)
main_group.append(layout)

lit_keys = [False] * 12
wheeloffset = 0
while True:
    key_event = macropad.keys.events.get()
    if key_event:
        if key_event.pressed:
            labels[key_event.key_number].text = "KEY{}".format(key_event.key_number)
            lit_keys[key_event.key_number] = not lit_keys[key_event.key_number] # flip it
        else:
            labels[key_event.key_number].text = ""

    # animate the pressed keys
    wheeloffset += 1 # glow thru the colorwheel
    for k in range(12):
        if lit_keys[k]:
            macropad.pixels[k] = colorwheel((k / 12 * 256) + wheeloffset)
        else:
            macropad.pixels[k] = 0 # turn it off

adafruit2
Site Admin
 
Posts: 20193
Joined: Fri Mar 11, 2005 7:36 pm

Re: Macropad source code for ADABOX019?

by collene on Sun Jul 25, 2021 6:46 pm

Great, thanks!

collene
 
Posts: 26
Joined: Thu Oct 05, 2017 8:38 pm

Re: Macropad source code for ADABOX019?

by rgm on Thu Jul 29, 2021 1:53 pm

Thanks, this is helpful, but I'm still looking for the actual firmware that's on the Macropad as it shipped, including the Adafruit and Digikey bitmaps that are shown on the OLED at startup. Is this in a git repo somewhere?

rgm
 
Posts: 35
Joined: Thu Jan 22, 2009 12:31 pm
Location: Austin, TX

Re: Macropad source code for ADABOX019?

by RufusVS2020 on Sun Aug 01, 2021 8:22 pm

If you had seen John Park's Unboxing, you'd have seen they posted a link to
the shipped firmware here: https://learn.adafruit.com/adabox019/original-firmware

RufusVS2020
 
Posts: 35
Joined: Thu Nov 19, 2020 6:31 pm

Please be positive and constructive with your questions and comments.