The Adafruit MacroPad RP2040 packs 12 mechanical keys with RGB LEDs, a rotary encoder, and a tiny OLED into one board you program in CircuitPython. Before writing any code, it helps to plan what each key does. Here’s how I laid mine out.

The layout

InputActionHow
Encoder turnVolume up/downConsumer Control VOLUME_INCREMENT / DECREMENT
Encoder clickPlay/pauseConsumer Control PLAY_PAUSE
Key 1Open my homelab dashboardWin+R, type the URL, Enter
Key 2Quick searchAlt+Space (PowerToys Run / Command Palette)
Key 3File ExplorerWin+E
Key 4Desk LEDs on/offHome Assistant service call
Key 5Cycle desk LED effectHome Assistant script
Key 6ScreenshotWin+Shift+S
Keys 7-10SpareRoom to grow
Key 11System muteConsumer Control MUTE
Key 12Discord muteAlt+M (set as Discord’s mute keybind), LED red when muted, green when live

The OLED: bongo cat

The screen shows a bongo cat all the time:

  • No keys pressed: paws up.
  • Any key pressed: paws down on the table.

It’s just two bitmaps swapped based on whether any key is held, which is easy to do with displayio and a small sprite sheet.

Getting started in CircuitPython

  1. Install the latest CircuitPython for the MacroPad from circuitpython.org.
  2. Copy the adafruit_macropad library (and its dependencies) from the library bundle into CIRCUITPY/lib.
  3. Start from a simple code.py:
from adafruit_macropad import MacroPad

macropad = MacroPad()
last_position = macropad.encoder

while True:
    # encoder -> volume
    position = macropad.encoder
    if position > last_position:
        macropad.consumer_control.send(macropad.ConsumerControlCode.VOLUME_INCREMENT)
    elif position < last_position:
        macropad.consumer_control.send(macropad.ConsumerControlCode.VOLUME_DECREMENT)
    last_position = position

    # encoder click -> play/pause
    macropad.encoder_switch_debounced.update()
    if macropad.encoder_switch_debounced.pressed:
        macropad.consumer_control.send(macropad.ConsumerControlCode.PLAY_PAUSE)

    # keys
    event = macropad.keys.events.get()
    if event and event.pressed:
        if event.key_number == 2:  # Key 3: File Explorer
            macropad.keyboard.send(macropad.Keycode.WINDOWS, macropad.Keycode.E)

Keys are numbered 0-11 in code, so “Key 3” in the table is key_number == 2.

Home Assistant buttons

The MacroPad is just a USB keyboard, so it can’t call Home Assistant directly. Two easy options:

  • Keyboard shortcut + automation: send an unused combo like Ctrl+Alt+F13 and have a desktop tool (AutoHotkey, or the HASS.Agent app on Windows) call the Home Assistant service.
  • Open a URL: point a key at a Home Assistant webhook automation.

The Discord mute LED

The MacroPad can’t know Discord’s real mute state, so the LED just tracks presses of the key: toggle a variable each time it’s pressed and set macropad.pixels[11] to red or green. If you mute with the mouse, it’ll drift out of sync. Press the key twice to fix it.

Key icons

If you print key labels or show icons on the OLED, free icon sets like Icons8 have matching styles for home, search, folder, lamp and list icons.