I'm building a MIDI IN to serial port RX cicruit (for Raspberry Pi, or Arduino, or anything else...) using a 6N138 optoisolator.

But I find many different circuits, I don't know why there are so different, and which one to choose:

Are these correct?

  1. First, this one with a 470 Ohm and 1KOhm resistor
    (source: electro-tech-online.com)

  2. Another, with respectively 1KOhm and 3.3KOhm resistor

(source: dernulleffekt.de)

  1. The official one on midi.org, with different resistor values, but not based on 6N138...


Last thing (maybe off topic here): If I want to connect to Raspberry Pi's GPIO's RX, should I use 3.3V for the optoisolator instead of 5V, to prevent breaked with GPIO's RX?


1 Answer 1


Optocouplers with Darlington output (like the 6N138) are very slow, especially when the output transistor should switch off.

To get a sufficiently fast raise time of the output signal, the base of the output transistor needs a connection to ground (through a resistor) so that the base charge can be removed quickly. Any value between 4.7 kΩ and 10 kΩ should work fine.

Furthermore, the raise time of the output signal also depends on the value of the pull-up resistor (R1 below). Smaller values result in faster raise times, but very small values increase the power usage when the optocoupler pulls the output low. In practice, about 1 kΩ is commonly used.

The 6N138 needs a 5 V power supply, and the Raspberry Pi does not work with 5 V signals. However, an open-collector output can be used to translate the signal level; just connect the pull-up resistor to 3.3 V instead, like this:

6N138 with level shift

If possible, forget about the 6N138 and use an optocoupler with a digital output (like the Sharp PC900 from the specification, or the H11L1); if you need to save space, use a SO-5 chip like the TLP2361 (which has a CMOS output, so it does not need a pull-up resistor).

  • \$\begingroup\$ Thanks for this detailed answer! Just to be sure: about you see that you should not go higher than about 200 Ω are you speaking about the resistor that was set to 470Ω in 1., 1KΩ in 2., and 280Ω in 3. ? So I can take everything between, say 200Ω and 500Ω, right? Sidenote: I have a few 6N138 here, so I would like to use it, instead of buying another component. \$\endgroup\$
    – Basj
    Apr 17, 2015 at 9:21
  • \$\begingroup\$ It works with your schematics! Yeepee! Could I power the 6N138 with 3.3V @CL. ? Or would it not work at all? \$\endgroup\$
    – Basj
    Apr 17, 2015 at 20:44
  • \$\begingroup\$ The datasheet does not allow it. I do not know if it would work with your chip. \$\endgroup\$
    – CL.
    Apr 17, 2015 at 21:10
  • \$\begingroup\$ Can I try to power with 3.3V or could it damage something? (I imagine it wouldn't) \$\endgroup\$
    – Basj
    Apr 17, 2015 at 21:16
  • \$\begingroup\$ See the Absolute Maximum Ratings in your datasheet. \$\endgroup\$
    – CL.
    Apr 17, 2015 at 21:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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