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 with 6N138 Optocoupler:

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 here 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 optocoupler’s output has two transistors and one or two resistors. 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 In Schematics with 6N137 Optocoupler:

The 6N138 is a widely used optocoupler from the 1980s, particularly in the era when the first digital guitar effects processors with MIDI capabilities were introduced. Another cost-effective alternative for MIDI input schematics is the 6N137. It is a high-speed optocoupler with a logic output making the rising and falling edges even faster. Both optocouplers are pin-compatible, allowing for easy interchangeability with minor modifications when utilizing a universal PCB design.

The 6N137 has a digital output optocoupler, distinguishing it from the 6N138. Surprisingly, the prices of both optocouplers are relatively comparable these days. While the use of a bypass capacitor with the 6N138 is optional, it becomes important for the 6N137. The sole distinction here lies in the absence of one resistor compared to the 6N138 schematics. Here you can see the fully working schematics using the 6N137 optocoupler:

MIDI input with 6N137 optocoupler

Designing The 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.

MIDI out schematics

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.

Niki Hristov