Advertisement

Electroschematics Projects + Tutorials

MIDI – An Introduction

Advertisement

No MIDI do it yourself electronics projects yet? Don’t worry! This article gives an introduction to MIDI (Musical Instrument Digital Interface), and covers useful details that might help you build your own microcontroller based MIDI projects!

 

MIDI – What You’ll Need to Know?

To get the most out of your projects, you should be familiar with the basics of MIDI. You can go through the following segments of this session to set a good foundation necessary for advanced study.

Advertisement

 

Advertisement

MIDI: The Musical Instrument Digital Interface is a specification for a communication protocol between digital synthesizers and other digital music devices. In principle it’s a communication and control language for musical instruments. Keep in mind that MIDI does not define the nature or timbre of a synthesized sound, but it simply keys out the action of playing the sounds. In a sense, it’s merely a markup language for synthesizers.

 

MIDI Devices: MIDI instruments are generally grouped in to two broad classes – controllers  i.e. devices that make MIDI signals based on human actions, and synthesizers including samplers, sequencers, and so on. The latter accept MIDI data in and create sound, light, or some other effect.

 

MIDI is UART: Needless to say, UART is asynchronous serial data (there’s no clock signal).  MIDI is a specific UART implementation that says the baud rate is 31,250 bits per second to within 1%, and the protocol is 1 start bit, 8 data bits and 1 stop bit. The bytes are either command/status bytes or data bytes. In detail, MIDI bytes are divided up into two types: command/status bytes and data bytes. Command bytes are always 128 or greater (0x80 to 0xFF in hex), while Data bytes are always less than 127 (0x00 to 0x7F in hex). The Commands include things such as note on, note off, pitch bend, etc. while Data bytes include things like the pitch of the note to play, the velocity, or loudness of the note, amount of pitch bend and so forth. Listen, MIDI data is usually set down in hexadecimal (hex) because MIDI banks and instruments are grouped in groups of 16.

 

MIDI Connectors: All MIDI connectors are female! MIDI defines the electrical and physical interface over a 5-pin DIN connector (on a 64Ω cable). The MIDI interface uses three different pin outs which are all defined on the 5-pin DIN connector – MIDI In, MIDI Out, and MIDI Thru.

 

 

Most traditional keyboards and digital pianos have MIDI in and out connectors as standard (look below). It’s possible your keyboard is only a controller, and may only have a MIDI out connector. That’s okay!

 

 

Most MIDI synthesizers are both controllers (the keyboard part) and receivers (the synthesizer part). MIDI devices are joined together in chains (up to 16 receivers per chain), passing the same message along the serial chain. Each will respond to messages sent to its channel, and ignore all other messages.

 

MIDI Cables: MIDI cables use the aforesaid 180º 5-pin DIN connector (the good old 5-pin DIN audio connector) with a single locating lug in the body, but only uses three of those pins.  Pin 2 is wired to the Shield (also known as Screen or Ground) and the other pins are routed straight through. Note that MIDI cables for certain MIDI devices use one or two additional pins for their own intents.

 

 

Want to Build MIDI projects?

Although MIDI at its core is a simple protocol to grasp, there are many facets to it. This session is just enough to give you a few ideas of how you can start making your own MIDI projects. Now note again that MIDI is a 5 volt DC serial communications protocol, operating at 31,250 bits per second. Each byte has 8 bits, plus a start bit and a stop bit. The standard MIDI connector is a 5-pin DIN connector, and usually all MIDI connectors are female, but both ends of a standard MIDI cable are male.

 

In terms of electrical connections, there is a specific wiring scheme for MIDI input and outputs, as we can see here http://www.tigoe.net/pcomp/code/communication/midi

 

MIDI & Arduino: Let me show you how to send MIDI notes from an Arduino Uno board to a MIDI device interfaced via the standard MIDI cable. Since on the Arduino Uno, SoftwareSerial is the best method to communicate with a MIDI sound module like a synthesizer. You can take the same approach to get started with your basic MIDI Note Player experiment(s). Here, you’ll need to use either Serial or SoftwareSerial output, but remember your Arduino Uno has only one serial port, so the “SoftwareSerial” library will be your best choice.

 

This is the proposed hardware setup diagram:

 

 

The MIDI note player sketch prepared for the above hardware setup shows how to use the serial transmit pin (pin 1) to send MIDI note data.  If the final hardware setup is connected to a MIDI synth, it will play the notes F#-0 (0x1E) to F#-5 (0x5A) in sequence. To grab the Arduino Uno sketch, go to https://www.arduino.cc/en/Tutorial/Midi

 

For more details on MIDI protocol, you can go through this detailed MIDI Protocol Guide http://hinton-instruments.co.uk/reference/midi/protocol/index.htm

 

As far as I know, 5-pin DIN connections are no longer used in audio electronics, and hence it’s not easy for me to get the 5-pin DIN connector locally. Luckily I got a pair of them, and this is the photo of my 5-pin DIN connector, I found in a ‘rusty’ scrap box. It works!

 

 

