USB MIDI Servo Control In 23 Lines Of Code

 
Description:

MIDI control is a well worn street. People have been using it to talk to computers and microcontrollers since the 1980s.

So why get excited over being able to control something in 23 lines of code?

Because, this was my first attempt at MIDI control, and I was able to have a example up and running in less than 30minutes. What I'm trying to stress is just how easy it was.

What really made it easy was that all the hard work was done by PJRC with the Teensyduino software add-on. Which integrates into the Arduino development environment. All the complex parts of making a USB MIDI device have been done in the background. All that is left for the application developer to do is write the code to make it do what is wanted.

This project uses a Teensy USB Development Board. It is programmed to respond to note-on/note-off events on MIDI channel 1.

Another reason to get excited about it is that, as many people have known for the past few decades, there is a ton of midi software freely available and doing choreographed movements via MIDI is as easy as playing notes on a keyboard.

WARNING: since the servo in this schematic is running from the USB port with its 5V 500ma limit, I would not advise putting any sort of load on the servo.

 
Schematic:

Image developed using Fritzing.

 
Source:
 
Notes:

With the software and schematic above the Teensy will respond to Note-on and Note-off midi commands.

When a note-on is received it is scaled to a range of about 0 to 180. The numbers I chose above are based on the midi keyboard I was using at the time. Its lowest note was MIDI note #36

At the same time a note is received and the servo is moved to a new position, a LED is triggered whose brightness is set by the note velocity. The LED turns off when a Note-off MIDI event is received.

 
Software License:

Numerous files are used to create the code for the Teensy and Teensyduino. Please see their respective licenses.

The 23 lines of code above are Copyright (c) 2011 James Delaney

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Copyright © 2009 James Delaney