4
\$\begingroup\$

I ordered a set of optocouplers the other day and was excited when they finally came in. Unfortunately, I've having a bit of trouble getting them to work. Simple on/off tasks work fine but when I attempt to use it to send MIDI data to an Arduino Uno I get no response. I suspect that the problem lies in the type of optocoupler I'm using. While the majority of projects on the internet seem to use the 6N138 I figured I could swap it out with the similar 6N38. Currently, I think the problem is switching time. The 6N138 is a diode optocoupler while my 4N38 is a transistor optocoupler. But without an oscilloscope I have no easy way to be sure. To complicate things, I can't find much in the way of any circuit using the 4N38 despite it's similarity to other chips. Is it possible to transmit MIDI data with this chip? Should I just buy a different one? 4N38 Circuit

NOTE: VCC is 5V.

EDIT: Corrected part number. EDIT: Specificity. EDIT: Added schematic.

\$\endgroup\$
  • 1
    \$\begingroup\$ You need to show us your circuit if we're to have any hope of helping you debug it. \$\endgroup\$ – Nick Johnson May 24 '15 at 16:38
  • \$\begingroup\$ Your title and your body don't match. \$\endgroup\$ – Ignacio Vazquez-Abrams May 24 '15 at 16:41
  • \$\begingroup\$ @ignacio, how so? \$\endgroup\$ – Patagonian Rat May 24 '15 at 16:45
  • \$\begingroup\$ @Nick I'll certainly add the circuit when I get the chance later today. \$\endgroup\$ – Patagonian Rat May 24 '15 at 16:46
  • 1
    \$\begingroup\$ @Andyaka I disagree - he's asking specifically why this chip isn't working for him; he's just not providing a lot of detail on the circuit in question. \$\endgroup\$ – Nick Johnson May 24 '15 at 17:29
5
\$\begingroup\$

R2 is too large. The specification specifies 220 Ω to get 5 mA; smaller currents just make the output transistor weaker.

R3 is wrong. A base-emitter resistor could be used to allow the charge to be removed faster from the saturated base when switching off. However, such a resistor also adds a minimum threshold for the base current (because no current will go into the base until the voltage drop over the resistor is large than the base-emitter voltage). This would be acceptable with a Darlington optocoupler like the 6N138, due to its high amplification, but with a simple phototransistor, that current is so small that it is unlikely that the transistor will ever turn on. Remove R3 altogether, or try a large value like 1 MΩ and go down from that.

The pull-up resistor R1 looks OK. But you might want to try a smaller value like 100 Ω, just to be sure.


At 31250 baud, one bit has a length of 32 µs. For reliable operation, the raise/fall times of your optocoupler's output must be much less than that; the MIDI specification recommends less than 2 µs.

A simple transistor optocoupler is unlikely to be fast enough.

The 6N138 uses a photodiode, but its Darlington output is too slow for MIDI unless you add more components (e.g., a base/emitter resistor) to speed it up.

The best optocoupler to use is a high-speed optocoupler with a logic output. Just use the one from the MIDI specification (note: "PC900" is Sharp's way of spelling "H11L1", which is made by many manufacturers).

\$\endgroup\$
  • \$\begingroup\$ You could also use a non-optical isolator, such as one from the Analog Device's ADUM series, or TI's ISO series. \$\endgroup\$ – Nick Johnson May 24 '15 at 17:01
  • \$\begingroup\$ @NickJohnson Those chips require a power supply for their input; how would you connect them to a MIDI cable? \$\endgroup\$ – CL. May 24 '15 at 17:04
  • \$\begingroup\$ True; I'm not familiar with MIDI standards. \$\endgroup\$ – Nick Johnson May 24 '15 at 17:28
  • \$\begingroup\$ The lack of speed is something I was concerned about when I looked at the datasheet. As you mentioned however, even the 6N138 is too slow without external components. Is it possible that doing the same could make the 4N38 workable? \$\endgroup\$ – Patagonian Rat May 24 '15 at 20:49
  • \$\begingroup\$ The 6N138 has only the problem of slow raise times. There's nothing much you can do about the slow fall time of the 4N38. \$\endgroup\$ – CL. May 25 '15 at 5:58
0
\$\begingroup\$

This may not be the answer you're looking for, but having personally tried to do a lot of stuff with MIDI and Arduino, you may want to look at Teensy if you are going to do anything serious with it. Teensy works with most MIDI stuff "out of the box"

\$\endgroup\$
  • \$\begingroup\$ The Teensy is a splendid microcontroller, but you still need to use an optocoupler circuit when accepting MIDI input. This doesn't answer the original question. \$\endgroup\$ – Nayuki Aug 27 '17 at 3:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.