DIY USB MIDI FOOT PEDAL!

Having spent a few hours messing about with running simple MIDI experiments, finally I set up a crude MIDI Note Player based on Arduino Uno, but it’s only a SoftwareSerial approach. So I planned to have another go with a Digispark Attiny85 development board to build a simple USB MIDI Foot Pedal. Then it’d be fairly easy to hook it up with my laptop’s USB port!

 

Hardware: Here’s how I built the usb foot pedal that sends out a note on/off message. Let me start with its hardware setup diagram, and then the software part. The code for the Digispark is really simple and I programmed it from the Arduino IDE. The device has no additional electronics and/or power supply circuitry as it operates and communicates directly through the USB port. That’s pretty much it.

 

 

Software: This pretty simple code is an adaptation of the famous “Adafruit’s USB Foot Switch Controller”, tailored to fit in my Digispark. See, in this code, the onboard LED of Digispark (internally wired to P1) acts as the foot pedal activity indicator. The MIDI channel is 9, note is 89, and velocity is 64.

 

/*

 * USB MIDI FOOT PEDAL V1

 * Digispark Attiny Development Board

 * (Default - 16.5 Mhz)

 * Discrete pedal (only note on/off)!

 * T.K.Hareendran 11/2029

 * www.edn.com

 */




#define USB_CFG_DEVICE_NAME 'm','i','d','i','p','e','d','a','l'

#define USB_CFG_DEVICE_NAME_LEN 9

#include <DigiMIDI.h> // MIDI Library

#define PINLED 1 // Onboard LED P1

#define PINPEDAL 0 // Switch Input P0

#define NOTE 89 // MIDI Note

#define VELO 64 // MIDI Velocity

#define CHAN 9 // MIDI Channel




DigiMIDIDevice midi;

int state = 0;

void setup() {

pinMode(PINPEDAL, INPUT_PULLUP);

pinMode(PINLED, OUTPUT);

midi.sendNoteOff(NOTE, VELO, CHAN);

}

void loop() {

midi.update();

if (digitalRead(PINPEDAL) == 0) {

if (state == 0) {

digitalWrite(PINLED, HIGH);

midi.sendNoteOn(NOTE, VELO, CHAN);

state = 1;

}

} else {

if (state == 1) {

digitalWrite(PINLED, LOW);

midi.sendNoteOff(NOTE, VELO, CHAN);

state = 0;

}

}

midi.delay(100);

}

 

After successful construction, when plugged it into one vacant USB port of my laptop, the USB foot pedal appeared instantly as a “MIDI class device” in my computer – Thanks to “USB Log View”.

 

 

As you may know, USB defines class code information that’s used to identify a device’s functionality and to nominally load a device driver based on that functionality. The information is contained in three bytes with the names Base Class, SubClass, and Protocol. There are two places on a device where class code information can be placed. One place is in the Device Descriptor, and the other is in Interface Descriptors. Some defined class codes are allowed to be used only in a Device Descriptor, others can be used in both Device and Interface Descriptors, and some can only be used in Interface Descriptors. For more details, do refer to this official documentation https://www.usb.org/defined-class-codes.

 

In my case, the base class is “00” and this base class “00h (device)” is defined to be used in Device Descriptors to indicate that class information should be determined from the Interface Descriptors in the device. There is one class code definition in this base class. All other values are reserved. This value is also used in Interface Descriptors to indicate a null class code triple.

 

 

Live Test: Sadly, I don’t have access to any MIDI devices yet, but I may get a chance to borrow one later. I decided to do a ‘blind’ test of my prototype with the pretty great software MIDI-OX installed recently in my Windows7 (Ultimate x64) laptop. Below you can see a screenshot of that successful (and cheerful) experience. Please note, MIDI-OX (http://www.midiox.com) is very new to me!

 

 

As you can see, my foot pedal is registered as a MIDI input device “MidiStomp”!

 

 

Just for the peace of mind, here’s a quick rendition of the MIDI-OX upshot:

 

 

Conclusions – For Now

Throughout this documentation, I got tired and forgot to include more and more MIDI project ideas and design examples. Perhaps, after a couple of weeks I will put them all up. In the mean-time if you want an immediate look at them, just drop me a note here.

 

When I was looking to build a couple of MIDI projects, naturally I began a long Google search. I stumbled across an avalanche of excellent online articles packed with fascinating design ideas. And of course, massive thanks to all respective authors/circuit designers for doing all the hard (and great) work and sharing their insights in the first place – the web world!

 

At last, this primer contains only minimal but useful information to get you started. For an in-depth learning, you may be interested in reading various online guides on MIDI such as:

 

https://blog.landr.com/what-is-midi/

 

www.interfacebus.com/PC_MIDI_Pinout.html

 

https://www.midimountain.com/midi/midi_status.htm

 

https://itp.nyu.edu/physcomp/labs/labs-serial-communication/lab-midi-output-using-an-arduino/

 

0 comments on “MIDI – An Introduction

Leave a Reply