5

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.

Patagonian Rat
  • 177
  • 1
  • 13

2 Answers2

6

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).

CL.
  • 18,161
  • 5
  • 40
  • 67
  • You could also use a non-optical isolator, such as one from the Analog Device's ADUM series, or TI's ISO series. – Nick Johnson May 24 '15 at 17:01
  • @NickJohnson Those chips require a power supply for their input; how would you connect them to a MIDI cable? – CL. May 24 '15 at 17:04
  • True; I'm not familiar with MIDI standards. – Nick Johnson May 24 '15 at 17:28
  • 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? – Patagonian Rat May 24 '15 at 20:49
  • 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. – CL. May 25 '15 at 05:58
  • Thanks for that. I'll try your revisions and if it still doesn't work (and that's looking pretty likely) I'll just buy an H11L1. – Patagonian Rat May 25 '15 at 13:46
  • 1
    Yup, no luck even with the revisions. I've ordered several H11L1 chips. Thanks. – Patagonian Rat May 26 '15 at 00:44
-2

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"

Korozjin
  • 513
  • 3
  • 10
  • 1
    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. – Nayuki Aug 27 '17 at 03:27