Using a Raspberry Pi as USB MIDI Host

February 8, 2016

Wheeeeeeeee! I have some money again, though not a lot of time, but I’m determined to finish and further expand the projects I started with such gusto last year.

Both the Tempest and FS1r are blurred memories, and I’ve been getting my kicks, whenever possible, with a Monomachine/Blofeld Combo.

The great thing about this pairing is that I can sequence 6 channels of Blofeld multimode goodness alongside 5 Monomachine tracks, with the 6th track acting as the FX machine for the Blofeld, which is routed back through the MnM inputs. A nice, self contained, and gloriously digital setup. Did I mention that MnM does killer drum synthesis?


On the the MnM it is possible to input chords using an external MIDI keyboard for the Arps and external sequencing.

I have an cheapo Akai LPK USB mid keyboard that would make a nice compliment to this mini setup. But MnM only accepts 5-pin DIN MIDI. One existing option is the Kenton USB MIDI Host, but that goes for over 100 euro.

I got to thinking that I could use my similarly-abandoned and superseded Raspberry Pi 1, and a MIDI 1×1 USB MIDI cable that never got used because it kept causing bluescreens on my Windows PC. What if I could use the Pi to route the output of the LPK through the 1×1?

Well yes, it’s possible, works perfectly, and is really easy to get running.

Any flavour of linux will do, in my case I’m using a Raspberry Pi v1 with an optimised Raspbian Wheezy image I downloaded from here. I’ve also got this to work on a Rpi2 using the official Ubuntu ARMv7 distro.
The instructions for both are the same.

EDIT: Georgios Says:

By the way, on the latest raspbian, it works out of the box. No need to install anything 🙂

Obviously, with only 2 USB ports on the Pi v1, there is no room for wireless, so I needed to login over ethernet.

Once a command prompt is available, it’s a matter of installing Alsa:

sudo apt-get install alsa alsa-utils

Now connect the *class compliant* MIDI devices, in my case the Akai LPK25 and E-mu USB MIDI 1×1.

To show all connected MIDI devices:

sudo amidi -l

Show connection status and port numbers of connected MIDI devices

sudo aconnect -i -o

Look for the device ID, which is in the format x:0. In my case, the LPK25 was 20:0 and the Emu 1×1 was 16:0. So to connect the output of the LPK to the output of the Emu, just go:

sudo aconnect 20:0 16:0

…and voila! Works a treat here, no latency and I’ve sent boatloads of MIDI through it.

To dump all midi message to the screen,
sudo amidi -d

Naturally, we will want this connection to happen automatically every time we start the Pi. Of the several ways to do this, I opted for the laziest, which was to make a root crontab.
If you’re not root already,

sudo su
crontab -e

at the end of the file, enter the aconnect command that works for you to run at reboot, e.g.

@reboot aconnect 20:0 16:0


