Skip to content

Instantly share code, notes, and snippets.

@sandyjmacdonald
Last active July 31, 2023 07:22
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sandyjmacdonald/2db20b2fecccd44b39d737fdc4d14d11 to your computer and use it in GitHub Desktop.
Save sandyjmacdonald/2db20b2fecccd44b39d737fdc4d14d11 to your computer and use it in GitHub Desktop.
CircuitPython USB MIDI to serial MIDI converter for Raspberry Pi Pico (RP2040)
# CircuitPython USB MIDI to serial MIDI converter for Raspberry Pi Pico (RP2040).
# IMPORTANT! Should *only be used for MIDI in*, i.e. from USB devices to hardware
# MIDI synths, and *not* in the opposite direction. Doing so could risk damage to
# the microcontroller, your computer, or both.
# Wire a 10Ω resistor from the Tx pin on the Raspberry Pi Pico or other
# RP2040 board to the 3.5mm stereo jack tip, a 33Ω resistor from the 3v3 pin on
# the Raspberry Pi Pico to the 3.5mm stereo jack ring, and the ground pin on the
# Raspberry Pi Pico to the 3.5mm stereo jack sleeve.
# The code below assumes you're using USB MIDI channel 1. Change the number in
# square brackets on the midi_in line if you want to use a different channel.
import usb_midi
import board
import busio
midi_in = usb_midi.ports[0]
midi_out = busio.UART(tx=board.GP0, baudrate=31250)
while True:
msg = midi_in.read(3)
if len(msg):
midi_out.write(msg)
@mightywombat
Copy link

How would you wire this to the output jack if you were using a mono cable (like in eurorack)? My instinct is tx to tip and gnd to sleeve, and leave out the 3v3 connection, but I want to confirm.

@sandyjmacdonald
Copy link
Author

Yes, I think that should work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment