Skip to content

MIDI with MicroPython

Warnining

I am not an expert on MIDI and I don't have any MIDI gear. This is mostly a collection of material I have for students that want to use MicroPython to generate music.

Sample Code

Ascending Notes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# Play Test MIDI Ascending Notes
from machine import Pin, UART
import time
uart = UART(1, baudrate=31250, tx=Pin(4), rx=Pin(5))
uart.init(bits=8, parity=None, stop=1)
led=Pin("LED", Pin.OUT)
note = 24

while True:
    midimessage = bytearray([0x90, note, 64])
    uart.write(midimessage)
    led.toggle()
    # change third parameter to be 0
    midimessage = bytearray([0x90, note, 0])
    # pause 1/8 of a second
    time.sleep(0.125)
    note += 2
    if note > 64:
        note=24

References

Raspberry Pi Pico MIDI Development Board Midimuso for $20 US. This board has all the MIDI connectors on it.

Simple DIY electromusic Project

DIY Electro Music SDEMP MicroPython Code on GitHub

Pico MIDI by Barb Arach

PicoMIDI manual v1.0