Building an Arduino MIDI Controller
Introduction: Building an Arduino MIDI Controller
This instructable was originally published on my blog on June 28, 2020.
I enjoy building stuff that includes electronics, and I always wanted to build something using Arduino.
One of the most common builds for beginners I found was a MIDI controller. A MIDI controller is any hardware that sends MIDI data (Musical Instrument Digital Interface) to a device to trigger sounds and make music.
I found that many implementations are complicated, even those that are for beginners. It was very frustrating to find I need to use hundreds of lines of unreadable code. Or that I need to solder a resistor in some cases, among other examples.
The Project
By building my own Arduino MIDI Controller, my intention was to make an enjoyable project, keeping the noise at the lowest. Something any beginner could follow. To accomplish that, I used the MIDI Fighter 3D as a base inspiration and removed every non-essential feature.
The total cost of my project was under $30, and the list of materials was really short (affiliate links):
* Arduino Leonardo (or clone): between $10 and $20.
* 16 x Sanwa buttons 24mm (or clone): between $1 and $2.50 per button.
* Soldering Iron
* 22 AWG Electrical Wire
The Arduino Board
When I started this project I found there are a bunch of new Arduino models (not including the hundreds of compatible boards). And all of them offer slightly different capabilities.
I needed to send MIDI signals to a computer and the simplest way to do that is through USB. Any Arduino board based on the ATmega32u4 microcontroller has built-in USB communication.
The official Arduino boards with native USB support are Arduino Due, Arduino Zero, Arduino Leonardo, Arduino Micro. These boards have integrated USB support which means they can act as a USB MIDI device.
I decided to go with a clone of the Arduino Leonardo. It has enough inputs for this project and it also includes headers, which makes it easier to plug/unplug wires.
First Steps
Although I'll explain step-by-step how I implemented the code for this project, you can download the final version.
To upload code to the board you need to use the Arduino IDE. 120
They also have a Web editor that is very useful but they have a limited quota on times per day that you can compile code.
Step 1: Blinking the Built-in LED
It's funny how the "Hello World" in the world of hardware is blinking an LED.
It was a nice surprise for me to discover that Arduino Leonardo has a built-in LED that you can blink to test your code. That way you don't need to build an external circuit on a breadboard with an LED and a resistor.
Code: https://gist.github.com/lean8086/4a4d95c33e937a295...
Step 2: Blinking the LED on Manual Input
The next logical step was to blink the same LED whenever I send a signal. I removed the plastic cover of one end of 2 Dupont wires, and connected the other end to the board:
* Pin number 2: One of the digital inputs (positive). It could be any digital pin.
* Pin GND: Any ground pin (negative).
Now, every time I join the exposed ends of the wires I'm closing the circuit and thus I can execute code in consequence.
Each of the 20 digital pins on the Leonardo has an internal resistor (disconnected by default) that can be enabled using INPUT_PULLUP. Keep in mind that a pull-up input means the button state is inverted:
* HIGH when the circuit is open (button is NOT pressed).
* LOW when the circuit is closed (button is pressed).
Code: https://gist.github.com/lean8086/a61e24e691c4ef188...
Step 3: Installing the MIDIUSB Library
This library allows an Arduino board with USB capabilities to act as a MIDI instrument over USB. Check the official documentation for more info.
Using the Arduino IDE, you can install extra Arduino Libraries using the Library Manager:
1. Open the IDE and click on the "Sketch" menu, then "Include Library", then "Manage Libraries".
2. Search for MIDIUSB and click Install.
3. Once it has finished, an Installed tag should appear next to the MIDIUSB library.
4. Close the Library Manager.
Now the Leonardo can send MIDI messages via USB! But first, some insight about how MIDI works is needed.
How MIDI Works
"MIDI (Musical Instrument Digital Interface) is a standard communication protocol that connects electronic musical instruments, computers, and related audio devices for playing music. 991