Skip to content

Commit 679c909

Browse files
authored
Merge pull request #2150 from adafruit/midi_friends
Adding code for midi friends learn guide
2 parents b29b64e + fdbf576 commit 679c909

File tree

1 file changed

+39
-0
lines changed
  • QT_Py_RP2040_USB_to_Serial_MIDI_Friends

1 file changed

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

0 commit comments

Comments
 (0)