Skip to content

Commit 5f70ac7

Browse files
committed
RP2040 USB Host Feather simpletest is now forwards to MIDI UART
1 parent 35e8eee commit 5f70ac7

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

examples/usb_host_midi_simpletest_rp2040usbfeather.py

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
#
33
# SPDX-License-Identifier: Unlicense
44

5-
import audiopwmio
65
import board
6+
import busio
77
import synthio
88
import adafruit_midi
99
import adafruit_usb_host_midi
1010
import usb.core
1111
from adafruit_midi.note_on import NoteOn
1212
from adafruit_midi.note_off import NoteOff
13+
from adafruit_midi.control_change import ControlChange
14+
from adafruit_midi.pitch_bend import PitchBend
1315

1416
print("Looking for midi device")
1517
raw_midi = None
@@ -21,25 +23,17 @@
2123
except ValueError:
2224
continue
2325

24-
# This setup is for pin D4 on Feather RP2040 with USB Type A Host
25-
# You must wire this up yourself to an RC filter and headphones or line in of an amp
26-
audio = audiopwmio.PWMAudioOut(board.D4)
27-
synth = synthio.Synthesizer(sample_rate=22050)
28-
audio.play(synth)
26+
# This setup is to use TX pin on Feather RP2040 with USB Type A Host as MIDI out
27+
# You must wire up the needed resistors and jack yourself
28+
# This will forward all MIDI messages from the device to hardware uart MIDI
29+
uart = busio.UART(rx=board.RX, tx=board.TX, baudrate=31250, timeout=0.001)
2930

30-
midi = adafruit_midi.MIDI(midi_in=raw_midi, in_channel=0)
31+
midi_device = adafruit_midi.MIDI(midi_in=raw_midi, in_channel=0)
32+
midi_uart = adafruit_midi.MIDI(midi_out=uart, midi_in=uart)
3133

32-
pressed = {}
3334

3435
while True:
35-
msg = midi.receive()
36-
if isinstance(msg, NoteOn) and msg.velocity != 0:
37-
note = synthio.Note(synthio.midi_to_hz(msg.note))
38-
print("noteOn: ", msg.note, "vel:", msg.velocity)
39-
synth.press(note)
40-
pressed[msg.note] = note
41-
elif (isinstance(msg,NoteOff) or (isinstance(msg,NoteOn) and msg.velocity==0)) and msg.note in pressed:
42-
print("noteOff:", msg.note, "vel:", msg.velocity)
43-
note = pressed[msg.note]
44-
synth.release(note)
45-
del pressed[msg.note]
36+
msg = midi_device.receive()
37+
if msg:
38+
print("midi msg:",msg)
39+
midi_uart.send(msg)

0 commit comments

Comments
 (0)