Skip to content

Commit 29f1587

Browse files
committed
Adding code for midi friends learn guide
Adding code for the USB to Serial midi friends learn guide. Using a pylint ignore for unused-import because the midi libraries are used to recognize the incoming midi messages over USB to send over UART
1 parent b29b64e commit 29f1587

File tree

1 file changed

+36
-0
lines changed
  • QT_Py_RP2040_USB_to_Serial_MIDI_Friends

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import board
2+
import busio
3+
import usb_midi
4+
import adafruit_midi
5+
# pylint: disable=unused-import
6+
from adafruit_midi.control_change import ControlChange
7+
from adafruit_midi.pitch_bend import PitchBend
8+
from adafruit_midi.note_off import NoteOff
9+
from adafruit_midi.note_on import NoteOn
10+
from adafruit_midi.program_change import ProgramChange
11+
12+
# uart setup
13+
uart = busio.UART(board.TX, board.RX, baudrate=31250)
14+
# midi channel setup
15+
midi_in_channel = 1
16+
midi_out_channel = 1
17+
# midi setup
18+
# UART is setup as the input
19+
# USB is setup as the output
20+
midi = adafruit_midi.MIDI(
21+
midi_in=usb_midi.ports[0],
22+
midi_out=uart,
23+
in_channel=(midi_in_channel - 1),
24+
out_channel=(midi_out_channel - 1),
25+
debug=False,
26+
)
27+
28+
while True:
29+
# receive MIDI message over USB
30+
msg = midi.receive()
31+
# if a message is received...
32+
if msg is not None:
33+
# send that message over UART
34+
midi.send(msg)
35+
# print message to REPL for debugging
36+
print(msg)

0 commit comments

Comments
 (0)