Skip to content

Instantly share code, notes, and snippets.

@ypelletier
Created July 9, 2025 16:03
Show Gist options
  • Select an option

  • Save ypelletier/996a28038c640f482e0339a2a515ccb4 to your computer and use it in GitHub Desktop.

Select an option

Save ypelletier/996a28038c640f482e0339a2a515ccb4 to your computer and use it in GitHub Desktop.
Réception d'un signal MIDI par un Raspberry Pi Pico.
'''
Réception d'un signal MIDI par un Raspberry Pi Pico.
Lors de la récepion d'un message MIDI "note On" ou "note Off", on affiche
les paramètres (hauteur de la note et vélocité).
Pour plus d'infos:
https://electroniqueamateur.blogspot.com/2025/07/midi-in-avec-le-raspberry-pi-pico.html
'''
import machine
uart = machine.UART(1,31250)
recu = 0
notes = ['DO','DO#','RE','MIb','MI','FA','FA#','SOL','SOL#','LA','SIb','SI']
while True:
if (uart.any()):
message = uart.read(1)[0]
if (message < 0xf8): # pour éviter les messages "system real time"
if (message >= 0x80): #c'est donc une commande
commande = message
else: # c'est un data byte
if (recu == 0): # premier data byte
message1 = message
recu = recu + 1
else: # deuxième data byte
message2 = message
recu = recu + 1
if (recu == 2): # toutes les informations ont été reçues
recu = 0
if ((commande == 0x80) or (commande == 0x90)): # message de type NoteOn ou NoteOff
if (message2 == 0):
OnOuOff = 'NoteOff'
else:
OnOuOff = 'NoteOn'
if (commande == 0x80):
OnOuOff = 'NoteOff'
print('Note: ',message1,' (', notes[message1 % 12],') \t Velocite: ' ,
message2, ' (',OnOuOff,')')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment