Patrick Fitzgerald
Published © GPL3+

Arduino MIDI Shields from Olimex and Sparkfun

Simple sketch for Uno to generate musical notes on MIDI shield DIN5 OUT connector. Olimex and Sparkfun both supported.

IntermediateProtip2 hours436

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
SparkFun MIDI Shield
SparkFun MIDI Shield
×1
Olimex MIDI Shield
×1
LED (generic)
LED (generic)
×1
Resistor 100 ohm
Resistor 100 ohm
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

MIDIabc.ino

Arduino
/* sketch uses https://www.olimex.com/Products/Duino/Shields/SHIELD-MIDI/open-source-hardware
* Arduino Uno works on both Olimex and Sparkfun MIDI shields
* simple loop sends MIDI notes on-off ABC pause
* board needs 5volts IO for MIDI. 3v too low
*/
/* sketch uses  
* https://www.olimex.com/Products/Duino/Shields/SHIELD-MIDI/open-source-hardware
*  Uno works on both Olimex and Sparkfun MIDI shields
*  simple loop sends MIDI notes on-off ABC pause 
*  board needs 5volts IO for MIDI.  3v too low
*/
const int ledPin1 =  13;       // built-in LED pin
void setup()  
{  
  pinMode(ledPin1, OUTPUT);    // initialize LED pin
  Serial.begin(31250);  // Select MIDI standard baud rate
 }
void loop() {  
  digitalWrite(ledPin1, HIGH);  // built-in LED on
      // Note A
      Serial.write(0x90);  // Note On at channel 0 
      Serial.write(0x39);  // Note A from the Low octave
      Serial.write(0x50);  // Velocity 80
      delay(250);
      Serial.write(0x80);  // Note Off at channel 0 
      Serial.write(0x39);  // Note A from the Low octave
      Serial.write(0x50);  // Velocity 80
      delay(250);
      // Note B 
      Serial.write(0x90);  // Note On at channel 0 
      Serial.write(0x3B);  // Note B from the Low octave
      Serial.write(0x50);  // Velocity 80
      delay(250);
      Serial.write(0x80);  // Note Off at channel 0 
      Serial.write(0x3B);  // Note B from the Low octave
      Serial.write(0x50);  // Velocity 80
      delay(250);
      // Note C
      Serial.write(0x90);  // Note On at channel 0 
      Serial.write(0x3C);  // Note middle C
      Serial.write(0x50);  // Velocity 80
      delay(250);
      Serial.write(0x80);  // Note Off at channel 0 
      Serial.write(0x3C);  // Note middle C 
      Serial.write(0x50);  // Velocity 80
      delay(250);

      delay(250);
// bab
  digitalWrite(ledPin1, LOW);   // built-in LED off
      // Note B 
      Serial.write(0x90);  // Note On at channel 0 
      Serial.write(0x3B);  // Note B from the Low octave
      Serial.write(0x50);  // Velocity 80
      delay(250);
      Serial.write(0x80);  // Note Off at channel 0 
      Serial.write(0x3B);  // Note B from the Low octave
      Serial.write(0x50);  // Velocity 80
      delay(250);
      // Note A
      Serial.write(0x90);  // Note On at channel 0 
      Serial.write(0x39);  // Note A from the Low octave
      Serial.write(0x50);  // Velocity 80
      delay(250);
      Serial.write(0x80);  // Note Off at channel 0 
      Serial.write(0x39);  // Note A from the Low octave
      Serial.write(0x50);  // Velocity 80
      delay(250);
      // Note B 
      Serial.write(0x90);  // Note On at channel 0 
      Serial.write(0x3B);  // Note B from the Low octave
      Serial.write(0x50);  // Velocity 80
      delay(250);
      Serial.write(0x80);  // Note Off at channel 0 
      Serial.write(0x3B);  // Note B from the Low octave
      Serial.write(0x50);  // Velocity 80
      delay(250);

      delay(750);
      
      Serial.flush();      // Clear the buffers 
}

MIDI Note Numbers

Plain text
text file listing a few octaves of MIDI note values
MIDI   note#   note
0x35   note 53   f3
0x36   note 54   f#3
0x37   note 55   g3
0x38   note 56   g#3
0x39   note 57   a3
0x3A   note 58   a#3
0x3B   note 59   b3
0x3C   note 60   c4
0x3D   note 61   c#4
0x3E   note 62   d4
0x3F   note 63   d#4
0x40   note 64   e4
0x41   note 65   f4
0x42   note 66   f#4
0x43   note 67   g4
0x44   note 68   g#4
0x45   note 69   a4
0x46   note 70   a#4
0x47   note 71   b4
0x48   note 72   c5
0x49   note 73   c#5
0x4A   note 74   d5
0x4B   note 75   d#5
0x4C   note 76   e5
0x4D   note 77   e5
0x4E   note 78   e#5
0x4F   note 79   g5
0x50   note 80   g#5

MIDIarray.ino

Arduino
Arduino sketch that sends MIDI messages. An array stores note numbers to play once.
/* test midi - octaves of notes in array  */
const int ledPin1 =  13;       // built-in LED pin
int array[] = {0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50  /* */ };
int size = sizeof(array);
void setup()
{
  pinMode(ledPin1, OUTPUT);    // initialize LED pin
  digitalWrite(ledPin1, LOW);  // built-in LED off
  Serial.begin(31250);  // Select MIDI standard baud rate
  digitalWrite(ledPin1, HIGH);  // built-in LED on
  for (int i = 0; i < size; i++) {
    Serial.write(0x90);  // Note On at channel 0
    Serial.write(array[i]);  // Note A from the Low octave
    Serial.write(0x50);  // Velocity 80
    delay(250);
    Serial.write(0x80);  // Note On at channel 0
    Serial.write(array[i]);  // Note A from the Low octave
    Serial.write(0x50);  // Velocity 80
    Serial.flush();      // Clear the buffers
  }
}
void loop() {}

Credits

Patrick Fitzgerald

Patrick Fitzgerald

114 projects • 38 followers

Comments