# MIDI for Makers

## Overview

Whether you're a classically trained pianist or a hobbyist who thinks synths sound really cool, the allure of DIY MIDI projects are incredibly tempting. It can be hard to know how to get started though. What board should you use? How does the code work? What even is MIDI?

This guide will tell you everything you need to know to get started with your own MIDI projects so that you can focus on building rather than searching everywhere on the internet.

![](https://cdn-learn.adafruit.com/assets/assets/000/109/137/medium800/microcontrollers_edited_P1320240.jpg?1645632335)

## What is MIDI?
Music Instrument Digital Interface (MIDI) is a 7-bit communication protocol that dates back to the 1980's. It may sound antiquated, but it is the standard digital communication method for all things music. If you've ever had a piano keyboard control a piece of software or digital audio workstation (DAW) on a computer, then you were using MIDI.

MIDI is dependable, predictable, reliable and at this point is usually plug and play without too much fuss. This also means that it's approachable for folks to build their own MIDI devices.

## Why build a MIDI controller?
There are a lot of aftermarket MIDI devices available, so why would you want to build your own? When you build your own MIDI controller, you can design it specifically for what you need. If you aren't quite sure what you want to do with MIDI, you can experiment and test things before committing to a full build. Additionally, you can share your MIDI project's details with the community for other musicians to benefit from.

## Parts
### Adafruit MIDI FeatherWing Kit

[Adafruit MIDI FeatherWing Kit](https://www.adafruit.com/product/4740)
Turn your Feather into a song-bird with this musically-enabled FeatherWing that adds MIDI input and output jacks to just about any Feather. You get both input and output DIN-5 MIDI jacks, a 3V optically isolator so you can interface with MIDI on 3.3V logic/power microcontrollers, and two...

In Stock
[Buy Now](https://www.adafruit.com/product/4740)
[Related Guides to the Product](https://learn.adafruit.com/products/4740/guides)
![Angled shot of a Adafruit MIDI FeatherWing Kit. ](https://cdn-shop.adafruit.com/640x480/4740-04.jpg)

### Adafruit Feather RP2040

[Adafruit Feather RP2040](https://www.adafruit.com/product/4884)
A new chip means a new Feather, and the Raspberry Pi RP2040 is no exception. When we saw this chip we thought "this chip is going to be awesome when we give it the Feather Treatment" and so we did! This Feather features the&nbsp; **RP2040** , and all niceties you know and...

In Stock
[Buy Now](https://www.adafruit.com/product/4884)
[Related Guides to the Product](https://learn.adafruit.com/products/4884/guides)
![Angled shot of black rectangular microcontroller "Feather RP2040"](https://cdn-shop.adafruit.com/640x480/4884-04.jpg)

### Adafruit QT Py RP2040

[Adafruit QT Py RP2040](https://www.adafruit.com/product/4900)
What a cutie pie! Or is it... a QT Py?&nbsp;This diminutive dev board comes with one of our new favorite chip, the RP2040. It's been made famous in the new [Raspberry Pi Pico](https://www.adafruit.com/pico) _and_ our [Feather...](http://www.adafruit.com/product/4884)

Out of Stock
[Buy Now](https://www.adafruit.com/product/4900)
[Related Guides to the Product](https://learn.adafruit.com/products/4900/guides)
![Video of hand holding a QT Py PCB in their hand. An LED glows rainbow colors.](https://cdn-shop.adafruit.com/product-videos/640x480/4900-06.jpg)

### Adafruit CLUE - nRF52840 Express with Bluetooth® LE

[Adafruit CLUE - nRF52840 Express with Bluetooth® LE](https://www.adafruit.com/product/4500)
Do you feel like you just don't have a CLUE? Well, we can help with that - get a CLUE here at Adafruit by picking up this sensor-packed development board. We wanted to build some projects that have a small screen and a lot of sensors. To make it compatible with existing projects, we made...

In Stock
[Buy Now](https://www.adafruit.com/product/4500)
[Related Guides to the Product](https://learn.adafruit.com/products/4500/guides)
![Animated GIF showing CLUE board  displaying data from the many on-board sensors.](https://cdn-shop.adafruit.com/product-videos/640x480/4500-04.jpg)

### Adafruit Metro M4 feat. Microchip ATSAMD51

[Adafruit Metro M4 feat. Microchip ATSAMD51](https://www.adafruit.com/product/3382)
Are you ready? Really ready? Cause here comes the fastest, most powerful Metro ever. The **Adafruit Metro M4** featuring the **Microchip ATSAMD51**. This Metro is like a bullet train, with its 120MHz Cortex M4 with floating point support. Your code will zig and zag...

In Stock
[Buy Now](https://www.adafruit.com/product/3382)
[Related Guides to the Product](https://learn.adafruit.com/products/3382/guides)
![Angled shot of a Adafruit Metro M4 feat. Microchip ATSAMD51. ](https://cdn-shop.adafruit.com/640x480/3382-13.jpg)

### Monochrome 1.3" 128x64 OLED graphic display - STEMMA QT / Qwiic

[Monochrome 1.3" 128x64 OLED graphic display - STEMMA QT / Qwiic](https://www.adafruit.com/product/938)
These displays are small, only about 1.3" diagonal, but very readable due to the high contrast of an OLED display. This display is made of 128x64 individual white OLED pixels, each one is turned on or off by the controller chip. Because the display makes its own light, no backlight is...

Out of Stock
[Buy Now](https://www.adafruit.com/product/938)
[Related Guides to the Product](https://learn.adafruit.com/products/938/guides)
![Monochrome 1.3" OLED module with Adafruit logos falling like snow](https://cdn-shop.adafruit.com/product-videos/640x480/938-05.jpg)

### Part: FeatherWing Doubler
quantity: 1
FeatherWing Doubler
[FeatherWing Doubler](https://www.adafruit.com/product/2890)

### Part: Breadboard
quantity: 1
Full Size
[Breadboard](https://www.adafruit.com/product/239)

### Part: Breadboard wire bundle
quantity: 1
Various size wires for breadboarding
[Breadboard wire bundle](https://www.adafruit.com/product/153)

### Part: Tactile Switch Buttons
quantity: 1
10 pack
[Tactile Switch Buttons](https://www.adafruit.com/product/1119)

### Part: Potentiometer
quantity: 4
1K
[Potentiometer](https://www.adafruit.com/product/1789)

### Part: Servo
quantity: 1
Micro servo
[Servo](https://www.adafruit.com/product/169)

### Part: STEMMA QT / Qwiic JST SH 4-pin Cable
quantity: 1
100 mm
[STEMMA QT / Qwiic JST SH 4-pin Cable](https://www.adafruit.com/product/4210)

### Part: USB A to USB C Cable
quantity: 1
1 meter long
[USB A to USB C Cable](https://www.adafruit.com/product/5153)

# MIDI for Makers

## How MIDI is Transmitted

![](https://cdn-learn.adafruit.com/assets/assets/000/109/136/medium800/microcontrollers_edited_P1320253.jpg?1645632308)

## MIDI In vs. MIDI Out
The MIDI communication protocol has two main options: MIDI in and MIDI out. MIDI **in** refers to receiving MIDI messages as an **input**. MIDI **out** refers to sending MIDI messages as an **output**.

Each type requires a different circuit to send or receive the messages properly. MIDI controllers will have the ports labeled as such. For homemade devices, you will define your device as either being an input or an output.

## MIDI Channels
MIDI messages are sent via channels. There are 16 available channels, numbered 1-16. The channels allow for devices to know what and who to listen to, similar to setting up a remote to control a specific television.

For example, a MIDI controller could send a C3 note and CC messages via channel 1 to a synthesizer setup to receive messages on channel 1. At the same time, that MIDI controller could send the same or different messages on channel 8 to a drum machine setup to receive messages on channel 8.

In code, these channels are numbered `0` to `15` because you are counting with [zero-based numbering](https://en.wikipedia.org/wiki/Zero-based_numbering). For example, real-world channel 1 is coded as channel `0`, real-world channel 2 is coded as channel `1`, etc.

In CircuitPython, your MIDI device's channel that it is listening to or sending messages on is defined at the beginning of your code. It looks like this:

`midi = adafruit_midi.MIDI(`  
`    midi_in=usb_midi.ports[0], in_channel=0, midi_out=usb_midi.ports[1], out_channel=0``)`

where `in_channel` and `out_channel` are holding the channel values.

In Arduino, it's a little different. In the `setup()`, the `begin()` function is called with `MIDI_CHANNEL_OMNI`. `MIDI_CHANNEL_OMNI` means that the code is able to listen for any of the 16 MIDI channels. it looks like this:

`MIDI_CREATE_DEFAULT_INSTANCE();`

`void setup()`  
`{`  
`  MIDI.begin(MIDI_CHANNEL_OMNI);`  
`}`

More discrete MIDI channel definitions can be defined when sending individual MIDI messages. Examples for this syntax are available on the [MIDI Messages](https://learn.adafruit.com/midi-for-makers/midi-messages) page of this guide.

## Connections
![](https://cdn-learn.adafruit.com/assets/assets/000/109/374/medium800/lcds___displays_edited_P1320286.jpg?1645826663)

### DIN-5
The original MIDI connector is a MIDI jack, or DIN-5 connector. These are chunky, hearty connectors. Though they are becoming less common on newer devices, they are reliable and provide a straight forward connection to transmit MIDI data.

![lcds___displays_edited_P1320278.jpg](https://cdn-learn.adafruit.com/assets/assets/000/109/372/medium640/lcds___displays_edited_P1320278.jpg?1645826461)

### TRS-A
A newer MIDI connection standard that has been implemented is TRS-A, which utilizes a TRS audio jack to transmit MIDI data over UART. When this first began appearing, the connection was not standardized so older devices may require specialized cables for full compatibility.&nbsp;

The standardized pinout for TRS-A is as follows:

- MIDI **Sink** to TRS **Tip**
- MIDI **Source** to TRS **Ring**
- MIDI **Shield** to TRS **Sleeve**

This new standard allows for the reliability of a DIN-5 connector, but in a smaller and more common form factor.

![lcds___displays_edited_P1320275.jpg](https://cdn-learn.adafruit.com/assets/assets/000/109/373/medium640/lcds___displays_edited_P1320275.jpg?1645827008)

Warning: 

[For more information on TRS MIDI connections, check out this resource from audionerd](https://minimidi.world/)
### MIDI over UART
When you see a connection with a DIN-5 or TRS-A connector, the device is using MIDI over **UART**. MIDI over UART transmits MIDI messages over the TX and RX serial connections at a baud rate of 31250.

You can use MIDI over UART to create MIDI devices using older boards with microcontrollers that do not have support for direct USB communication, such as the Atmega328. Additionally, you can have boards communicate with each other over MIDI directly using UART.

### Adafruit METRO 328 Fully Assembled - Arduino IDE compatible

[Adafruit METRO 328 Fully Assembled - Arduino IDE compatible](https://www.adafruit.com/product/50)
We sure love the ATmega328 here at Adafruit, and we use them&nbsp;_a lot_&nbsp;for our own projects. The processor has plenty of GPIO, Analog inputs, hardware UART SPI and I2C, timers and PWM galore - just enough for most simple projects. When we need to go small, we use a <a...></a...>

Out of Stock
[Buy Now](https://www.adafruit.com/product/50)
[Related Guides to the Product](https://learn.adafruit.com/products/50/guides)
![Angled shot of a Adafruit METRO 328 Fully Assembled](https://cdn-shop.adafruit.com/640x480/50-09.jpg)

### USB MIDI
USB MIDI has become more common for MIDI controllers. These devices have a configuration descriptor allowing them to be plug and play. These do not have direct compatibility with MIDI over UART devices, and, as a result, would require a converter to communicate directly.&nbsp;

For MIDI over USB devices, you can use them with your computer to interface with music tech software. You can also use them with a USB MIDI Host, which allows for USB devices to interface with each other. There are aftermarket USB MIDI hosts available, as well as DIY options ([you can even use a Raspberry Pi](https://neuma.studio/rpi-midi-complete.html)).

Many current microcontrollers have the ability to be used for DIY USB MIDI projects, including boards that are based on the ATSAMD21 (M0 Express), ATSAMD51 (M4 Express) and RP2040. All of these boards have support for both CircuitPython and Arduino.

### Adafruit ItsyBitsy M0 Express - for CircuitPython & Arduino IDE

[Adafruit ItsyBitsy M0 Express - for CircuitPython & Arduino IDE](https://www.adafruit.com/product/3727)
What's smaller than a Feather but larger than a Trinket? It's an **Adafruit ItsyBitsy M0 Express**! Small, powerful, with a rockin' ATSAMD21 Cortex M0 processor running at 48 MHz - this microcontroller board is perfect when you want something very compact, but still...

In Stock
[Buy Now](https://www.adafruit.com/product/3727)
[Related Guides to the Product](https://learn.adafruit.com/products/3727/guides)
![Angled shot of Adafruit ItsyBitsy M0 Express - for CircuitPython & Arduino IDE.](https://cdn-shop.adafruit.com/640x480/3727-06.jpg)

### Adafruit Feather M4 Express - Featuring ATSAMD51

[Adafruit Feather M4 Express - Featuring ATSAMD51](https://www.adafruit.com/product/3857)
It's what you've been waiting for, the Feather M4 Express featuring ATSAMD51. This Feather is fast like a swift, smart like an owl, strong like a ox-bird (it's half ox, half bird, OK?) This feather is powered by our new favorite chip, the **ATSAMD51J19** -&nbsp; with...

In Stock
[Buy Now](https://www.adafruit.com/product/3857)
[Related Guides to the Product](https://learn.adafruit.com/products/3857/guides)
![Angled shot of a Adafruit Feather M4 Express. ](https://cdn-shop.adafruit.com/640x480/3857-10.jpg)

### Adafruit QT Py RP2040

[Adafruit QT Py RP2040](https://www.adafruit.com/product/4900)
What a cutie pie! Or is it... a QT Py?&nbsp;This diminutive dev board comes with one of our new favorite chip, the RP2040. It's been made famous in the new [Raspberry Pi Pico](https://www.adafruit.com/pico) _and_ our [Feather...](http://www.adafruit.com/product/4884)

Out of Stock
[Buy Now](https://www.adafruit.com/product/4900)
[Related Guides to the Product](https://learn.adafruit.com/products/4900/guides)
![Video of hand holding a QT Py PCB in their hand. An LED glows rainbow colors.](https://cdn-shop.adafruit.com/product-videos/640x480/4900-06.jpg)

### BLE MIDI
One of the more unique ways to transmit MIDI is over Bluetooth with BLE MIDI. BLE MIDI allows for wireless MIDI communication over Bluetooth. It can be the perfect choice for some projects that benefit from not being tethered by cables.

If you want to build a BLE MIDI project, you'll want to use an nRF52840 Express-based board, which has support for BLE.

### Adafruit CLUE - nRF52840 Express with Bluetooth® LE

[Adafruit CLUE - nRF52840 Express with Bluetooth® LE](https://www.adafruit.com/product/4500)
Do you feel like you just don't have a CLUE? Well, we can help with that - get a CLUE here at Adafruit by picking up this sensor-packed development board. We wanted to build some projects that have a small screen and a lot of sensors. To make it compatible with existing projects, we made...

In Stock
[Buy Now](https://www.adafruit.com/product/4500)
[Related Guides to the Product](https://learn.adafruit.com/products/4500/guides)
![Animated GIF showing CLUE board  displaying data from the many on-board sensors.](https://cdn-shop.adafruit.com/product-videos/640x480/4500-04.jpg)

### Adafruit Feather nRF52840 Express

[Adafruit Feather nRF52840 Express](https://www.adafruit.com/product/4062)
The **Adafruit Feather nRF52840 Express** is the new Feather family member with Bluetooth® Low Energy and _native USB support_ featuring the nRF52840!&nbsp; It's our take on an 'all-in-one' Arduino-compatible + Bluetooth® Low Energy with built-in USB...

In Stock
[Buy Now](https://www.adafruit.com/product/4062)
[Related Guides to the Product](https://learn.adafruit.com/products/4062/guides)
![Angled shot of a Adafruit Feather nRF52840 Express. ](https://cdn-shop.adafruit.com/640x480/4062-02.jpg)

# MIDI for Makers

## MIDI Messages

![](https://cdn-learn.adafruit.com/assets/assets/000/109/135/medium800/microcontrollers_edited_P1320247.jpg?1645632284)

You've read how MIDI is transmitted, but what exactly are MIDI messages? This section will go through the most commonly used messages and show how to send them with either CircuitPython or Arduino.

[For more information on the Arduino MIDI library, check out this documentation on GitHub.IO](http://fortyseveneffects.github.io/arduino_midi_library/)
[For more information on the CircuitPython MIDI library, check out this documentation on readthedocs](https://circuitpython.readthedocs.io/projects/midi/en/latest/index.html)
## NoteOn
This message begins playing a note. A MIDI `NoteOn` message sends the MIDI note number and the velocity of the note.

MIDI note numbers range from `0` to `127`, where `21` is A0. [Inspired Acoustics](https://www.inspiredacoustics.com/en/MIDI_note_numbers_and_center_frequencies) has a great table here showing the MIDI note numbers with their corresponding English note name, piano key number and pitch frequency.

### CircuitPython
```python
midi.send(NoteOn(note, velocity))
```

### Arduino
```cpp
MIDI.sendNoteOn(note, velocity, midi channel);
```

## NoteOff
This stops a note from playing. If a `NoteOff` message is _not_ sent after a `NoteOn` message, the note will continue playing forever. A MIDI `NoteOff` message sends the note number and the velocity of the note.

### CircuitPython
```python
midi.send(NoteOff(note, velocity))
```

### Arduino
```cpp
MIDI.sendNoteOff(note, velocity, midi channel);
```

## ControlChange Messages
`ControlChange` (CC) messages are utility messages that can have a range of functionality. CC messages are usually what is sent when you turn a knob or move a slider on a MIDI controller. Some examples of common messages are modulation and sustain. Each CC message has an assigned number. The MIDI Association has a resource listing CC messages [here](https://www.midi.org/specifications-old/item/table-3-control-change-messages-data-bytes-2).

A MIDI CC message contains the CC number and the value that you want to send to that control change. The value range will differ depending on the CC message, but usually have a range of `0` - `127`.

### CircuitPython
```python
midi.send(ControlChange(CC, value))
```

### Arduino
```cpp
MIDI.sendControlChange(CC, value, midi channel);
```

## PitchBend
`PitchBend` is a special MIDI message, with a range of `0` to `16383`. Since pitch can be bent up or down, the midpoint (no pitch bend) is `8192`.

### CircuitPython
```python
x = PitchBend(value)
midi.send(x)
```

### Arduino
```cpp
MIDI.sendPitchBend(value, midi channel);
```

## Reading MIDI In
You can receive MIDI data and have your microcontroller read the incoming MIDI message.

### CircuitPython
```python
midi.receive()
```

### Arduino
```cpp
MIDI.read();
```

# MIDI for Makers

## Let's Build!

![](https://cdn-learn.adafruit.com/assets/assets/000/109/134/medium800/microcontrollers_edited_P1320236.jpg?1645632269)

In the next section, you'll be able to look at six example projects that apply the MIDI knowledge in this guide. You can reference these projects for your own creations.

The first three projects are examples for sending MIDI out:

- **Basic MIDI Keyboard**
  - Send MIDI notes with button presses

- **MIDI CC Control with Pots**
  - Affect control change messages with potentiometers

- **BLE MIDI Sequencer**
  - Send arpeggios to a synth over BLE MIDI. Wireless melodies!

The last three projects are examples for receiving MIDI in:

- **Receive and Display MIDI Messages**
  - Using an LCD screen, view the MIDI messages being sent in real-time from a MIDI controller

- **Receive MIDI Over UART and Send Over USB**
  - Convert a UART MIDI device to a USB MIDI device

- **Control Motors with MIDI**
  - You can control a variety of peripherals with MIDI messages. Motors are common since you can create MIDI-controlled robotic instruments

## Prerequisite Guides
If this is your first time using electronics or CircuitPython, you will want to browse these guides first to have a better background when trying out the MIDI example projects.

[Welcome to CircuitPython! Learn Guide](https://learn.adafruit.com/welcome-to-circuitpython)
[CircuitPython Essentials Learn Guide](https://learn.adafruit.com/circuitpython-essentials)
[Which CircuitPython Board is Right for You? Learn Guide](https://learn.adafruit.com/choose-your-circuitpython-board)
# MIDI for Makers

## Basic MIDI Keyboard

![](https://cdn-learn.adafruit.com/assets/assets/000/109/138/medium800/microcontrollers_edited_P1320235.jpg?1645632364)

Being able to send note messages is one of the most popular MIDI projects. In this example, you'll see how to use button inputs to send `NoteOn` and `NoteOff` messages to a synth or DAW.

Below, a simple circuit is built using a Feather RP2040 microcontroller board wired to four buttons. The components and wires are seated in a [breadboard](https://www.adafruit.com/product/239 "Breadboard") which facilitates connections via wires.

The Feather will need to have header pins soldered on. The Breadboard can help hold them while you do this.

## Circuit Diagram
- **Button 1**
  - **Pin 1** to Feather pin **D5**
  - **Pin 4** to Feather **GND**

- **Button 2**
  - **Pin 1** to Feather pin **D6**
  - **Pin 4** to Feather **GND**

- **Button 3**
  - **Pin 1** to Feather pin **D9**
  - **Pin 4** to Feather **GND**

- **Button 4**
  - **Pin 1** to Feather pin **D10**
  - **Pin 4** to Feather **GND**

![microcontrollers_noteOnNoteOff.png](https://cdn-learn.adafruit.com/assets/assets/000/109/022/medium640/microcontrollers_noteOnNoteOff.png?1644941006)

## 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.

[Feather RP2040 CircuitPython Setup](https://learn.adafruit.com/adafruit-feather-rp2040-pico/circuitpython)
## 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 **&nbsp;Download Project Bundle** &nbsp;button in the window below. It will download as a zipped folder.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/MIDI_for_Makers/Basic_MIDI_Keyboard/code.py

## 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&nbsp; **CIRCUITPY**. Unzip the folder and copy the following items to the Feather RP2040's&nbsp; **CIRCUITPY** &nbsp;drive.&nbsp;

- **lib** &nbsp;folder
- **code.py**

Your Feather RP2040&nbsp; **CIRCUITPY&nbsp;** drive should look like this after copying the&nbsp; **lib** &nbsp;folder and the&nbsp; **code.py&nbsp;** file.

![](https://cdn-learn.adafruit.com/assets/assets/000/109/128/medium800/microcontrollers_midiMakersLibs.jpg?1645622169)

## How the CircuitPython Code Works
The MIDI note numbers assigned to each button are setup in the `midi_notes` array. When a key press is detected, a `NoteOn` message with the corresponding MIDI note number is sent. When a key is released, then a `NoteOff` message is sent.

If you wanted to change the notes or buttons, you would edit the `midi_notes` and `key_pins` array.

## Usage
You can connect your Feather RP2040 via USB to either your computer or a USB MIDI host. Then, press the buttons to play the notes of a C major triad.&nbsp;

A DIY MIDI keyboard is a very popular project. You can add more buttons, change the notes or create a fun enclosure to customize this project further.

https://www.youtube.com/watch?v=BxIuHFkJNBE

# MIDI for Makers

## MIDI CC Control with Pots

![](https://cdn-learn.adafruit.com/assets/assets/000/109/139/medium800/microcontrollers_edited_P1320243.jpg?1645632376)

Potentiometers (often times shortened to the word pots, which are resistors varied by turning a knob) are a common peripheral on MIDI controllers. They also provide a greater sense of control than clicking and dragging when using a mouse with a DAW. In this example, you'll see how to update control change (CC) messages with pots.

## Circuit Diagram
- **Pot 1**
  - **Pin 1** to QT Py RP2040 **GND**
  - **Pin 2** to QT Py RP2040 **A0**
  - **Pin 3** to QT Py RP2040 **3V**

- **Pot 2**
  - **Pin 1** to QT Py RP2040 **GND**
  - **Pin 2** to QT Py RP2040 **A1**
  - **Pin 3** to QT Py RP2040 **3V**

- **Pot 3**
  - **Pin 1** to QT Py RP2040 **GND**
  - **Pin 2** to QT Py RP2040 **A2**
  - **Pin 3** to QT Py RP2040 **3V**

- **Pot 4**
  - **Pin 1** to QT Py RP2040 **GND**
  - **Pin 2** to QT Py RP2040 **A3**
  - **Pin 3** to QT Py RP2040 **3V**

![microcontrollers_sendCC.png](https://cdn-learn.adafruit.com/assets/assets/000/109/025/medium640/microcontrollers_sendCC.png?1644939829)

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

[QT Py RP2040 CircuitPython Setup](https://learn.adafruit.com/adafruit-qt-py-2040/circuitpython)
## CircuitPython Code
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 **&nbsp;Download Project Bundle** &nbsp;button in the window below. It will download as a zipped folder.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/MIDI_for_Makers/MIDI_CC_Control_with_Pots/code.py

## Upload the Code and Libraries to the QT Py RP2040
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&nbsp; **CIRCUITPY**. Unzip the folder and copy the following items to the QT Py RP2040's&nbsp; **CIRCUITPY** &nbsp;drive.&nbsp;

- **lib** &nbsp;folder
- **code.py**

Your QT Py RP2040&nbsp; **CIRCUITPY&nbsp;** drive should look like this after copying the&nbsp; **lib** &nbsp;folder and the&nbsp; **code.py&nbsp;** file.

![](https://cdn-learn.adafruit.com/assets/assets/000/109/129/medium800/microcontrollers_midiPotsLib.jpg?1645622374)

## How the CircuitPython Code Works
The `map_range()` function is used to map the analog values from the potentiometers to MIDI values. The `_val1` and `_val2` variables are compared to each other for each pot to see if the pot has been turned. If it has, then an updated MIDI value is sent.&nbsp;

## Usage
You can connect your QT Py RP2040 via USB to either your computer or a USB MIDI host. Then, turn the knobs to affect modulation, sustain and pitch bend. This project works best with a software or hardware synth since the effects generally affect musical input happening in real time.

Going further, you could combine this project with the components and code from the MIDI keyboard example to create a larger MIDI interface.

https://www.youtube.com/watch?v=eFYiZPMJzs4

# MIDI for Makers

## BLE MIDI Sequencer

![](https://cdn-learn.adafruit.com/assets/assets/000/109/140/medium800/microcontrollers_edited_P1320266.jpg?1645632390)

BLE MIDI lets you send MIDI data wirelessly over Bluetooth. In this example, you'll use a CLUE to send arpeggios to a DAW.

## Setup the CLUE
This example uses an Adafruit CLUE microcontroller board. To make sure it is setup properly with CircuitPython, please follow the steps in the guide below.

[CLUE CircuitPython Setup](https://learn.adafruit.com/adafruit-clue/circuitpython)
## CircuitPython Code
Once you've finished setting up your CLUE with CircuitPython, you can access the code and necessary libraries by downloading the Project Bundle.

To do this, click on the **&nbsp;Download Project Bundle** &nbsp;button in the window below. It will download as a zipped folder.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/MIDI_for_Makers/BLE_MIDI_Sequencer/code.py

## Upload the Code and Libraries to the CLUE
After downloading the Project Bundle, plug your CLUE 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&nbsp; **CIRCUITPY**. Unzip the folder and copy the following items to the CLUE's&nbsp; **CIRCUITPY** &nbsp;drive.&nbsp;

- **lib** &nbsp;folder
- **code.py**

Your CLUE&nbsp; **CIRCUITPY&nbsp;** drive should look like this after copying the&nbsp; **lib** &nbsp;folder and the&nbsp; **code.py&nbsp;** file.

![](https://cdn-learn.adafruit.com/assets/assets/000/109/130/medium800/microcontrollers_clueMidiLibs.jpg?1645622468)

## How the CircuitPython Code Works
There are three sequences of MIDI note numbers setup: `c_triad`, `f_triad` and `g_triad`. These correspond with the CLUE's three capacitive touch inputs.&nbsp;

In the loop, `NoteOn` and `NoteOff` messages are sent every `0.5` seconds to play through the triad. If a touch input is detected, then the triad updates.

The code is using BLE MIDI to utilize the CLUE's nRF52840. The loop is dependent on a BLE connection being active, otherwise the CLUE will wait for a connection.

## Usage
You can connect your CLUE via BLE to your computer or mobile device. After a BLE connection is established, open your preferred music software to send the arpeggios to a software synth. Tap the three capacitive touch inputs to change the chord.

Going further, you could change the notes being sent and also play with the timing for sending the notes. You could use an additional input to code up a tap tempo to set the beats per minute (BPM) for sending notes.

https://www.youtube.com/watch?v=p4ffRAgaRFU

# MIDI for Makers

## Receive and Display MIDI Messages

![](https://cdn-learn.adafruit.com/assets/assets/000/109/467/medium800/lcds___displays_edited_P1320294.jpg?1646352817)

Reading incoming MIDI messages can come in handy for troubleshooting, hacking or general curiosity. In this example, you'll see how to receive MIDI in messages and display them on an LCD screen.

## Circuit Diagram
You can easily connect the LCD to the QT Py RP2040 with a STEMMA QT cable.

- LCD **3V** to QT Py RP2040 **3V**
- LCD **GND** to QT Py RP2040 **GND**
- LCD **SDA** to QT Py RP2040 **SDA**
- LCD **SCL** to QT Py RP2040 **SCL**

![microcontrollers_midiInMessages.png](https://cdn-learn.adafruit.com/assets/assets/000/109/026/medium640/microcontrollers_midiInMessages.png?1644943051)

## Setup the QT Py RP2040
This example uses an QT Py RP2040. To make sure it is setup properly with CircuitPython, please follow the steps in the guide below.

[QT Py RP2040 CircuitPython Setup](https://learn.adafruit.com/adafruit-qt-py-2040/circuitpython)
## CircuitPython Code
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 **&nbsp;Download Project Bundle** &nbsp;button in the window below. It will download as a zipped folder.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/MIDI_for_Makers/Receive_and_Display_MIDI_Messages/code.py

## Upload the Code and Libraries to the QT Py RP2040
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&nbsp; **CIRCUITPY**. Unzip the folder and copy the following items to the QT Py RP2040's&nbsp; **CIRCUITPY** &nbsp;drive.&nbsp;

- **lib** &nbsp;folder
- **code.py**

Your QT Py RP2040&nbsp; **CIRCUITPY&nbsp;** drive should look like this after copying the&nbsp; **lib** &nbsp;folder and the&nbsp; **code.py&nbsp;** file.

![](https://cdn-learn.adafruit.com/assets/assets/000/109/131/medium800/microcontrollers_midiDisLibs.jpg?1645622578)

## How the CircuitPython Code Works
`msg` is acting as a variable to hold the incoming MIDI messages received with `midi.receive()`. Every time a new message comes in, the text on the screen is updated using `text_area.text`. The message values are converted to strings using `str()` so that they can be displayed.

## Usage
You can connect your QT Py RP2040 via USB to either your computer or a USB MIDI host. Setup your software to send MIDI messages out and you will see the messages update in real time on the screen.&nbsp;

You can use this project to figure out what MIDI messages are being sent out, especially with ControlChange messages.

https://www.youtube.com/watch?v=wSOXQBgUGpA

# MIDI for Makers

## Receive MIDI Over UART and Send Over USB

![](https://cdn-learn.adafruit.com/assets/assets/000/109/142/medium800/microcontrollers_edited_P1320259.jpg?1645632414)

In this example, you'll receive MIDI in over UART with the Adafruit MIDI FeatherWing,&nbsp; 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.

![microcontrollers_inUartOutUSB.png](https://cdn-learn.adafruit.com/assets/assets/000/109/144/medium640/microcontrollers_inUartOutUSB.png?1645632760)

[For more information on the Adafruit MIDI FeatherWing, check out this guide](https://learn.adafruit.com/adafruit-midi-featherwing/overview)
## 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.

[Feather RP2040 CircuitPython Setup](https://learn.adafruit.com/adafruit-feather-rp2040-pico/circuitpython)
## 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 **&nbsp;Download Project Bundle** &nbsp;button in the window below. It will download as a zipped folder.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/MIDI_for_Makers/Receive_MIDI_Over_UART_and_Send_Over_USB/code.py

## 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&nbsp; **CIRCUITPY**. Unzip the folder and copy the following items to the Feather RP2040's&nbsp; **CIRCUITPY** &nbsp;drive.&nbsp;

- **lib** &nbsp;folder
- **code.py**

Your Feather RP2040&nbsp; **CIRCUITPY&nbsp;** drive should look like this after copying the&nbsp; **lib** &nbsp;folder and the&nbsp; **code.py&nbsp;** file.

![](https://cdn-learn.adafruit.com/assets/assets/000/109/132/medium800/microcontrollers_midiMakersLibs.jpg?1645622611)

## 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.

## Usage
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.

https://www.youtube.com/watch?v=sNN1Hre9_0E

# MIDI for Makers

## Control Motors with MIDI

![](https://cdn-learn.adafruit.com/assets/assets/000/109/143/medium800/microcontrollers_edited_P1320251.jpg?1645632426)

Musical robots controlled by incoming MIDI messages are a popular project. This example will show how you can use MIDI in messages to affect a servo motor.

## Circuit Diagram
- Servo **GND** to Metro M4 Express **GND**
- Servo **power** to Metro M4 Express **5V**
- Servo **signal** to Metro M4 Express pin **D2**

![microcontrollers_midiToServo.png](https://cdn-learn.adafruit.com/assets/assets/000/109/028/medium640/microcontrollers_midiToServo.png?1644943739)

## Setup the Metro M4 Express
This example uses a Metro M4 Express microcontroller board. To make sure it is setup properly with CircuitPython, please follow the steps in the guide below.

[Metro M4 Express CircuitPython Setup](https://learn.adafruit.com/adafruit-metro-m4-express-featuring-atsamd51/circuitpython)
## CircuitPython Code
Once you've finished setting up your Metro M4 Express with CircuitPython, you can access the code and necessary libraries by downloading the Project Bundle.

To do this, click on the **&nbsp;Download Project Bundle** &nbsp;button in the window below. It will download as a zipped folder.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/MIDI_for_Makers/Control_Motors_with_MIDI/code.py

## Upload the Code and Libraries to the Metro M4 Express
After downloading the Project Bundle, plug your Metro M4 Express 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&nbsp; **CIRCUITPY**. Unzip the folder and copy the following items to the Metro M4 Express's&nbsp; **CIRCUITPY** &nbsp;drive.&nbsp;

- **lib** &nbsp;folder
- **code.py**

Your Metro M4 Express&nbsp; **CIRCUITPY&nbsp;** drive should look like this after copying the&nbsp; **lib** &nbsp;folder and the&nbsp; **code.py&nbsp;** file.

![](https://cdn-learn.adafruit.com/assets/assets/000/109/133/medium800/microcontrollers_midiMotorLibs.jpg?1645622707)

## How the CircuitPython Code Works
This code is an example of having another peripheral react to a MIDI input. Every time a `NoteOn` message is received, the servo turns to `180` degrees. When a `NoteOff` message is received, the servo turns back to `0` degrees.

## Usage
You can connect your Metro M4 via USB to either your computer or a USB MIDI host. Send MIDI `NoteOn` and `NoteOff` messages to the Metro and you should see the servo move back and forth accordingly.

Musical robots are a popular music technology project that often incorporate MIDI. Using techniques like this can also be useful in interactive installations where folks can see a physical reaction to a digital input.

https://www.youtube.com/watch?v=mnKVtUq_rNY

# MIDI for Makers

## MIDI Projects on the Learn System

There are many fantastic [MIDI projects on the Adafruit Learning System](https://learn.adafruit.com/search?q=midi) for you to get further inspiration from. These projects are full builds compared to the examples in this guide, so you can get some ideas for enclosures, hardware and more advanced code.

## [Raspberry Pi Pico and LED Arcade Button MIDI Controller](https://learn.adafruit.com/raspberry-pi-pico-led-arcade-button-midi-controller-fighter)
This project uses 16 light-up arcade buttons to send MIDI note messages out. Additionally, it has a 5-way joystick and a screen to change the MIDI note numbers assigned to each button on the go.

## [Trellis M4 Expressive MIDI Controller](https://learn.adafruit.com/trellis-m4-midi-keypad-and-tilt-controller)
This project uses the Trellis M4 to have 32 button inputs for sending MIDI out. Additionally, it uses the built-in accelerometer to control MIDI parameters by panning and tilting the board.

## [MIDI Solenoid Drummer](https://learn.adafruit.com/midi-solenoid-drummer)
This project sends MIDI out to control solenoid motors. The solenoids are setup to hit percussive objects to create a robotic percussion instrument.

## [MIDI Melody Maker](https://learn.adafruit.com/midi-melody-maker)
This project sends MIDI note sequences out. There are parameters for changing the note pattern, key and note value. Additionally, there is a slider that affects the BPM, or the speed, at which notes are sent out.&nbsp;

## [Power Glove Wireless MIDI Controller](https://learn.adafruit.com/power-glove-bluetooth-midi-controller)
This project uses BLE MIDI to modify a classic Nintendo Power Glove to be a wireless MIDI controller. Flex sensors in the fingers are used to affect the values of the MIDI messages.


## Featured Products

### Adafruit MIDI FeatherWing Kit

[Adafruit MIDI FeatherWing Kit](https://www.adafruit.com/product/4740)
Turn your Feather into a song-bird with this musically-enabled FeatherWing that adds MIDI input and output jacks to just about any Feather. You get both input and output DIN-5 MIDI jacks, a 3V optically isolator so you can interface with MIDI on 3.3V logic/power microcontrollers, and two...

In Stock
[Buy Now](https://www.adafruit.com/product/4740)
[Related Guides to the Product](https://learn.adafruit.com/products/4740/guides)
### Adafruit Feather RP2040

[Adafruit Feather RP2040](https://www.adafruit.com/product/4884)
A new chip means a new Feather, and the Raspberry Pi RP2040 is no exception. When we saw this chip we thought "this chip is going to be awesome when we give it the Feather Treatment" and so we did! This Feather features the&nbsp; **RP2040** , and all niceties you know and...

In Stock
[Buy Now](https://www.adafruit.com/product/4884)
[Related Guides to the Product](https://learn.adafruit.com/products/4884/guides)
### Adafruit QT Py RP2040

[Adafruit QT Py RP2040](https://www.adafruit.com/product/4900)
What a cutie pie! Or is it... a QT Py?&nbsp;This diminutive dev board comes with one of our new favorite chip, the RP2040. It's been made famous in the new [Raspberry Pi Pico](https://www.adafruit.com/pico) _and_ our [Feather...](http://www.adafruit.com/product/4884)

Out of Stock
[Buy Now](https://www.adafruit.com/product/4900)
[Related Guides to the Product](https://learn.adafruit.com/products/4900/guides)
### Adafruit CLUE - nRF52840 Express with Bluetooth® LE

[Adafruit CLUE - nRF52840 Express with Bluetooth® LE](https://www.adafruit.com/product/4500)
Do you feel like you just don't have a CLUE? Well, we can help with that - get a CLUE here at Adafruit by picking up this sensor-packed development board. We wanted to build some projects that have a small screen and a lot of sensors. To make it compatible with existing projects, we made...

In Stock
[Buy Now](https://www.adafruit.com/product/4500)
[Related Guides to the Product](https://learn.adafruit.com/products/4500/guides)
### Adafruit Metro M4 feat. Microchip ATSAMD51

[Adafruit Metro M4 feat. Microchip ATSAMD51](https://www.adafruit.com/product/3382)
Are you ready? Really ready? Cause here comes the fastest, most powerful Metro ever. The **Adafruit Metro M4** featuring the **Microchip ATSAMD51**. This Metro is like a bullet train, with its 120MHz Cortex M4 with floating point support. Your code will zig and zag...

In Stock
[Buy Now](https://www.adafruit.com/product/3382)
[Related Guides to the Product](https://learn.adafruit.com/products/3382/guides)
### FeatherWing Doubler - Prototyping Add-on For All Feather Boards

[FeatherWing Doubler - Prototyping Add-on For All Feather Boards](https://www.adafruit.com/product/2890)
This is the **FeatherWing Doubler** - a prototyping add-on and more for all Feather boards. This is similar to our [FeatherWing Proto](https://www.adafruit.com/products/2884) except there are two! The magic of the Doubler comes when stacking a Feather and another...

In Stock
[Buy Now](https://www.adafruit.com/product/2890)
[Related Guides to the Product](https://learn.adafruit.com/products/2890/guides)
### Tactile Switch Buttons (12mm square, 6mm tall) x 10 pack

[Tactile Switch Buttons (12mm square, 6mm tall) x 10 pack](https://www.adafruit.com/product/1119)
Medium-sized clicky momentary switches are standard input "buttons" on electronic projects. These work best in a PCB but [can be used on a solderless breadboard as shown in this tutorial](https://learn.adafruit.com/adafruit-arduino-lesson-6-digital-inputs?view=all). The...

In Stock
[Buy Now](https://www.adafruit.com/product/1119)
[Related Guides to the Product](https://learn.adafruit.com/products/1119/guides)
### Panel Mount 1K potentiometer (Breadboard Friendly)

[Panel Mount 1K potentiometer (Breadboard Friendly)](https://www.adafruit.com/product/1789)
This **1K** potentiometer is a two-in-one, good in a breadboard or with a panel. It's a fairly standard linear taper 1K ohm potentiometer, with a grippy shaft. It's smooth and easy to turn, but not so loose that it will shift on its own. We like this one because the legs are...

In Stock
[Buy Now](https://www.adafruit.com/product/1789)
[Related Guides to the Product](https://learn.adafruit.com/products/1789/guides)

## Related Guides

- [Adafruit Metro M4 Express featuring ATSAMD51](https://learn.adafruit.com/adafruit-metro-m4-express-featuring-atsamd51.md)
- [Introducing Adafruit CLUE](https://learn.adafruit.com/adafruit-clue.md)
- [Adafruit MIDI FeatherWing](https://learn.adafruit.com/adafruit-midi-featherwing.md)
- [Introducing Adafruit Feather RP2040](https://learn.adafruit.com/adafruit-feather-rp2040-pico.md)
- [Adafruit QT Py RP2040](https://learn.adafruit.com/adafruit-qt-py-2040.md)
- [BLE Thermal "Cat" Printer with CircuitPython](https://learn.adafruit.com/ble-thermal-cat-printer-with-circuitpython.md)
- [CLUE Dice Roller](https://learn.adafruit.com/clue-dice-roller.md)
- [LIS3MDL Triple-axis Magnetometer](https://learn.adafruit.com/lis3mdl-triple-axis-magnetometer.md)
- [7 Segment Display Internet Clock](https://learn.adafruit.com/7-segment-display-internet-clock.md)
- [Touch Deck: DIY Customizable TFT Control Pad](https://learn.adafruit.com/touch-deck-diy-tft-customized-control-pad.md)
- [CircuitPython 101: Basic Builtin Data Structures](https://learn.adafruit.com/basic-datastructures-in-circuitpython.md)
- [Toddler Timer](https://learn.adafruit.com/toddler-timer.md)
- [3D Printed LED Buckle](https://learn.adafruit.com/3d-printed-led-buckle.md)
- [Mini GIF Players](https://learn.adafruit.com/mini-gif-players.md)
- [MIDI Breath Controller](https://learn.adafruit.com/midi-breath-controller.md)
- [Bluetooth Cycling Speed & Cadence Sensor Display with Clue](https://learn.adafruit.com/bluetooth-bicycle-speed-cadence-sensor-display-with-clue.md)
- [Controlling Objects in Unity with a 9 DoF Sensor and Arduino](https://learn.adafruit.com/controlling-objects-in-unity-with-arduino.md)
- [CircuitPython MIDI to CV Skull](https://learn.adafruit.com/circuitpython-midi-to-cv-skull.md)
- [AdaBox 015](https://learn.adafruit.com/adabox015.md)
- [Native MP3 decoding on Arduino](https://learn.adafruit.com/native-mp3-decoding-on-arduino.md)
