introduction

midi interfaces

This project is an introduction to physical interfaces for working with digital processes, with a focus on sculptural, critical, and experimental approaches to musical instrument and interaction design. We will use a low cost microcontroller, the Pro Micro, and standard MIDI messages to communicate between the physical world of movement and matter and the digital world of voltage and computation.

A microcontroller takes information from sensors and lets you map these inputs to processes and events on a computer. It can also be used to send messages from the computer to control things in the physical world, like lights, relays, and small motors.

While buttons, dials, and sliders are commonly used sensors, but you could also use photocells (which measure light), FSRs (pressure), and conductive thread (which measures capacitance, or touch), among others. While MIDI is commonly used in musical instruments, it is a standard communication protocol that can be used in interactive installations, live performances, and kinetic sculptures. MIDI messages can be mapped to a broad range of software — Max, Ableton, Reaper, Mad Mapper, Processing — any program with MIDI input/output.

Image result for midi logo

MIDI stands for Musical Instrument Digital Interface. It’s a protocol that was developed in the early 1980’s as a way to connect music devices, but it is fast and reliable and now works with a lot of different software environments. While MIDI is lower resolution compared to serial communication, it gets everything talking quickly and provides enough flexibility for most projects.

We are using the Pro Micro microcontrollers because they can be easily configured as class-compliant MIDI devices. When you plug it in, your computer automatically recognizes the interface as a midi device, and it can immediately be mapped to whatever program you are working with.

set up

(note that clicking on an image with open a larger version of the image in a new tab, easier to see!)

The starter code below is written with 2 digital inputs, 2 analog inputs, and 1 digital output, but you can change a few lines to the code to add, subtract, or change pin allocations. You can download the starter code here, or just paste the code below into an arduino sketch…

#include <Control_Surface.h> // Include the Control Surface library

USBMIDI_Interface midi; // Instantiate a MIDI over USB interface.

// Instantiate an array of NoteButton objects that send
// MIDI note events when a push button or toggle is pressed/released
NoteButton buttons[]{
{5, MIDI_Notes::C(4)}, // Push button on pin 5
{6, MIDI_Notes::D(4)}, // Toggle switch on pin 6
};

// Instantiate an array of CCPotentiometer objects that send
// MIDI CC messages when an analog sensor is changed (0-127)
CCPotentiometer potentiometers[]{
{ A0, 16}, // Analog pin (A0) connected to potentiometer, midi controller number (16)
{ A1, 17}, // Analog pin (A1)connected to light dependant resistor (LDR), midi ontroller number (17)}
};

// Instantiate an array of NoteLED objects that receive midi note events from the
// computer to turn LEDs on and off on the microcontroller
NoteLED leds[]{
{9, MIDI_Notes::E(4)}, // pin 9: LED output (midi note E4 or 64)
};

void setup() {
Control_Surface.begin(); // Initialize Control Surface
}

void loop() {
Control_Surface.loop(); // Update the Control Surface
}


digital inputs

Digital inputs send a binary signal to the computer, which we can think of as ON or OFF. Digital Inputs are good for triggering events (like a sound or video file) or playing a key (like on a keyboard) or changing the state of something.  Here we will connect a pushbutton and a switch, the most common types of digital inputs.

This picture above shows how to a momentary button. The button pictured above is a pretty standard button with two legs, but buttons and switches come in all kinds of shapes and forms — the connection method remains the same! Because the button is simply making and breaking a connection, it doesn’t matter which wire goes to which leg. Just attach one leg to ground (GND) and one leg to pin 5. Here is what the code looks like for a digital input…

// Instantiate an array of NoteButton objects that send 
// MIDI note events when a push button or toggle is pressed/released 
NoteButton buttons[]{ 
{5, MIDI_Notes::C(4)}, // Push button on pin 5 
{6, MIDI_Notes::D(4)}, // Toggle switch on pin 6 
};

In the code, first we create a NoteButton object and then we say that we are going to create a bunch of them by creating a button array — buttons[]. All of this initial code will stay the same, regardless of how many buttons, switches, or other digital inputs you add! On the next line we specify a pin number, 5, and tell the arduino what to do when pin 5 is connected to ground, meaning the button is pressed. In this case, the arduino sends a message to play MIDI note C4. So, if you have a midi track enabled in a DAW, you will hear note C4. In Max, you can use this note information to play a note, but you can also use it to start a process or to turn something on and off!

