In this example, you'll receive MIDI in over UART with the Adafruit MIDI FeatherWing,  using a DIN-5 connector, to send the received MIDI messages out over USB with the Feather M4 Express. Basically, converting a UART MIDI device to use USB MIDI.

Plug the Feather RP2040 and the Adafruit MIDI FeatherWing into a FeatherWing Doubler.

Setup the Feather RP2040

For this example, you'll be using the Feather RP2040. To make sure it is setup properly with CircuitPython, please follow the steps in the guide below.

CircuitPython Code

Once you've finished setting up your Feather 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 board
import busio
import adafruit_midi
import usb_midi
from adafruit_midi.control_change import ControlChange
from adafruit_midi.pitch_bend import PitchBend
from adafruit_midi.note_off import NoteOff
from adafruit_midi.note_on import NoteOn

#  uart setup
uart = busio.UART(board.TX, board.RX, baudrate=31250)
#  midi channel setup
midi_in_channel = 1
midi_out_channel = 1
#  midi setup
#  UART is setup as the input
#  USB is setup as the output
midi = adafruit_midi.MIDI(
    in_channel=(midi_in_channel - 1),
    out_channel=(midi_out_channel - 1),

print("MIDI UART In/USB Out")
print("Default output channel:", midi.out_channel + 1)

#  array of message types
messages = (NoteOn, NoteOff, PitchBend, ControlChange)

while True:
    #  receive MIDI input from UART
    msg = midi.receive()

    #  if the input is a recognized message...
    if msg is not None:
        for i in range(0, 3):
            #  iterate through message types
            #  makes it so that you aren't sending any unnecessary messages
            if isinstance(msg, messages[i]):
                #  send the input out via USB

Upload the Code and Libraries to the Feather RP2040

After downloading the Project Bundle, plug your Feather 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 Feather RP2040's CIRCUITPY drive. 

  • lib folder

Your Feather RP2040 CIRCUITPY drive should look like this after copying the lib folder and the file.

How the CircuitPython Code Works

The MIDI FeatherWing's DIN-5 (or TRS) connections use MIDI over UART to transmit MIDI messages. Here, the code is setting up midi_in to use UART and midi_out to use the Feather's USB connection.

In the loop, when a recognized MIDI message is received, it is sent out via USB. As a result, you have a small form factor DIN-5 MIDI to USB MIDI converter.


You can connect your Feather via USB to either your computer or a USB MIDI host. Then, plug your DIN-5 hardware controller's output to the MIDI FeatherWing's input jack. When you send a MIDI message from your hardware controller, it should transmit via USB.

This essentially creates a simple DIN-5 to USB converter box. You could also do the reverse (taking MIDI in over USB and sending MIDI out over UART) if you wanted to send software MIDI to a hardware synth that did not have a USB connection.

This guide was first published on Mar 02, 2022. It was last updated on 2022-03-02 13:24:41 -0500.

This page (Receive MIDI Over UART and Send Over USB) was last updated on May 24, 2022.

Text editor powered by tinymce.