24 Responses to “Using a Raspberry Pi as USB MIDI Host”

  1. Do you run it on battrery (for me it would make just any sense for mobile usage of my mini maudio and i.e. my shruti) or similiar? If so, how long does it reach (with the Akai USB Keyboard connected too)?

    • stimresp Says:

      Hi Niels,
      I have not run it off batteries, but I know it is possible with a suitable battery clip. I’m powering it from a USB phone charger.

      The reach is long enough. The Emu interface cable is nearly 2 metres, and the USB cable connecting the LPK25 can be as long as you like.

      I’m already looking at ways to expand this, possibly to offer a USB-CV interface. Rasp Pi model B+ are < 30euro.
      I'm sure there's an even cheaper ay, but I had all the ingredients available, so it was free. Yay!


  2. David Says:

    This is very cool got a few Raspberry Pi’s very first one and a B+ and 2 and 3 of course, I already own a USB Midi Host but still want to try this out, going to see how I could power this via battery 🙂 thank you for this

  3. Rich Says:

    Thanks! I figured this wouldn’t be hard but it’s always nice to get a confirmation before trying.

  4. Paul Says:

    Thank you for your fine work. This was extremely helpful. I am now able to get my OP1 to play nicely with my circuit and organelle. BTW your Tempest guide was masterful.

  5. Georgios Says:

    Thank you so much for sharing this.

    I was thinking to get the Kenton Midi hub but it feels so overpriced for what it does.

    Getting a raspberry pi will do the job on 1/3 of the price, plus you’ll have all that fun with anything else that can be built on top of that.


  6. Daniel Hamilton Says:

    I’m a beginnner at all things Linux but keen to try this out, all I am wondering is if you can use alsa to convert CCs going in to different ccs going out? I’d be looking to convert CC74 to CC01.

  7. Grant M Says:

    Great, thanks! Although having bother getting the frontal to work, the MIDI ports of my devices seem to jump around every time I reboot!

  8. Stéphane A Says:

    Wow this is the best thing I’ve read on the subject so far!
    I want to use a raspberry pi as a midi bridge between devices and wondered if it’s possible to catch the midi input messages and modify them before sending them to the output? I was thinking about doing that with a python program but I don’t know if it can get throug alsa utils to do so.
    Thanks for your great article 🙂

  9. Hi! Thanks for this! I have plans on doing something similar. One question though: was midi channels a factor of the alsa setup? Or did you set the outgoing midi channel directly on the lpk?

  10. Michel Says:

    Great job, thanks! Do you know if is possible to send messages to change the emulate instruments. Thanks in advanced.

  11. Giacecco Says:

    Thanks a lot for these instructions, however they did not work straight away for me for a few reasons:

    a) my MIDI devices change channel number almost every time I reboot the Raspberry Pi

    b) the aconnect command does not create the connection sometimes, and it is not clear why; my current hypothesis is that cron may launch it before alsa is ready, so I delayed it execution by a few seconds, and

    c) I did not need to sudo the commands to make them work, so I use “pi” user’s cron.

    In the end, the command in crontab is:

    @reboot sleep 5 && aconnect $(aconnect -i -o | grep client | grep “some string to identify the sender” | awk ‘{print $2}’):0 $(aconnect -i -o | grep client | grep “some string to identify the receiver” | awk ‘{print $2}’):0

  12. Peter Greco Says:

    This is great! Thank you so much.

    Here’s a solution to the “ports jumping around” problem (same device gets assigned a different number on reboot).

    The ALSA aconnect command lets you specify the client NAME (which doesn’t change from one boot to the next) instead of its number (which sometimes does).

    Example (substitute your client names, of course):

    aconnect microKEY:0 USB Midi Cable:0

    I also created a udev rule which triggers a shutdown of the Raspberry Pi when I unplug the microKEY; this solves the problem of how to turn the RPi off when you don’t have a display or keyboard attached.

    I found the instructions for that here:

  13. Georgios Says:

    I’ve built a small server & web app which can be installed on the Pi for having a GUI to manage the connections:

    I hope you might find it useful!


  14. Julian Says:

    This is great. However, I seem to be having trouble getting it to go two way. Should it work no matter the order that I type in sudo aconnect 20:0 24:0 (in my case, that’s what my Beatstep and MIDI interface are using).

  15. Michel Sandri Lima Says:

    Hi everyone.
    I need some help. I’m using a Yamaha MX (USB-MIDI and MIDI ports) and Casio CDP 120 (USB-MIDI port only). I would like to use the Casio as a controller and the Yamaha as a sound generator but I’m getting no success. Below is the aconnect -l command I get the result below.
    client 0: ‘System’ [type=kernel]
    0 ‘Timer’
    1 ‘Announce’
    client 14: ‘Midi Through ‘ [type=kernel]
    0 ‘Midi Through Port-0’
    client 20: ‘Midi Through ‘ [type=kernel]
    0 ‘Yamaha MX Series MIDI 1’
    Connected From: 24:0
    1 ‘Yamaha MX Series MIDI 1’
    2 ‘Yamaha MX Series MIDI 2’
    3 ‘Yamaha MX Series MIDI 3’
    4 ‘Yamaha MX Series MIDI 4’
    5 ‘Yamaha MX Series MIDI 5’
    client 24: ‘Midi Through ‘ [type=kernel]
    Connected From: 20:0
    Thank you

  16. Ed Says:

    I got it working using the host names instead of the ports and it’s been rock solid! if you are having any difficulties with the command prompt remember to check out the man page for Aconnect. I can also confirm that ALSA seems to be included with Raspbian now, which is pretty rad.


Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: