MIDI input with optocouplers!

Hey Everyone,

What do I need to know when choosing the right optocoupler for a MIDI input?

There are a bunch of schematics on the internet for midi input using the 4N25, 4N28, 6N137 like in the shruthi, 6N138, etc. I have been reading up as much as I can, but still don’t understand why or if one type would be better suited for midi input. Or how to calibrate my circuit with the optocoupler for the best performance.

Also, I did make this circuit here at “instructables”:http://www.instructables.com/id/Arduino-MIDI-in-shield/

Although I got it to work, the midi data bytes were not accurate coming through the optocoupler on the serial monitor, even though they were in typical 3 byte midi groups.

Any help would be greatly appreciated. Thanks!

You need to choose an Optocoupler that produces nice sharp edges so your Microprocessor can easily read them - scope the MIDI signal at your MicroProz Input Port and you will see - so its dependent on the Input characteristics of the MicroProz and the output Characteristics of the Optocoupler. I guess easiest is try different ones :wink:

BTW there isn’t much you can calibrate in the standard Circuit……

For PicAxe i use the vanilla 6N137 as seen by MI, but you han here swap to a 6N138 without problems.

Do not copy any schematics found on arduino forums if you don’t understand them. Most of them are published by people who don’t know what they are doing. They might work just by chance!

Proof: when I started electronics, I just did this. I copied the 4N28 schematics that was circulating on the arduino forum. I actually used this on the original Shruti-1. Well, let me tell you, this circuit is pure crap and did not work with a bunch of MIDI devices. You might have more luck with a CNY17-1, but I do not recommend “passive” optocouplers like the 4Nxx or CNY. The right way to do it is to use an “active” optocoupler, capable of amplification, like the 6N137 or 6N138. Open the lid of any recent commercial product and it’s almost always one of these two guys.

The 6N137 is the one that gives the sharpest edges - even with a 10k pull-up. The 6N138 has soft positive edges, you’ll have to use a very low pull-up resistor (220). Both work with the appropriate choice of pull-up. I’m not sure why people prefer the 6N138 - maybe there are situations in which people want to avoid very hard edges running on their PCBs… Using a scope to monitor the signal edges helps a lot! I’ve found that the 6N138 are more sensitive when being manipulated - I’ve destroyed a few. So I’m a 6N137 guy.


True. I had a lot of failed attempts getting MIDI stuff running based on those Arduino schematics.

+1 on the 6n137, never had any issues with that part (unlike others)

Had 2 pieces DOA, lesson learned: always have 10 spare…

You buy chips by 2???

Odd, I even have some PC900 ICs in a drawer for that old gear that follows the MIDI spec slavishly. Wonder which odd project used the 6n139 or whatever odd something it was?

Edit: The 9090 goes with 6n136. MIDIBox is usually 6n138.

These were the times i ordered them by one - i am a slow learner :wink:

Thank you so much for all your input, this helps me out a bunch!

and order 6N137s by ten !

Hey again everyone!

Would you guys be able to explain the signal flow in these MIDI IN schematics? I am still unclear about which pins are used for “sharpening” the edges of the output signal.

The first schematic is for the 6N138 (which are the optocouplers I currently have). It is from the forum post here “http://www.electro-tech-online.com/threads/midi-in-thru-using-a-6n138-and-a-74hc14.116584/

So as far as I understand now, how this works is that the 5+ volts is going into the Rx of the microcontroller. But when the input of the optocoupler is triggered then that 5+ is re-directed to ground and the Rx then receives a zero or lower voltage. What I don’t understand is why the 5+ is connected to both pins 8 and 6 (collector 1 and collector 2). Why can’t it just connect to pin 6 (collector 2)? Also, the guy who posted it mentions how the 1K resistor on the base pin helps make the edges of the signal sharper. Why is that so?

Secondly, here is the screenshot of the 6N137 from the Shruthi schematic below. This circuit is similar except there the base pin is left floating. Why isn’t it connected to ground with a resistor? What part of the circuit here functions to sharpen the edges of the signal?

Thanks so much for your help everyone, it is greatly appreciated.

You make it sound like there’s a part of a circuit that generates a signal with slow edges, and then another part that sharpens then. No, there is no circuit or part responsible for “edge sharpening”. The resistor(s) decide how much current is available for the output to switch state. The more current (smaller resistors), the faster it can switch.

Regarding the 6N137 circuit:

> the base pin is left floating.

This pin doesn’t do the same thing than on the 6N138. The 6N138 has a darlington inside, the 6N137 a comparator and AND gate. So pin 7 on the 6N137 is not a “base pin”, it just goes to the AND gate. It works as an enable/disable pin, and needs to be set high. Since it has an internal pull-up resistor, it can be left unconnected too. Check the datasheet.

> What part of the circuit here functions to sharpen the edges of the signal?

Simple: none!

1 Like

> What I don’t understand is why the 5+ is connected to both pins 8 and 6 (collector 1 and collector 2).

The +5V is not connected to pin 6. What is connected on pin 6 is a pull-up resistor which sets the voltage at which pin 6 rests when the photo-diode doesn’t receive any light - otherwise this pin would be in an unknown state. Maybe you could have a look at transistor inverter circuits to get the idea of pull-ups.

> Why is that so?

I guess it affects only the descending edges - by draining current from the diode faster.

Awesome, thanks again for your help. I got the circuits working now and I feel like I have a much better idea of what is going on inside the optocouplers.

Hi –
FWIW, I discovered this thread while troubleshooting a MIDI problem on WTPA2.
First, thanks for all the info here.

Second, here’s a writeup of the solution I used for 6N138 optos, along with scope traces, in case anybody was still curious about this:

Olivier rules. Buy his stuff.


Hi Todd :slight_smile: