As a musician who has amassed a collection of musical instruments and noise boxes, the humble Arduino is the perfect tool to build your own MIDI controller. While the Raspberry Pi may have taken the Internet of Things (IoT) crown projects, a simple Arduino Uno ( what are the types of Arduino? ) this project has more than enough power.

First time using Arduino? Don’t worry, we have a complete guide for to read before taking on this project.

arduino-midi-controller-breadboard

What is MIDI?

MIDI stands for Musical Instrument Digital Interface. It describes a standard way for music devices to communicate with each other. If you have an electronic keyboard, you probably have a MIDI interface. While there are a few technical details involved in implementing MIDI, it’s important to remember that MIDI is not audio! MIDI data is a simple set of instructions (one instruction is called a «message») that another device can implement to create different sounds or control parameters.

MIDI supports 16 channels. This means that each cable can support 16 different devices that communicate independently with each other. The devices are connected using a 5-pin DIN cable. DIN stands for German Standards Institute and is simply a cable with five pins inside a connector. USB is often used in place of the 5-pin DIN, or a USB-MIDI interface may be used.

MIDI cable-male

Management change and program change

There are two main types of MIDI messages: control change and program change.

Control Change (CC) messages contain the controller number and a value from 0 to 127. CC messages are often used to change settings such as volume or pitch. Devices that accept MIDI should come with a manual explaining which channels and messages are configured by default and how to change them (called MIDI Mapping).

Program Change messages (PC) are simpler than CC messages. PC messages consist of a single number and are used to change a preset or patch on the device. PC messages are sometimes referred to as «Patch Change». Similar to CC messages, manufacturers must provide a document outlining which presets are changed by a particular message.

What will you need

  • Arduino
  • 5-pin DIN socket
  • 2 x 220 ohm resistors
  • 2 x 10 kΩ resistors
  • 2 x momentary switches
  • Mounting wires
  • mock up
  • MIDI cable
  • MIDI device or USB interface

Construction plan

This project will be pretty simple. Of course, you can add more buttons or hardware to suit your needs. Almost any Arduino will do — only three pins are needed for this example. This project consists of two buttons for program control, a MIDI port for sending data, and a device for receiving messages. This circuit was built on a breadboard here, however it can be moved to the project box and soldered connectors for a solid solution.

Assembly diagram

arduino-midi-controller circuit

MIDI connection

MIDI Pinout

Connect your MIDI connector as follows:

  • MIDI pin 5 to transmit Arduino (TX) 1 through 220 ohm resistor
  • MIDI pin 4 to Arduino +5V via 220 ohm resistor
  • MIDI pin 2 for Arduino ground

Connect Button

The buttons work by changing the resistance that the Arduino «sees». The Arduino pin goes through the switch straight to ground ( SHORT ) through a 10 kΩ resistor (the «buck» resistor, ensuring that the value stays low). When the button is pressed, the value seen by the circuit changes to +5V with no resistor ( HIGH ). Arduino can detect this change with the command digital Read (pin) . Connect the buttons to pins 6 and 7 on the Arduino digital input/output (I/O). Connect both buttons:

  • Left side of button to +5V
  • Right side of button to Arduino Ground via 10 kΩ resistor
  • Right side of button to Arduino pin (6 or 7)

MIDI testing

Now that all the hardware is finished, it’s time to test it out. You will need a USB to MIDI interface (many audio interfaces can do this) and a MIDI cable. The MIDI port connected to the breadboard is sending data, so this is the output. Your computer is receiving data, so it’s an input. This project uses the excellent Arduino MIDI v4.2 library from Forty Seven Effects. Once you have installed the library, you can include it in your code by selecting Sketch > Include Library > MIDI .

You will also need a program to monitor incoming MIDI data:

  • MIDI monitor for OS X
  • MIDI-OX for Windows
  • KMidimon for Linux

Connect Arduino to on your computer and download the following test code (don’t forget to select the correct board and port in menu Tools> Fee and Tools> Menu ports ).

#include  #include  #include  #include  #include  MIDI_CREATE_INSTANCE(HardwareSerial,Serial, midiOut); // create a MIDI object called midiOut void setup() { Serial.begin(31250); // setup serial for MIDI } void loop() { midiOut.sendControlChange(56,127,1); // send a MIDI CC -- 56 = note, 127 = velocity, 1 = channel delay(1000); // wait 1 second midiOut.sendProgramChange(12,1); // send a MIDI PC -- 12 = value, 1 = channel delay(1000); // wait 1 second } 

This code will send message to CC, wait 1 second, send message to PC, then wait 1 second indefinitely. If everything is working correctly, you should see a message on your MIDI monitor.

If nothing happens, don’t panic! Try troubleshooting:

  • Make sure all connections are correct
  • Make sure the MIDI port is connected properly — there should be 2 spare pins on the outer edges.
  • Double check that the schema is correct
  • Make sure the circuit is connected to the USB-MIDI interface using a MIDI cable.
  • Make sure your MIDI cable is connected to entrance your USB-MIDI interface.
  • Make Sure the Arduino Has Power
  • Install the correct driver for your USB-MIDI interface

If you have everything more there are problems, it might be worth checking your layout. Sometimes cheap boards can be very inconsistent and low quality — this happened to me while working on this project.

Button testing

Now it’s time to check if the buttons are working properly. Download the following test code. MIDI does not need to be connected to test this part.

 const int buttonOne = 6; // assign button pin to variable const int buttonTwo = 7; // assign button pin to variable void setup() { Serial.begin(9600); // setup serial for text pinMode(buttonOne,INPUT); // setup button as input pinMode(buttonTwo,INPUT); // setup button as input } void loop() { if(digitalRead(buttonOne) == HIGH) { // check button state delay(10); // software de-bounce if(digitalRead(buttonOne) == HIGH) { // check button state again Serial.println("Button One Works!"); // log result delay(250); } } if(digitalRead(buttonTwo) == HIGH) { // check button state delay(10); // software de-bounce if(digitalRead(buttonTwo) == HIGH) { // check button state again Serial.println("Button Two Works!"); // log result delay(250); } } } 

Run this code (but don’t unplug the USB cable) and open the serial monitor ( top right > Serial Monitor ). When you click the button, you should see «Button One Works!» Or «Button Two Works!» Depending on the pressed button.

There is one important point to take away from this example — software de-bounce. This is a simple delay of 10 milliseconds (ms) between checking the button and rechecking the button. This improves button press accuracy and helps prevent noise triggering the Arduino. You do not need to do this, although it is recommended.

Creating a controller

Now that everything is connected and working, it’s time to assemble the complete controller.

In this example, a separate CC message will be sent for each button pressed. I use this to control Ableton Live 9.6 on OS X. The code is similar to both test cases above.

 #include  #include  #include  #include  #include  const int buttonOne = 6; // assign button pin to variable const int buttonTwo = 7; // assign button pin to variable MIDI_CREATE_INSTANCE(HardwareSerial,Serial, midiOut); // create a MIDI object called midiOut void setup() { pinMode(buttonOne,INPUT); // setup button as input pinMode(buttonTwo,INPUT); // setup button as input Serial.begin(31250); // setup MIDI output } void loop() { if(digitalRead(buttonOne) == HIGH) { // check button state delay(10); // software de-bounce if(digitalRead(buttonOne) == HIGH) { // check button state again midiOut.sendControlChange(56,127,1); // send a MIDI CC -- 56 = note, 127 = velocity, 1 = channel delay(250); } } if(digitalRead(buttonTwo) == HIGH) { // check button state delay(10); // software de-bounce if(digitalRead(buttonTwo) == HIGH) { // check button state again midiOut.sendControlChange(42,127,1); // send a MIDI CC -- 42 = note, 127 = velocity, 1 = channel delay(250); } } } 

Note. You will not be able to use Serial.println() with MIDI output.
If you want to send a message to PC instead of CC just replace:

 midiOut.sendControlChange(42,127,1); 

FROM:

 midiOut.sendProgramChange(value, channel); 

In battle

Below is a demo as a controller for Ableton Live (Best DJ software for any budget DJ software for any budget). Top right shows audio meters and top middle shows incoming midi messages (via MIDI Monitor in OS X)

Have you made a MIDI controller?

There are many practical uses for a custom MIDI controller. You can build a huge foot-operated unit or an elegant studio controller. And if you’re interested in buying one, here are the best USB MIDI controllers. you can buy.

Image courtesy of Keith Gentry via Shutterstock.com

Похожие записи