Once you've finished setting up your QT Py RP2040 with CircuitPython, you can access the code and necessary libraries by downloading the Project Bundle.
To do this, click on the Download Project Bundle button in the window below. It will download as a zipped folder.
# SPDX-FileCopyrightText: 2022 Liz Clark for Adafruit Industries
# SPDX-License-Identifier: MIT
import time
import board
import usb_midi
import adafruit_midi
import simpleio
from analogio import AnalogIn
from adafruit_midi.control_change import ControlChange
# midi setup
midi = adafruit_midi.MIDI(
midi_in=usb_midi.ports[0], in_channel=0, midi_out=usb_midi.ports[1], out_channel=0
)
# potentiometer setup
mod_pot = AnalogIn(board.A0)
# function to read analog input
def val(pin):
return pin.value
# variables for last read value
# defaults to 0
mod_val2 = 0
while True:
# Print out the min/max values from potentiometer to the serial monitor and plotter
print((mod_pot.value,))
time.sleep(0.05)
# map range of potentiometer input to midi values - update the min/max values below
mod_val1 = round(simpleio.map_range(val(mod_pot), 0, 65535, 0, 127))
# if modulation value is updated...
if abs(mod_val1 - mod_val2) > 2:
# update mod_val2
mod_val2 = mod_val1
# create integer
modulation = int(mod_val2)
# create CC message
modWheel = ControlChange(1, modulation)
# send CC message
midi.send(modWheel)
After downloading the Project Bundle, plug your QT Py RP2040 into the computer's USB port. You should see a new flash drive appear in the computer's File Explorer or Finder (depending on your operating system) called CIRCUITPY. Unzip the folder and copy the following items to the QT Py RP2040's CIRCUITPY drive.
- lib folder
- code.py
Your QT Py RP2040 CIRCUITPY drive should look like this after copying the lib folder and the code.py file.
Adjust Min/Max Values
In the code, values from the potentiometer are mapped to a range of MIDI CC values.
Use the serial monitor and plotter in Mu Editor to see the values from the potentiometer and set the minimum and maximum values.
Change the first and second number values in the map_range function to map the potentiometer to the range of control change (values 0-127).
Page last edited January 22, 2025
Text editor powered by tinymce.