Skip to content

Conversation

earlephilhower
Copy link
Owner

Runs arduino_midi_library and MIDIUSB native applications on the RP2040 and RP2350 over USB

@earlephilhower earlephilhower force-pushed the midichlorian branch 2 times, most recently from ddc7d82 to 002004c Compare October 7, 2025 19:54
Runs arduino_midi_library and MIDIUSB native applications on the RP2040
and RP2350 over USB
@earlephilhower earlephilhower merged commit 4e2b030 into master Oct 7, 2025
32 checks passed
@earlephilhower earlephilhower deleted the midichlorian branch October 7, 2025 20:15
@madias123
Copy link
Contributor

Thank you so much for this! I'll test it out when my current projects allow it!

@earlephilhower
Copy link
Owner Author

Cool, thanks. Do open up something with detailed info on reproducing if there's something amiss. I tried the MIDIUSB native output examples and the arduino_midi_library ones and they seemed to play fine when I cut-n-pasted the magic aplay or whatever incantation. But I didn't/don't really know how to test comms in the other way. Everything builds at least

@madias123
Copy link
Contributor

Ok, I did a (no so ) quick try, and I'm missed something:
Installed your branch of MIDIUSB, tried out any example "out of the box" _ > fail.

Works with MIDIUSB and arduino_midi_library as USBMIDI_CREATE_DEFAULT_INSTANCE()

But the library IS a fork of MIDIUSB and there is no "USBMIDI_CREATE_DEFAULT_INSTANCE()"?
Searching for "USBMIDI_CREATE_DEFAULT_INSTANCE()" i found this
https://github.com/lathoub/Arduino-USBMIDI
...another (sub)library fragment not working standalone.

There are TOO many MIDI/ USB MIDI libraries/forks into the wild, so there is no way getting the "right" one.

Ok, mostly I get this error message:

In file included from C:/Users/test/AppData/Local/Arduino15/packages/rp2040/hardware/rp2040/5.3.0/pico-sdk/lib/tinyusb/src/tusb.h:73,
                 from C:\Users\test\AppData\Local\Arduino15\packages\rp2040\hardware\rp2040\5.3.0\cores\rp2040/USB.h:24,
                 from c:\Users\test\Documents\Arduino\libraries\MIDIUSB\src\MIDIUSB.cpp:40:
c:\Users\test\Documents\Arduino\libraries\MIDIUSB\src\MIDIUSB.cpp: In member function 'void MIDI_::interfaceCB(int, uint8_t*, int)':
C:/Users/test/AppData/Local/Arduino15/packages/rp2040/hardware/rp2040/5.3.0/pico-sdk/lib/tinyusb/src/device/usbd.h:312:60: error: 'AUDIO_SUBCLASS_CONTROL' was not declared in this scope
  312 |   9, TUSB_DESC_INTERFACE, _itfnum, 0, 0, TUSB_CLASS_AUDIO, AUDIO_SUBCLASS_CONTROL, AUDIO_FUNC_PROTOCOL_CODE_UNDEF, _stridx,\
      |                                                            ^~~~~~~~~~~~~~~~~~~~~~
c:\Users\test\Documents\Arduino\libraries\MIDIUSB\src\MIDIUSB.cpp:55:9: note: in expansion of macro 'TUD_MIDI_DESC_HEAD'
   55 |         TUD_MIDI_DESC_HEAD((uint8_t)itf, _strID, _cables),

So I'm pretty sure, that I missed one (or more?) dependency /ies ?
Which libraries did you use? (Please include a Github link, as there are far too many with the same name)

Thank you :)

regards Matthias

@earlephilhower
Copy link
Owner Author

Ah, I am not the only one who can't figure out what MIDI library is the right one! 😆

Anyway, the examples in the core itself build and run (as part of CI, in fact) under MIDIUSB.

I also then used arduino_midi_library from FortySevenEffects
https://github.com/FortySevenEffects/arduino_midi_library

arduino_midi_library needs an add'l library to support USB transport. By default a_m_l only has UART-MIDI since that's the lowest common denominator on boards:
https://github.com/lathoub/Arduino-USBMIDI

I hooked up both libs' SinpleSynth modified to use a PWMAudio output so I could just plug in my earbud and verify. Used aconnect and aplay (I think those were the tools) under Linux to find and send a MID file to the USB port and try the receiver.

Re: the compile error, you seem to be building the generic MBED MIDIUSB (c:\Users\test\Documents\Arduino\libraries\MIDIUSB\src\MIDIUSB.cpp:). Please remove it and rebuild. I thought if the library arch matched perfectly then Arduino would pick the core distributed version. In the worst case I'll just buymp the revision # in this MIDIUSB compat library so it always wins on this arch...

@madias123
Copy link
Contributor

ok, I think there are some quirks: I completely deleted your RP2040 core, get rid of all Cache and "staging" files (packages and libraries), reinstalled it via
https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
and again the MIDIUSB is missing after install. I also get rid of the MBED RP2040 core and all other "MIDIUSB" things.
Results: (Github left, Win Explorer right)
image
So i put manually the MIDIUSB @ 9be8b7c
into
C:\Users\test\AppData\Local\Arduino15\packages\rp2040\hardware\rp2040\5.3.0\libraries

Same results as before:

