This project uses two off-the-shelf Arduino shields to provide a USB and Serial MIDI merge to a single Serial MIDI OUT.
Warning! I strongly recommend using old or second hand equipment for your experiments. I am not responsible for any damage to expensive instruments!
These are the key Arduino tutorials for the main concepts used in this project:
If you are new to Arduino, see the Getting Started pages.
- Arduino Uno
- USB Host 2.0 Shield
- MIDI Shield or alternative MIDI interface (DIY or ready-made)
- MIDI note sources and MIDI sound source.
The main concept is shown above. The USB Host Shield 2.0 provides the USB MIDI functionality acting as a host for USB MIDI controllers. An off-the-shelf MIDI shield provides the 5-pin DIN MIDI IN and OUT functionality. The Arduino does the routing between the two sets of interfaces, using SPI to talk to the USB Host Shield and the built-in serial port (UART) to talk to the MIDI shield.
It is probably worth saying that you can’t just hook up several MIDI IN streams to the same receive port as they would corrupt the individual serial signals if MIDI messages should happen to arrive at the same time. MIDI is meant to be a single current loop, so extra hardware is required to combine MIDI signals properly.
Also, assuming the hardware is placing nicely, software-wise MIDI messages need to be “complete” (as far as I know). So ideally a complete MIDI message would be processed on one interface before a MIDI message from another interface is processed.
Also, at the end of the day, the serial protocol MIDI runs at 31250 bits per second. If you have two full streams going on, there will be latency issues on the output – it can’t run any faster than the specification. USB MIDI can support multiple virtual “streams” over the USB link so a lot more data can be transferred, but when the output is serial port MIDI – that will be the limiting factor.
Of course, this also assumes that the Arduino can keep up processing the USB host functionality at the same time as serving several MIDI interfaces. If you start seeing limitations there are probably other (faster, more powerful) microcontrollers you could consider too (such as SAMD based ones, or possibly the Raspberry Pi Pico).
This code requires three libraries:
- The Arduino MIDI Library – https://github.com/FortySevenEffects/arduino_midi_library.
- The USB Host Shield v2.0 Library – https://github.com/felis/USB_Host_Shield_2.0.
- The UHS2-MIDI “transport” Library – https://github.com/YuuichiAkagawa/Arduino-UHS2MIDI.
These should all be available via the Arduino’s library manager.
The MIDI library includes a built-in “THRU” capability that will automatically send anything it receives over a MIDI IN port to the corresponding MIDI OUT port. This means that by default anything received on the serial MIDI IN will already appear at the serial MIDI OUT.
Consequently all the code really has to do then is watch the USB MIDI port and copy any received traffic over to the serial port too. Note that I disable the automatic THRU for the USB MIDI port. I don’t want that echoed back over the USB MIDI link by default.
The code is based on the DualMerger.ino example from the MIDI Library combined with the basic example from the UHS2MIDI library.
In the video you can see this merging two keyboard streams, one on channel 1 and one on channel 2, sending them both to my MT-32 sound module.
Once again this is the kind of project that would lend itself to becoming a completely self-contained USB and Serial MIDI merger unit – possibly once again looking at the USB Host Mini Shield and an Arduino Pro Mini.
More complex MIDI routing could be provided as well. Some examples might be:
- Allow either serial or USB as the “out”.
- Allow both serial and USB as an “out” – so all MIDI information received ends up on both interfaces.
- Allow some MIDI filtering – for example, maybe certain channels go one way and other channels go another.
- Combine with a hardware THRU unit so that the same two MIDI IN options could be routed to several MIDI OUT ports.
- Update the hardware to use a Pro Mega 2560 or a Teensy, both of which have several hardware serial ports. This would allow for some very sophisticated MIDI routing indeed.
If you really want to explore the universe of MIDI routing, merging and THRU options, you should take a look at the Teensy-based boards available from Tindie seller deftaudio (although please note I’ve not used any of them myself – they just look like a really neat idea).