This is a library for creating a MIDI controller using an Arduino board.
It enables you to easily create MIDI controllers or instruments with very few lines of code. It supports digital inputs, like pushbuttons and switches, analog inputs, like faders, potentiometers, light sensors, and rotary encoders, like jogwheels.
The library works on pretty much all Arduino and Teensy boards, like the Arduino Uno, Mega, Zero, Due, Leonardo, Micro, Teensy 3.2, ...
It uses a MIDI-over-USB connection to connect to your computer, and can be used in your favourite DJ or DAW software.
The MIDI Controller library has been obsoleted by its successor, the Control Surface library. |
---|
It has more features, a better architecture, unit tests, continuous integration, clearer documentation, support for more and newer Arduino boards, etc.
It adds support for MIDI input, SysEx, the Mackie Control Universal protocol, VU meters, LEDs, OLED displays, audio over USB, MIDI over Bluetooth, MIDI routing ...
https://github.com/tttapa/Control-Surface
I no longer offer support for the MIDI Controller library, and I won't be adding any new features.
For new projects, it is highly recommended to use the Control Surface library instead of the MIDI Controller library.
Control Surface is well-supported, and new features are added regularly. It completely replaces MIDI Controller.
If you need help porting your existing MIDI Controller project to Control Surface, feel free to open an issue.
Download the latest stable version here.
Please read the installation instructions first.
The library can take input from a variety of analog devices, such as variable resistors, potentiometers, linear faders, light sensors ...
It filters the inputs and applies hysteresis, to get smooth transitions and to reduce noise.
You have full control over the value mapping, control curves, and the range of the inputs.
Accuracy up to 10 bits supported using pitch bend events.
Analog inputs can be mapped to controls like volume, balance, effect parameters, EQ ...
The library can be used with a wide range of digital inputs as well, like pushbuttons, latching switches, footswitches ...
Buttons are debounced and can be inverted if necessary.
Digital inputs can be mapped to controls like transport control (play/pause/stop/cue/... buttons), mute/solo/rec buttons, effect enable/disable, looping options, sample triggers ...
There is support for matrices of buttons as well. This allows you to use a very large number of buttons with only a limited number of IO pins.
Just like with Digital inputs, these buttons can be mapped to controls like transport control (play/pause/stop/cue/... buttons), mute/solo/rec buttons, effect enable/disable, looping options, sample triggers ...
Another way to input continuous values is by using rotary encoders or jog wheels. Unlike potentiometers, they can turn indefinitely, and allow for more precise controls.
The library has many settings for accuracy and speed.
Different MIDI modes are available for compatibility with a huge range of music production, DJ or DAW software.
Rotary encoders can be mapped to controls like volume, balance, effect parameters, EQ, jog wheels, timeline scrolling, library scrolling ...
The library will automatically detect what kind of Arduino-compatible board you are using, and it will use the USB connection for MIDI communication (if available). This means that you can just plug it into your computer or tablet (PC, Mac, Linux, iOS, Android ...), it will be automatically detected as a MIDI device, and you can start playing right away.
If your board doesn't support MIDI over USB, it will default to the Serial USB interface. More information on the MIDI over USB Wiki page.
For maximum flexibility, you can use the MIDI functions to send your own custom MIDI events, without having to worry about compatibility issues between different boards.
The debug mode allows you to print the MIDI events in the serial monitor for easier developing, testing and debugging.
MIDI interfaces on hardware serial ports as well as SoftwareSerial ports are supported as well, to use the controller with MIDI devices that use a 5-pin DIN MIDI connector.
Use analog multiplexers and shift registers to save IO pins. Using the Extended IO classes and the ExtIO namespace, you can treat them as if they were normal input/output pins, without having to worry about the actual implementation.
- Improved filtering
- Header-only rotary encoder classes to remove Encoder.h dependency
- Completely reworked library structure
- Added more MIDI interface options
- Added ButtonMatrix control element
- Added debounce for buttons
- Automatically average analog inputs
- Added Bank and BankSelector classes instead of bank() method per class
- Added files containing constants to use Control Change controller names instead of magic numbers
- Automatically refresh all MIDI Control elements at once
- Added support for analog multiplexers and shift registers using Extended IO classes
- Cleaner and more efficient code
- Bank functionality for rotary encoders
- Minor bug fixes
- Easier access to debug mode using
USBMidiController.begin(baud, true);
- More examples
- Minor bug fixes
To install this library, download the latest version as a .ZIP file. Then open the Arduino IDE, go to Sketch > Include Library > Add .ZIP library, and open the .ZIP file you just downloaded.
The MIDI_controller library depends on the PJRC Encoder library for using rotary encoders and jog wheels. Download the .ZIP library from GitHub and install it.
If you are using an Arduino with native USB support, like the Leonardo, Due, Zero, Micro ... you'll need to install the MIDIUSB library. Install it using the Arduino IDE's library manager (Sketch > Include Library > Manage Libraries). Search for 'MIDIUSB', and install it. Alternatively, download the .ZIP library from GitHub and install it.
If you're using a Teensy board, you have to install the Arduino core for Teensy (aka Teensyduino). Download it here, if you haven't already.
The Arduino Uno and Mega don't have native USB support, so they need extra firmware to be installed to the USB-to-Serial chip in order to work as a MIDI device. To flash this firmware, you have to install a DFU programmer. On Windows, you can use Atmel Flip. On OSX and Linux, install dfu-programmer.
Windows:
Download and install Atmel Flip:
- Download the latest Java Runtime Environment from the Java site.
- Run the java installer.
- Click 'install'.
- Close the installer when finished.
- Download 'Flip' from the Atmel site.
- Run the installer.
- Click 'next'.
- Accept the terms in the License agreement and click 'next'.
- Click 'next'.
- Click 'install'.
- Click 'next' when completed.
- Click 'finished'.
Mac:
sudo port install dfu-programmer
Linux:
sudo apt-get install dfu-programmer
More information can be found here.
Open one of the example sketches, connect your Arduino, select the right port from the Tools menu, and hit upload.
Open one of the example sketches, connect your Teensy, select the right port from the Tools menu, select 'MIDI' (or 'Serial + MIDI') as the USB type, and hit upload.
Open one of the example sketches, connect your Arduino, select the right port from the Tools menu, and hit upload. When the upload is complete, take a ballpoint pen (or anything conductive) and reset the ATmega16U2 by connecting the reset pin of the 6-pin ISP header (next to the USB connector) to ground, as shown in the following picture.
Install the drivers for the ATmega16U2:
- Make sure you have reset the ATmega16U2 to put it in DFU mode (Device Firmware Update). Read more here.
- Go to the Control Panel in Windows. Click 'Hardware and Sound'.
- Under 'Devices and Printers', click 'Device Manager'.
- In Device Manager, there is a category 'Other devices'. In this category, there should be something like 'Arduino Uno DFU' or 'ATmega16U2 DFU'. Right click the device, and select 'Update Driver Software'.
- Choose 'Browse my computer for driver software'
- Then hit 'Browse...' and browse to C:\Program Files\Atmel\Flip 3.4.7\usb in the new window.
- Make sure 'Include subfolders' is checked, then click 'Next'.
- In the Windows Security window that pops up, click 'Install'.
- You should get a notification that Windows has successfully updated the driver software for 'AT90USB162'.
Download the ATmega16U2 firmware:
- Download the Arduino firmware from the Arduino GitHub page: Arduino-usbserial-atmega16u2-Uno-Rev3.hex or Arduino-usbserial-atmega16u2-Mega2560-Rev3.hex
- Download Dimitri Diakopoulos's HIDUINO firmware from his GitHub page: arduino_midi.hex
Flash the MIDI firmware:
- Open the Flip software.
- Hit CTRL+S to select a device, choose 'ATmega16U2', and click 'OK'.
- Hit CTRL+U, and click 'Open' to open the USB connection.
- Hit CTRL+L to load a HEX file.
- Browse to your Downloads folder and load the 'arduino_midi.hex' file you just downloaded.
- Make sure all 4 boxes on the left hand side are checked, and click 'Run'.
- Once this is finished, you can unplug the Arduino. Now it is no longer in DFU mode.
- Go back to the Device Manager, and check if the Arduino shows up as a MIDI device, under 'Sound, video and game controllers'.
- Now your Arduino is a working MIDI controller!
- To upload a new program, just repeat these same steps again, but use the Arduino firmware you downloaded previously.
==TODO==
(probably just transcoding the Linux Bash scripts to OSX Bash)
Go to the folder where you installed this library (usually ~/Arduino/libraries/MIDI_controller) and go to 'DFU scripts/Linux' and open it in a terminal. Then allow execution of the scripts:
chmod +x *
And run the script to flash the MIDI firmware:
./MIDI*
Type 'y' to confirm, and enter your root password if necessary.
The script will download and install the firmware to the Arduino.
When the script is finished, unplug the Arduino and plug it back in: your computer should now recognize it as a MIDI device.
Now that the MIDI firmware is running on the USB-to-Serial converter, you can't upload new sketches to the Arduino.
To upload a new sketch, install the Arduino Serial firmware again: put the Arduino into DFU mode again, by connecting the reset pin to ground, and run the second script in the 'DFU scripts/Linux' folder:
./Serial*
This script will download the Arduino Serial firmware and install it to the Arduino. When it's finished, unplug the Arduino, plug it back in, and upload your new sketch.
Then you can install the MIDI firmware again.
Read more on how different boards use differents methods to send MIDI over USB in the Wiki.
You can find the entire library documentation with a description of all available functions in the Wiki.
In the Wiki, you can also find a page that explains how to connect the hardware, like pusbuttons, potentiometers and rotary encoders.
The library includes a whole lot of example sketches that demonstrate the usage of the library. You can find them under File > Examples > Examples from custom libraries > MIDI Controller or in the examples folder on GitHub.
I have tested this library with an Arduino Uno, an Arduino Leonardo and a Teensy 3.2.
Other users have successfully used the library with an Arduino Mega 2560 and an Arduino Micro.
Boards that use an FTDI USB-to-Serial chip (like the Nano and some older boards) do not support MIDI over USB, but can still use Serial MIDI.
If you try this library with a different board, please let me know whether it works or not. If it doesn't, please open an issue. Thanks!