5
\$\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\$
10
  • 1
    \$\begingroup\$ You need to show us your circuit if we're to have any hope of helping you debug it. \$\endgroup\$ Commented May 24, 2015 at 16:38
  • \$\begingroup\$ Your title and your body don't match. \$\endgroup\$ Commented May 24, 2015 at 16:41
  • \$\begingroup\$ @ignacio, how so? \$\endgroup\$ Commented May 24, 2015 at 16:45
  • \$\begingroup\$ @Nick I'll certainly add the circuit when I get the chance later today. \$\endgroup\$ Commented May 24, 2015 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\$ Commented May 24, 2015 at 17:29

2 Answers 2

6
\$\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\$
7
  • \$\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\$ Commented May 24, 2015 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.
    Commented May 24, 2015 at 17:04
  • \$\begingroup\$ True; I'm not familiar with MIDI standards. \$\endgroup\$ Commented May 24, 2015 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\$ Commented May 24, 2015 at 20:49
  • 1
    \$\begingroup\$ Yup, no luck even with the revisions. I've ordered several H11L1 chips. Thanks. \$\endgroup\$ Commented May 26, 2015 at 0:44
-2
\$\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\$
1
  • 1
    \$\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
    Commented Aug 27, 2017 at 3:27

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