MIDI Over Serial With Hairless

If you’re looking for a quick and easy way to implement MIDI control of Arduino, the Hairless MIDI to Serial bridge is a nice option.  It lets you take MIDI messages generated by sequencing like Ableton and route it to your Arduino over the USB port without having to build a separate input MIDI circuit or use a USB to MIDI converter.

 

For this example, I’ll be controlling a little robot arm with a drum stick on the end of it.  It’s got two servos with a pan-tilt bracket for positioning and a clapper solenoid on the end for striking the stick.

 

Here are  few notes on getting MIDI from Ableton (or some other MIDI sequencer) to Arduino using hairless.

First, we’ll start with Ableton.

Screen Shot 2013-11-07 at 1.42.45 PM

I have one track setup with my MIDI pattern.  On the MIDI output,  I’ve  selected “IAC Driver (Bus 1)” and “Channel 1″ (which will be specified in our Arduino code).
if you don’t see these drop downs for specifying the output routing, make sure the “I/O” button on the right  Screen Shot 2013-11-07 at 2.03.14 PM is selected.
The IAC Driver Bus is used for sending MIDI data between programs on a Mac.  You can activate  busses through the “Audio MIDI Setup” under utilities:
Screen Shot 2013-11-07 at 2.07.26 PM

 

We’ll also configure Hairless to receive  MIDI  on this same bus and select the serial port our Arduino is on.
Screen Shot 2013-11-07 at 1.17.56 PM

You’ll need to make sure that Hairless is sending at a baud rate that matches your Arduino as well in the settings panel.

Screen Shot 2013-11-07 at 1.18.15 PM

Now that we have Ableton sending data over Serial, let’s look at how Arduino is handling it.  In this sketch, I’m controlling two servo motors and a solenoid.  I’ll parse the incoming serial data and then call two functions(one for the servos, one for the solenoid)  that control the appropriate outputs when the assigned notes are triggered.  In this case, I’m using Notes 36 & 37 to control the servos and Note 38 to trigger the servo.  The velocity byte of my MIDI message is translated into an angle for the servos and a note on or off command for the solenoid.