I want to connect a MIDI keyboard (oxygen) to a pico, to use the keys and knobs as controllers to other functions on the pico.
Connected directly via USB using an OTG-adapter, i.e
Oxygen - USB-B USB-A cable - OTG - Pico
I'm powering with 5V to vbus on pico, which then also powers the Oxygen via usb (Looks like it's working fine on oxygen. And I have used similar setup to read a USB memory stick on another Pico running C++ code, which works fine)
Using CircuitPython, with the example code that looks very simple and straight-forward (below), but I'm not getting any messages on MIDI in, only "None".
Any idea on what I'm missing here?
The example code used: (Note, I have replaced the "print" statement with writing to a terminal via UART, works fine.
import usb_midi
import adafruit_midi
from adafruit_midi.note_on import NoteOn
from adafruit_midi.note_off import NoteOff
midi = adafruit_midi.MIDI(midi_in=usb_midi.ports[0], in_channel=0)
while True:
msg = midi.receive()
if msg is not None:
print("Received:", msg)
if isinstance(msg, NoteOn):
print(f"Note On: {msg.note}")
elif isinstance(msg, NoteOff):
print(f"Note Off: {msg.note}")
Updated with some additional info:
Tried connecting both the oxygen and pico to a PC, and have the PC "resend" all MIDI messages, and then the pico could read them. So, a missing USB host in the setup, I assumed. Then tried setting up a USB_host according to docs, and then I could see the oxygen as device. But since it seems only possible to set that up on GPIO pins, how do I address that (USB_host) port when setting up the MIDI connection in adafruit_midi.MIDI(midi_in=???)
And, will it work?