In file included from C:/Users/test/AppData/Local/Arduino15/packages/rp2040/hardware/rp2040/5.3.0/pico-sdk/lib/tinyusb/src/tusb.h:73,
                 from C:\Users\test\AppData\Local\Arduino15\packages\rp2040\hardware\rp2040\5.3.0\cores\rp2040/USB.h:24,
                 from C:\Users\test\AppData\Local\Arduino15\packages\rp2040\hardware\rp2040\5.3.0\libraries\MIDIUSB\src\MIDIUSB.cpp:40:
C:\Users\test\AppData\Local\Arduino15\packages\rp2040\hardware\rp2040\5.3.0\libraries\MIDIUSB\src\MIDIUSB.cpp: In member function 'void MIDI_::interfaceCB(int, uint8_t*, int)':
C:/Users/test/AppData/Local/Arduino15/packages/rp2040/hardware/rp2040/5.3.0/pico-sdk/lib/tinyusb/src/device/usbd.h:312:60: error: 'AUDIO_SUBCLASS_CONTROL' was not declared in this scope
  312 |   9, TUSB_DESC_INTERFACE, _itfnum, 0, 0, TUSB_CLASS_AUDIO, AUDIO_SUBCLASS_CONTROL, AUDIO_FUNC_PROTOCOL_CODE_UNDEF, _stridx,\
      |                                                            ^~~~~~~~~~~~~~~~~~~~~~
C:\Users\test\AppData\Local\Arduino15\packages\rp2040\hardware\rp2040\5.3.0\libraries\MIDIUSB\src\MIDIUSB.cpp:55:9: note: in expansion of macro 'TUD_MIDI_DESC_HEAD'
   55 |         TUD_MIDI_DESC_HEAD((uint8_t)itf, _strID, _cables),
      |         ^~~~~~~~~~~~~~~~~~
C:/Users/test/AppData/Local/Arduino15/packages/rp2040/hardware/rp2040/5.3.0/pico-sdk/lib/tinyusb/src/device/usbd.h:312:84: error: 'AUDIO_FUNC_PROTOCOL_CODE_UNDEF' was not declared in this scope
  312 |   9, TUSB_DESC_INTERFACE, _itfnum, 0, 0, TUSB_CLASS_AUDIO, AUDIO_SUBCLASS_CONTROL, AUDIO_FUNC_PROTOCOL_CODE_UNDEF, _stridx,\

@earlephilhower
Copy link
Owner Author

Well, you've gotten rid of the /home/xxx/Arduino/libraries/MIDIUSB which is good, but you're not running the version with MIDI support turned on.

I have not done an official release w/the change yet, so you need to use the git version of the core. 5.3.0 does not have MIDI turned on in libpico or tinyusb.conf.g

@madias123
Copy link
Contributor

I have not done an official release w/the change yet, so you need to use the git version of the core. 5.3.0 does not have MIDI turned on in libpico or tinyusb.conf.g

ROFL - The dumbest possible mistake on my part?

@madias123
Copy link
Contributor

madias123 commented Oct 10, 2025

Ok, enough for today, after struggling 2 hours around with GIT (especially python!!!!) under windows I got the git version running. Sadly the install manual for GIT won't work (for windows): https://github.com/earlephilhower/arduino-pico#installing-via-git

Ok, it compiles now ok, MIDI IN is working (so I get DATA into the PICO), but no MIDI out (from PICO to PC) - no example would produce a MIDI out event - not even a simple loopback.

@earlephilhower
Copy link
Owner Author

Thanks for giving it a go. Windows makes everything hard, but FWIW git gets better with use. I used to be this guy, but it's been a while since I've needed to start from scratch...

There's a bunch of stuff you need to configure w/the OS before you can get a legit git clone locally, but they should all be documented. If not, please let us know what else you had to do. W/the speed Microsoft is breaking things in Windows 11, it's definitely possible there's some new hoop that wasn't there before.

If you have the exact sketch and any options or apps/settings you used that would be helpful for the Pico-MIDI-out. There's a whole pile of stuff that it looks like you need to configure before getting any kind of MIDI-IN to the PC under Linux and I'm not sure where to start to confirm if the messages aren't being sent from the Pico, or they're being sent but in a wrong format, or the Pico is identifying in a wrong way, etc...

@earlephilhower
Copy link
Owner Author

I just found a simple tester and repro'd the MIDI-OUT issue. It was sending the packets using the wrong call. Using aseqdump -p 20 I was able to see note on/off using the MIDIUSB_write example. As soon as #3196 merges later today you can do a git pull and a git submodule update --init --recursive on your local copy to get the new change.

$ aseqdump -p 20
Waiting for data. Press Ctrl+C to end.
Source  Event                  Ch  Data
 20:0   Note on                 0, note 48, velocity 64
 20:0   Note off                0, note 48, velocity 64
 20:0   Note on                 0, note 48, velocity 64
 20:0   Note off                0, note 48, velocity 64
 20:0   Note on                 0, note 48, velocity 64
 20:0   Note off                0, note 48, velocity 64
 20:0   Note on                 0, note 48, velocity 64
 20:0   Note off                0, note 48, velocity 64
 20:0   Note on                 0, note 48, velocity 64
 20:0   Note off                0, note 48, velocity 64

@madias123
Copy link
Contributor

(deleting all my text, because the error is found) :)
Thank you for your efforts! The good thing with MIDI is: It's a really simple serial protocol with no real magic. If you send and receive a note, you will get everything out of it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants