You could mistake the MIDI connector for an XLR or PS2 interface. Big, round. Big pins.
XLR DIN3 connectors are for microphones and provide balanced tip, ring and sleeve connections. DIN5 Pins 4 and 5 are added to the 3pins for the MIDI connector hardware. DIN is Deutsches Institut für Normung standards organization.
MIDI uses straight cables from MIDI OUT to MIDI IN. Check labels when you make connections and look at pinouts from both the plug and jack sides.
The signal from MIDI OUT is connected to MIDI IN. Only pins 4 and 5 carry a MIDI digital signal. Grounds are often not connected. MIDI THRU is an optically isolated repeat of the MIDI IN signal.
MIDI Musical Instrument Digital InterfaceSynthesizers were around in the 1970s, automating synthesizers, recording devices and lighting systems. The MIDI organization created a digital music format that is still around today. If you have an electronic keyboard look for the DIN5 connector. It works on USB.
Olimex and Sparkfun ShieldsLook at the schematic for the Olimex shield. Locate the DIN5 connectors on your shield. Look for a programming enable switch in the middle of the board. There may be buttons on your version.
Our sketch sends a serial signal on our UART transmit data circuit. This is digital IO pin D1 on the Arduino board. This lead goes through a resistor to MIDI OUT pin 4 and will sink current from the Arduino board through pin5.
The MIDI in signal on pins 4 and 5 blink an LED for optical isolation. The LED is inside an integrated circuit so we cannot see it. Optical isolation means the signal from one device does not risk electrical hazards.
The programming enable switch controls access to the UART receive data signal.
MIDI THRUOptional circuit. MIDI THRU is an optically isolated repeat of the MIDI IN signal. Signal available when there is an input and board is powered. Low latency that allows multiple connections. Often looped to input of next device.
Open a new sketch and insert the code below. It is an attachment to this project. No library needs to be added, we are using the basic serial interface included in Arduino. The sketch works on both Olimex and Sparkfun shields.
/* 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
}
UploadThe shield has a programming enable switch. Look for PROG/RUN or ON/OFF. This shares the UART Tx and Rx leads between avrdude programming and MIDI output.
Leaving on program setting does not affect MIDI output. Select the upload port in the IDE. Upload and built-in LED blinks to verify flash programming.
Signal TestAt this point you want to prove the signal is coming out the DIN5 connector labelled OUT on the MIDI shield. Pin 5 is +5Volts DC from the Arduino board, connector pin4 is the Tx lead from Arduino board pinD1.
Solder or twist together the leads of the diode and a 100ohm resistor. 220ohm will work and produce a dimmer light. A diode with no resistor should be okay for short periods.
We are looking at the MIDI DIN5 connector and pin5 the 5volt lead is on our right. Our LED has a long wire and a short one, the long wire is on the positive side.
MIDI is a format where the lead is pulled positive when idle. Our UART chip on the Uno board will pull the lead to ground when we transmit. Then current will flow through our LED and we see a light.
WaveformStraight from the UART circuits on the Uno board. A budget oscilloscope shows us 5Volt DC with signal going negative at 31500 baud speed.
Connect the signal from the MIDI OUT to the MIDI IN connectors. If you do not have a MIDI cable then loose wires on pin4 and pin5 will work. Add an LED to the MIDI THRU connector. As the sketch runs the LED will blink showing you how the signal from the MIDI IN input is repeated on MIDI THRU. Disconnect signal or power and the LED stops blinking.
MIDI requires a 5volt signal. Boards with 3.3volt logic output too weak a signal. A board may have multiple UART circuits that could be used for MIDI or SoftSerial. Our sketch uses only a small amount of flash storage in our board and could fit on a smaller ATmega8 chip.
What is SoftSerial?We are not using SoftSerial. Our sketch is quite simple. Since we are using our UART for MIDI SoftSerial borrows some of the unused leads to create a software serial circuit that can talk on USB.
The same Uno board with the same MIDI shield can be programmed for many very useful functions as both a musical and electronic instrument. You could write a sketch where you tell the board what notes to play, or you can view MIDI being received.
Next StepsIf you have other MIDI equipment try connecting to the MIDI shield. Sticky connectors can be lubricated to work better.
Look for libraries that will add functionality and provide example sketches. Musical equipment with MIDI is still available new and used.
USB to MIDI adaptor dongles can connect our MIDI shield to a computer.
Comments