Home   |  Schematics |  Products |  Tutorials  |  Datasheets  |  Robotics   |   Download    |   Link Exchange

Direct Current
Alternating Current
Digital Electronics
PC Architecture
Electronics Dictionary

Associations and Societies
Component Manufacturers


Electronics Symentics

Microcontroller Advanced Kit - MIDI Controller

This project shows you how the hardware of a MIDI interface works and goes through some simple examples to show how the controller can be used in MIDI systems. First we will start by explaining the details of the hardware interface. Then we will look at the MIDI protocol and see how simple it is to write custom software for this MIDI controller.

The MIDI Hardware Interface

There are only a couple parts needed to build the MIDI connections. A few resistors, a diode, and a small 8 pin IC and that is it. The controller part of the system is a 2051 microcontroller (a 20 pin version of the popular 8051). The MIDI interface connects to the serial port of the 2051 (pins 2 and 3). The 2051 also has a reset circuit (the 10 uF capacitor and the 8.2k resistor) and an oscillator circuit (the 24 MHz crystal and the two 33 pF capacitors). For more information on the 2051, The only thing not shown is the 5 volt power supply that creates Vcc (5 Volts DC) for the circuit. An LM7805 and 220 uF capacitor is included with the kit to create 5 Volts DC from a 9 to 12 Volt DC source.

6N137 Optoisolator



The 6N137 isolates one electrical system from another. There is no electrical connection between devices connected by MIDI. When a current flows through the internal LED connected between pins 2 and 3, the LED transmits light to a light detecting diode. The diode is activated and the Output at pin 6 is pulled low by the internal transistor. If no current flows then the Output floats. Rather than let it float, we connect an 8.2k resistor to pin 6 to lightly pull the voltage at the Output to 5 Volts when the circuit in not active. 

Sending a Signal

The microcontroller sends signals through the MIDI port by controlling the voltage at its pin 3. The current is provided by the 5 volts (Vcc) connected to pin 4 of the MIDI Out port. When the MIDI Out port is connected to a MIDI In port of another system the following circuit is created.



If we simplify this circuit a little bit then it looks like the circuit below.

When Pin 3 of the controller goes to 0 volts then a current flows through the circuit making the internal LED in the 6N137 light up. Then when Pin 3 of the controller goes to 5 Volts (Vcc), the current stops flowing and the LED turns off. As discussed above, the light detecting diode in the receiving circuit detects when the LED turns on and off, completing the reception of the digital signal.

You should be able to build the MIDI controller from the first schematic at the top of the page. Use the MIDI connector with the ground wire for the MIDI out port.  You should end up with something that looks like the picture below.

Click For Larger Image

You can also add an LED going from 5 volts to Pin 2 of the 2051, in series with a 510 ohm resistor, to have a visual indication when there is activity on the MIDI In Port. You can do the same for Pin 3 to see activity on the MIDI Out Port.

Using MIDI - The Software

Before we get into the actual software for the controller, we will look at a few simple MIDI commands. The first is a Note On command. This tells the receiving system to play a particular note. Then we send a Note Off command to tell the system to stop playing the note.

The commands are made up of a series of bytes. The Note On command is 3 bytes. It looks like 

9x yy zz

x is the channel number. There are 16 possible channels (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F). yy is the note number and can be anything between 00 and 7F (0 and 127 in decimal values). zz is the attack velocity and can be anything between 01 and 7F (an attack velocity of 00 makes the Note On command into a Note Off command).

The Note Off command is about the same. It is

8x yy zz. 

The values are the same as before except zz is the release velocity. 

For our first example we will make the controller play some notes. The software is midi1.asm. You only need to connect a a MIDI cable from the MIDI out port of the circuit to the MIDI IN port of a keyboard. Study the documentation in the software file to learn more about how the software works.

The basic process of compiling an assembly language program and loading it into the microcontroller was covered in the first microcontroller project. Compile the program and download it to the 2051. Make sure the power is off to the circuit you have built. Then move the 2051 to the circuit. Turn on the power to the breadboard.

The second example monitors inputs on the MIDI IN port of the controller. When a Note Off command is detected, the controller sends out a Note On and Note Off command for the same note. This creates a sort of echo effect.

Home  Products  Tutorials   Schematics   Robotics   Resources   Radio Stuff    Career    Download   Link Exchange

HTML Sitemap   XML Sitemap

Terms & Conditions  Privacy Policy and Disclaimer