Related projects

 
Arduino MIDI I/O Board

March, 02th 2009
Board overview and connections
A minimal MIDI input/ouput board ready to be connected to your Arduino! The schematic is very simple, I used a single-copper-hole prototyping board to build mine, but a breadboard is also a nice alternative.
Basic MIDI output is really easy to do with Arduino, all you have to do is initialize the serial port using Serial.begin(31250), then you can send standard MIDI data using Serial.print function.
If you don't want to mess too much with low level MIDI data handling you can just use the MIDI Library developed by François Best (see the links on the right), otherwise just read the MIDI protocol specification and start doing your experiments!
To debug your MIDI applications i would suggest MIDI-OX, it's really a great tool... and it's free!


Bill of Materials:
1x Optocoupler 6N137 (OK1)
2x 220 Ohm 1/4 W Resistor (R1,R4)
1x 1.2 KOhm 1/4 W Resistor (R2)
1x 5.6 KOhm 1/4 W Resistor (R3)
1x 1N4148 (D1)
1x IC DIL socket-8Pin (optional, for the 6N137)
1x Male header 2.54mm/0.100" strip (JP1,JP2,JP3)
A simple MIDI example
  1. /*---------------------------------------------------------*/
  2. /*   Simple MIDI example                                   */
  3. /*   Vincenzo Pacella - www.shaduzlabs.com                 */
  4. /*---------------------------------------------------------*/
  5. /*                         DataByte1     Data Byte2        */
  6. /* -------------           ------------  ---------------   */
  7. #define NOTE_OFF    0x80// Key number    Note Off velocity
  8. #define NOTE_ON     0x90// Key number    Note on velocity
  9. #define POLY_KEY_P  0xA0// Key number    Amount of pressure
  10. #define CONTROL_CHG 0xB0// Controller    Controller value
  11. #define PROGRAM_CHG 0xC0// Program num   None
  12. #define PRESSURE_V  0xD0// Pressure val  None            
  13. #define PITCH_BEND  0xE0// MSB           LSB
  14.  
  15. int MIDI_channel = 1;   // [1-16]
  16. int i = 0;
  17.  
  18. void setup() {
  19.   Serial.begin(31250);
  20. }
  21.  
  22. void loop() {
  23.  for(i=0;i<128;i++){
  24.    sendNoteOn(i,127);  //Send a Note ON
  25.    delay(50);
  26.    sendNoteOff(i,0);  //Send a Note OFF
  27.    delay(50);
  28.  }
  29.  for(i;i>0;i--){
  30.    sendNoteOn(i,127);  //Send a Note ON
  31.    delay(50);
  32.    sendNoteOff(i,0);  //Send a Note OFF
  33.    delay(50);
  34.  }
  35. }
  36.  
  37. void sendNoteOn(byte note, byte velocity) {
  38.   sendMidiMessage(NOTE_ON, note, velocity);
  39. }
  40.  
  41. void sendNoteOff(byte note, byte velocity) {
  42.   sendMidiMessage(NOTE_OFF, note, velocity);
  43. }
  44.  
  45. void sendControllerChange(byte controller, byte value) {
  46.   sendMidiMessage(CONTROL_CHG, controller, value);
  47. }
  48.  
  49. void sendMidiMessage(byte message, byte data1, byte data2) {
  50.   Serial.print((MIDI_channel-1)&0x0F|message, BYTE);
  51.   Serial.print(data1, BYTE);
  52.   Serial.print(data2, BYTE);
  53. }