Last year, while on an all-night-long adventure with my church, one of my over-caffeinated friends came over to me and told me that we needed to make a "really awesome musical instrument with lasers!" I'll put up that project when I'm done but for now, here's how I found out (after much googling) about how to use the Arduino as a MIDI device.
What is MIDI?MIDI (Musical Instrument Digital Interface) is a protocol that uses a series of commands to send musical notes. The most basic command, Note On, sends the name of the note (pitch), the velocity (how hard the note was played), and the channel. MIDI commands are sent over a DIN cable or, more popularly, USB. The benefit of MIDI is that the commands only send the pitch and the velocity, not the type of sound or the volume. This is helpful because you can have a MIDI keyboard that is connected to a computer with a MIDI software and the type of instrument can be customized.
For more info on what were about to do (Please read):
- http://morecatlab.akiba.coocan.jp/lab/index.php/aruino/midi-firmware-for-arduino-uno-moco/?lang=en
- https://www.arduino.cc/en/Hacking/DFUProgramming8U2
- https://www.arduino.cc/en/Hacking/MidiWith8U2Firmware
Before we start, make sure that you have Arduino IDE and MIDI Keyboard (Or any other MIDI app) installed and ready to go.
NOTE: Only the Arduino Uno and the Arduino Mega have a 8u2 (or 16u2)2.0 Flash the ArduinoFollowing the instructions here, flash dualMoco.hex to the Arduino.
Just skip the part "Download updated firmware".
Also, be sure to flash dualMoco.hex to the board!
2.5 Test and set up the ArduinoWhen you plug the Arduino (once the firmware has been changed) you should get a message like "We're setting up the device 'Moco/LUFA'." With the Arduino as a MIDI device, we can't upload code to it with the Arduino
Connect a wire/jumper between pins 4 and 6 on the ICSP header as shown below:
Adding the jumper will set the Arduino back to "normal mode" (So we can upload code to it). Plug it back into your computer and it should now show up as an Arduino. Now we can upload code!
3.0 Upload Code!We will upload a simple code that will play a note on and off.
#include <MIDI.h> // Include MIDI Library
#define C3 48 // Define some notes
MIDI_CREATE_DEFAULT_INSTANCE(); // Create an instance of the midi library
void setup() {
MIDI.begin(MIDI_CHANNEL_OMNI); // Begin MIDI and listen to all channels
}
void loop() {
MIDI.sendNoteOn(C3, 120, 1); // Send note C3 on with a velocity of 120 and on channel 1
delay(500);
MIDI.sendNoteOff(C3, 0, 1);
delay(500);
Next unplug the Arduino and remove the jumper on the ICSP header. Now it is back to "MIDI mode." Now plug the Arduino back into your computer and open your favorite midi app (Something like Garage Band). If all goes correctly, your app should pick up the Arduino as a MIDI instrument and it will start playing C over and over again.
4.0+ Going furtherThe Arduino MIDI Library is very versatile and you can make many different projects with it. (Special thanks to FortySevenEffects!) Just remember that to program your board, you have to add the jumper back to the ICSP!
Comments
Please log in or sign up to comment.