This next example shows how to connect a button and a toggle switch, both digital inputs. Note that the toggle switch has 3 legs, not two like the button. By toggling the switch back and forth, you are connecting the middle leg to one or the other outer legs. So, when you connect a toggle switch, connect one wire to the middle leg and one wire to one of the outside legs. Also, not that instead of connecting both components directed to ground, I have connected the ground legs together, so that I only need to connect to ground on the board once!

The code above works with both of these digital inputs — the outer leg of the toggle switch is connected to pin 6, and the middle leg is connected to ground through the ground leg on the button. Try to add more digital inputs to your interface. Also try other kinds of digital switches — tilt switches are fun, but you could also simply connect and disconnect the two wires, allowing for all kinds of sculptural possibilities.

analog inputs

Unlike Digital Inputs which only transmit two values (On and Off, or High and Low), Analog Inputs are continuous sensors that send a range of values. Analog inputs are great for variable control of parameters like speed, volume, or saturation.  The picture below shows how to connect a potentiometer and a photocell, typical Analog Inputs. There are a ton of different types of analog inputs. Some of the more complicated sensors are difficult to connect and use over MIDI, but the majority of analog sensors will work. For more detail, see the Analog Input tutorial on the Teensy website (or search for any of the million arduino resources on the topic).

A potentiometer is a variable resistor that usually has three legs. Connect one outer leg to power and the other to ground. The middle leg connects to an Analog Input Pin, in this case A0. Here is the code for using an Analog input…

// Instantiate an array of CCPotentiometer objects that send 
// MIDI CC messages when an analog sensor is changed (0-127) 
CCPotentiometer potentiometers[]{ 
{ A0, 16}, // Analog pin (A0) connected to potentiometer, midi controller number (16) 
{ A1, 17}, // Analog pin (A1)connected to light dependant resistor (LDR), midi ontroller number (17)} 
};

Once again, we start by creating an object, this time it’s called CCPotentiometer and then we create a bunch of them by creating an array of potentiometers. Again, this initial code will stay the same, regardless of how many analog inputs you add! On the next line we specify a pin number, A0, and then tell the arduino what channel to send information on, in this case 16. So the arduino will send Midi control messages– a range of messages between 0-127, on channel 16.

The photocell does require a 10K resistor, which connects one of the legs to ground. The other leg is connected to  power  and the leg with the resistor is also connected to an Analog Input Pin, in this case A1. Now both of them together…

digital outputs

Connect the Anode (+) or longer leg of the LED to one of your digital output pins — in this case Pin 9. Connect the shorter, or cathode, leg to ground through a 220Ω resistor (red red brown gold).

If you play the MIDI note associated with pin 9, the pin is turned on, or set to HIGH, and will send 3.3v through the LED and the resistor, completing the circuit to ground. Your LED should turn on! Let’s look at the code…

// Instantiate an array of NoteLED objects that receive midi note events from the 
// computer to turn LEDs on and off on the microcontroller 
NoteLED leds[]{ 
{9, MIDI_Notes::E(4)}, // pin 9: LED output (midi note E4 or 64) 
};

Create a NoteLED object and set up an array, leds[]. The array lets you easily add more leds if you want. Next specify the pin (9) and the MIDI note that the pin responds to, note E4.

You can use a similar setup to drive a small motor. Connect one leg of the motor (it really doesn’t matter which leg in this case) to power (red) and the other leg to ground through a 10K resistor. You won’t be able to control the speed of the motor, but you’ll be able to turn it on and off from your computer by sending a MIDI note.

reading

Laetitia Sonami has been building new musical instruments for decades and she has so many interesting thoughts about control and interfacing:

George Lewis is a trombonist and composer who has been improvising with machines for decades as well. His work focuses more on the algorithmic/software side of things, but his ideas still apply to thinking about different paradigms of control and expression as they play out in the interface.

The New Instruments for Musical Expression, or NIME, conference has been the academic hub exploring expressive interfaces for a few decades now. There are many wonderful papers on specific and general topics related to sound and interaction. If there is sometime specific you are looking for, I recommend using your browser’s seach function.

The Guthman Musical Instrument Competition is another place where music and microcontrollers converge in interesting and odd ways. Take a look at the past participants for ideas and inspiration.

Below is an assortment of papers, essays, and books that I have found relevant to this type of work. If you have suggestions / additions, feel free to add them in the comments!