In 1982, Hayes released the 1200 baud modem, Microsoft released MS-DOS 1.25, and the Musical Instrument Digital Interface (MIDI) was announced in Keyboard magazine by Robert Moog with its first implementation in the Sequential Prophet-600 synthesizer.

While these days you’re unlikely to use a 1200 baud modem or early MS-DOS, you can still use MIDI to hook up the Prophet-600 to new equipment currently being sold. Even in 2020, few manufacturers would consider producing anything but a novelty synthesizer or drum machine without MIDI connectivity. Digital standards that can compare to this amazing 38 years of mainstream success are few and far between.

MIDI is a robust and easy-to-understand protocol. Simple messages are sent and received without handshakes or acknowledgments. While slow by today’s standards, for the purpose of sending musical information it still functions effectively for all but the most exotic applications. Given the speeds of modern microcontrollers, building MIDI devices is easy, cheap, and extremely satisfying. A quick perusal of the Tindie marketplace for MIDI devices underscores the creative ideas that continue to explode in the maker community.

Makers can also gain access to the universe of MIDI control surfaces. Grid controllers, slider and knob boxes, drum machines, and even wind controllers that output MIDI can become parts of projects that may have nothing to do with music. Capturing and repurposing their messages is a simple matter of programming. To understand what this would take, let’s look closer at the standard itself.

How It Works

MIDI combines a messaging standard, a digital protocol for sending those messages, and a physical scheme for how to wire systems together. This article will focus on the “classic” MIDI standard that uses 5-pin DIN plugs, and sometimes ⅛” (3.5mm) tip-ring-sleeve (TRS) plugs, with a current loop connection scheme. MIDI has also become popular over USB, but that’s an approach for another article.

Starting with the physical side of things, MIDI uses unidirectional current loop networking. This means that sending 1s and 0s is done with changes in current rather than voltage. The MIDI standard limits the current loop signals to 5mA and 5V, so realistically runs of MIDI cable can easily be 20 feet, and can more than double that with high quality cables. MIDI also uses a common current loop technique of opto-isolating the receiving system to prevent ground loops and voltage spikes. MIDI circuits are defined as MIDI IN, MIDI OUT and MIDI THRU. OUT and THRU differ only in that THRU is wired to IN and sends along whatever is received.

This ability to “chain” MIDI devices is one of the great features MIDI users enjoy.

While wiring MIDI circuits is straightforward, multiple vendors produce inexpensive MIDI shields for Arduino (usable as breakout boards for other microcontrollers). These boards typically provide standard serial I/O connections for the host controller and include the opto-isolator and DIN plugs.

Moving up from the physical, MIDI operates at 31250 baud. This value has often frustrated users since it is, to say the least, uncommon to find it implemented outside of MIDI. In actuality, its origins make perfect sense. The first MIDI implementations commonly used the outstanding Intel 8051 microcontroller. The 8051, at least in 1982, used an external XTAL oscillator with 12MHz as the fastest supported value. Internally, it divided that signal by 12 to derive a 1MHZ timer clock. If you divide 1MHz by 32 (2⁵), you get 31,250!

MIDI Messages

MIDI encodes its messages into a status byte which describes the type of message, followed by up to two data bytes. Each data frame has a start bit (value 0,) and a stop bit (value 1,) for a total length of ten bits per byte sent. Status bytes have a 1 as the most significant bit (MSB) and data bytes have a 0 as the MSB.

Messages can be channel messages which are targeted at one of the 16 channels MIDI supports (types: channel voice, channel mode) or system messages received by all devices (types: system common, system real-time, and system exclusive.) Channel messages encode the message type onto the three bits following the MSB and the target channel onto the 4 Least Significant Bits (LSB) of the status byte. Data bytes encode their payload onto the 7 bits following the MSB.

A full description of all the different MIDI messages is beyond the scope of this article, but it’s worth looking at a couple of common messages. Let’s say we want to send a message to a synthesizer on channel 4 to turn on the note C3. (Having 7 bits to encode note number means that MIDI has a range of 127 notes, from C-1 to G9.) We’d send a status byte with the channel and message type, a data byte with the note number and a second data byte with the velocity (the force with which the note is played). If we wanted to change the value of a parameter, such as the modulation wheel, then we’d send a status byte, a data byte with the controller number, and a data byte with the controller value we want to set.

Building Projects

Much like deciding to use a MIDI shield instead of wiring your own interface, using MIDI libraries like the one from FortySevenEffects makes it extremely easy to handle all the technical details of sending and receiving messages. Once messages are received, a case structure or chain of if statements selects the desired logic to implement. Sending messages requires only a single command.

Advanced MIDI messaging such as MIDI timing/clock and System Exclusive (sysex) are all supported in the FortySevenEffects library. But fantastic MIDI projects may only need to use a couple of messages like NoteOn and NoteOff or a small set of ControlChange messages. Just ignore any messages that you aren’t interested in.

Any sensor you can attach to a microcontroller can become a substitute for the keys or controls of a synth or the pads of a drum machine. Simple sketches can transpose notes, create arpeggiations, reroute messages, or any other operation you can perform on MIDI’s messages.

In 2019, MIDI 2.0 was announced, assuring the future of the standard. The new standard will be backward compatible and support existing MIDI devices, assuring the viability of maker MIDI projects for a long time to come.


Building BooshBeats

 

Who doesn’t love a grid of pads with RGB LEDs? When I needed to create an 8-channel × 8-step sequencer for my mega-flame effect BooshBeats.

An Arduino sequencer using Novation Launchpad Pro

I used MIDI to talk back and forth with a Novation Launchpad Pro. Button presses came as MIDI messages in, and I could control the colors of the pads with MIDI messages out. The Launchpad grid visually displays the pattern, and lets me edit existing and create new patterns, even while playing! I use the top, bottom, and left buttons to start, stop, retrieve, and store patterns. The right side buttons are used as displays to show the sequencer walking through the steps.

Learn more about MIDI

Midi.org

Sparkfun