-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Welcome to the k3MIDIController wiki!
- Adafruit MacroPad RP2040
- CircuitPython Libraries
- Mu Editor
- Adafruit Libraries
- MIDI-OX
- VirtualMIDISynth
To get started, you need to install the latest version of CircuitPython for the MacroPad RP2040. Follow the steps below:
- Download the appropriate version of CircuitPython from this link.
- Connect the MacroPad to your computer via USB-C.
- Put the MacroPad into BOOT mode by pressing the top-right cursor button while holding the button on the left side of the board.
- Drag and drop the downloaded CircuitPython file into the
RPI-RP2device that appears in your files. - Once the installation is complete, the device should change from
RPI-RP2toCIRCUITPY.
![]()
To write and transfer CircuitPython code to the MacroPad, we use Mu Editor. Here’s how to install it:
- Go to the official Mu Editor website.
- Download and install the IDE.
- On the first launch, select the CircuitPython mode.
- If you haven’t connected your MacroPad yet, an error message may appear. Simply connect your MacroPad, and Mu Editor will detect it automatically.
This initial version of the code allows the MacroPad to emit a sound frequency based on the key pressed.
import time
import displayio
import terminalio
from adafruit_display_text import label
from adafruit_macropad import MacroPad
# Initialize the MacroPad
macropad = MacroPad()
# Frequencies of the notes (C, D, E, F, G, A, B, C)
NOTES = [
262, 294, 330, 349,
392, 440, 494, 523,
587, 659, 698, 784
]
macropad.display.auto_refresh = False
group = displayio.Group()
# Text displayed on the screen at startup
text_area = label.Label(terminalio.FONT, text="Press a key!", color=0xFFFFFF)
text_area.anchor_point = (0.5, 0.5) # Center
text_area.anchored_position = (macropad.display.width // 2, macropad.display.height // 2)
group.append(text_area)
macropad.display.root_group = group
macropad.display.refresh()
while True:
key_event = macropad.keys.events.get()
if key_event and key_event.pressed:
key_index = key_event.key_number
if key_index < len(NOTES):
frequency = NOTES[key_index]
# Change the displayed text
text_area.text = f"Note: {frequency} Hz"
macropad.display.refresh()
# Play the note
macropad.start_tone(frequency)
time.sleep(0.2) # Sound duration
macropad.stop_tone() # Stop the sound
time.sleep(0.01)Note: With this code, the sound will come directly from the Arduino board.
To output sound directly from your computer, two solutions are possible:
-
Use MIDI software on your PC:
- The MacroPad will send MIDI notes to the computer.
- Software like GarageBand, Ableton Live, FL Studio, Virtual MIDI Piano Keyboard (VMPK), or MIDI-OX can interpret these notes and play the sound.
-
Use a Python script on your PC:
- The MacroPad will send keyboard inputs.
- A Python program on your PC will listen for these inputs and play the sound using pydub or pygame.mixer.
In this project, we chose the first option: using software to receive MIDI inputs sent by the MacroPad.
For the MacroPad to send MIDI messages via USB, you need to install the adafruit_midi and usb_midi libraries on the CircuitPython board. If they are not present in your /lib folder, you can download them from the Adafruit CircuitPython Bundle.
On Windows, we use VirtualMIDISynth and MIDI-OX to interpret MIDI signals.
- Download VirtualMIDISynth from this link.
- Install the software.
- Download an
.sf2file (MIDI soundbank) from Musical Artifacts. - Open VirtualMIDISynth and add your
.sf2file by clicking the green plus icon on the right.
![]()
- Download MIDI-OX from this site.
- Install the software.
- Go to the Options tab and then MIDI Devices to configure MIDI devices.
![]()
This code allows you to play piano notes (or other instruments depending on the .sf2 file used) based on the key pressed.
import time
import usb_midi
import adafruit_midi
from adafruit_midi.note_on import NoteOn
from adafruit_midi.note_off import NoteOff
from adafruit_macropad import MacroPad
# Ajout des bibliothèques nécessaires pour l'affichage à l'écran du MacroPad
import displayio
import terminalio
from adafruit_display_text import label
# Initialisation du MacroPad et du module MIDI USB
macropad = MacroPad()
midi = adafruit_midi.MIDI(midi_out=usb_midi.ports[1], out_channel=0)
# Liste des notes MIDI associées aux touches du MacroPad.
# Chaque touche correspond à une note de l’échelle musicale.
MIDI_NOTES = [36, 43, 48, 52, 55, 60, 64, 67, 72, 76, 79, 84]
# Configuration de l'affichage sur l’écran du MacroPad
macropad.display.auto_refresh = False # Désactivation du rafraîchissement automatique
group = displayio.Group() # Création d'un groupe d'affichage
# Création d'une zone de texte pour afficher la note jouée
text_area = label.Label(terminalio.FONT, text="Appuie sur une touche !", color=0xFFFFFF)
text_area.anchor_point = (0.5, 0.5) # Positionnement au centre de l'écran
text_area.anchored_position = (macropad.display.width // 2, macropad.display.height // 2)
# Ajout du texte au groupe d'affichage et mise à jour de l'écran
group.append(text_area)
macropad.display.root_group = group
macropad.display.refresh()
while True:
# Vérifie si une touche a été pressée ou relâchée
key_event = macropad.keys.events.get()
if key_event:
key_index = key_event.key_number # Récupère l'index de la touche
if key_event.pressed and key_index < len(MIDI_NOTES):
note = MIDI_NOTES[key_index] # Récupère la note MIDI associée
midi.send(NoteOn(note, 127)) # Envoie un signal MIDI "Note On" avec vélocité max
text_area.text = f"Note: {note}" # Met à jour l'affichage avec la note jouée
macropad.display.refresh() # Rafraîchit l'affichage
elif key_event.released and key_index < len(MIDI_NOTES):
note = MIDI_NOTES[key_index] # Récupère la note MIDI associée
midi.send(NoteOff(note, 0)) # Envoie un signal MIDI "Note Off" pour arrêter la note
text_area.text = "Appuie sur une touche !" # Réinitialise l'affichage
macropad.display.refresh() # Rafraîchit l'affichage
time.sleep(0.01) # Légère pause pour éviter une boucle trop rapideThis project transforms the MacroPad RP2040 into a custom MIDI controller. By using .sf2 files, you can play a variety of virtual instruments directly from your computer. Feel free to explore other libraries and software to expand the functionality of your KeyCube!