MIDI Projects with MicroPython
Welcome to the MIDI Projects Section
Musical Instrument Digital Interface (MIDI) is the language that electronic instruments use to talk to each other. With a Raspberry Pi Pico and a few components, you can build your own MIDI instrument, controller, or sequencer. Let's build something amazing!
What Is MIDI?
Musical Instrument Digital Interface (MIDI) is a standard protocol that lets electronic instruments, computers, and controllers communicate with each other.
MIDI does not send audio — it sends instructions, like:
- "Play note 60 (Middle C) at volume 80"
- "Stop note 60"
- "Change to instrument 25 (steel guitar)"
These instructions are called MIDI messages. A synthesizer or software — like GarageBand or any Digital Audio Workstation (DAW) — receives the messages and produces the actual sound.
Key Idea
Think of MIDI like sheet music. The sheet music tells a musician what notes to play, but the musician (or synthesizer) decides what it sounds like. MIDI separates the instructions from the sound.
MIDI on the Raspberry Pi Pico
The Pico can send MIDI messages over its UART (Universal Asynchronous Receiver-Transmitter) serial port at the standard MIDI speed of 31,250 bits per second.
To send MIDI to external gear, you need:
- A MIDI output circuit (an optocoupler and resistors, or a ready-made board)
- A 5-pin DIN MIDI cable
For beginners, the easiest approach is to use USB MIDI by connecting the Pico directly to a computer. The computer sees the Pico as a USB MIDI device.
MIDI Hardware Options
| Option | Cost | Notes |
|---|---|---|
| Direct UART (serial MIDI) | about $1 in parts | Needs optocoupler circuit |
| PicoMIDI Development Board (Midimuso) | about $20 | All-in-one board with DIN connectors |
| USB MIDI (software only) | $0 | Needs special Pico W firmware |
Projects in This Section
| Project | What You Build |
|---|---|
| MIDI Basics | Send ascending MIDI notes over UART |
| Chromatic Scale | Play every note in one octave on a MIDI synth |
| Piano Keyboard | 13 buttons that play a full octave |
| MIDI Sequencer | A looping pattern of notes |
You Can Do This!
MIDI might look complicated at first with all those numbers. But once you see the pattern — three bytes for every message — it clicks very fast. You can do this!
Quick Start: Play a Note Over UART
You need:
- A Raspberry Pi Pico
- A MIDI output circuit connected to GP4 (TX1)
- A MIDI synthesizer, or a computer with a soft synth installed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | |
What Each Line Does
UART(1, baudrate=31250, tx=Pin(4), rx=Pin(5))— sets up UART 1 for MIDI on pins 4 and 5.uart.init(bits=8, parity=None, stop=1)— sets the exact serial format that MIDI requires.def note_on(channel, note, velocity):— defines a function to start a note. Velocity is how hard a key is pressed (0 = silent, 127 = loudest).0x90 | channel— combines the Note On command (0x90) with the channel number.uart.write(bytearray([...]))— sends the 3-byte MIDI message out the TX pin.def note_off(channel, note):— defines a function to stop a note.note_on(0, 60, 100)— starts playing Middle C at high volume on channel 0.note_off(0, 60)— stops playing Middle C.
MIDI Note Numbers
MIDI uses numbers from 0 to 127 for notes. Middle C is note number 60:
| Note | MIDI number |
|---|---|
| C4 (Middle C) | 60 |
| D4 | 62 |
| E4 | 64 |
| F4 | 65 |
| G4 | 67 |
| A4 (440 Hz) | 69 |
| B4 | 71 |
| C5 | 72 |
Monty's Tip
You can test MIDI without any hardware by installing a free software synthesizer on your computer. Try VirtualMIDISynth on Windows or the built-in IAC Driver on Mac. Connect the Pico via USB and the computer will receive your MIDI messages as if from a keyboard.
References
- MIDI Association — MIDI Basics
- Simple DIY Electromusic Project (Kevin)
- SDEMP MicroPython MIDI Code on GitHub
- Pico MIDI by Barb Arach
- PicoMIDI Development Board (Midimuso)
Great Work!
You now know how MIDI works and how to send MIDI messages from your Pico. Build the piano keyboard project next and make real music!