When I first began designing devices that support MIDI, I searched for schematic examples on Google. After reviewing a few examples, I realized that I needed to delve deeper into the matter to create a well-functioning MIDI implementation for all N-audio devices. In this topic, I’d like to share my experience with you.

What is MIDI?

MIDI stands for Musical Instrument Digital Interface, which is a serial communication protocol operating at 31,250 bits per second. It uses 8 bits per byte, along with a start bit and a stop bit, and operates at 5 volts DC. The standard MIDI connector is a 5-pin DIN connector, with female connectors on the device and male connectors on both ends of the MIDI cable.

Designing the MIDI In Schematics:

Galvanic isolation of all MIDI inputs is crucial, as it helps to isolate the digital ground loops. This is done through an optocoupler, which is a component that contains a separate LED and phototransistor (or an opto component) in a single package with galvanic isolation within the range of 1000-5000 volts between both elements. It’s important to choose an optocoupler that is fast and can adequately transfer the MIDI data without skipping bits. My choice is the 6N138 optocoupler, which is relatively cheap and available in DIP and SMD packages, although it’s relatively large in size.

MIDI in schematics
To protect the LED inside the optocoupler, R1 limits the current to the LED. The MIDI voltage is usually 5V, and the forward voltage of the LED is 1.3V. Therefore, using Ohm’s law, the current to the LED is limited to (5-1.3)/220= 17mA if a 5V supply is applied from the outside. The R1 value is typical for all MIDI designs, and it matches the resistor values on the MIDI out schematic. The diode D1 protects the LED against its maximum forward voltage. The output of the optocoupler has two transistors, and usually, one or two resistors are connected there. The 6N138 datasheet examples omit R3, but my experiments show that there must be a resistor. I found that a 1k resistor for both R2 and R3 works better and faster, and using identical components will decrease the bill of materials. C1 is optional but exists on all devices that I make. It’s a 100n capacitor placed next to the optocoupler, which filters high-frequency noise across the 5V power supply rail. The MIDI IN goes to the processor as shown.
MIDI trace

The yellow trace shows the input MIDI signal before the optocoupler. The green trace shows the output signal after the optocoupler.

Designing The MIDI Out Schematics:

MIDI out schematics

When it comes to the MIDI out schematic, simplicity is key. To achieve this, I opted for a single transistor buffer, which is not only fast but also affordable. Moreover, this transistor also isolates the microprocessor, ensuring added protection. I selected the 2N5551 (MMBT5551 SMD) transistor specifically for its high Vce (collector-emitter voltage) of 160V. For EMI protection, I incorporate two 100p capacitors into the circuit. Implementing this circuit with two 220 Ohm resistors effectively limits the current across the 6N138 LED from the MIDI in schematics to approximately 5mA. R3 plays a role in limiting the base current, while grounding the middle pin enhances shielding across the MIDI cable. It’s important to note that when using this circuit, you must invert the signal from the microprocessor.

Summary:

I hope sharing my experience with MIDI implementation helps you in your own designs and understanding of this technology. These schematics should provide a good working solution, saving you time and effort in your search for an effective MIDI implementation.