So I have an interesting situation I would like to share. I created a MIDI input circuit that mostly follows the MIDI schematic detailed by Paul on the midi library page. I originally used this 6N139 optocoupler to do the job: https://www.fairchildsemi.com/datasheets/6N/6N138M.pdf and everything worked great!
I changed over to this optocoupler (6N139-X009 option) http://www.mouser.com/ds/2/427/6n138-67270.pdf because of its low vertical profile. After assembly, my MIDI wasn't working properly! Clock messages would not come through, and stop messages would be recognized as clock messages. I noticed that there was some slew on the signal when I hooked up a scope. I swapped the new Vishay 6N139-X009 with one of my old fairchild 6N139 chips, and it worked as expected...
I then stumbled upon this article: https://electronics.stackexchange.co...-many-circuits
I followed the advice of the green check solution, and connected a 10k resistor between the Vbase (pin7 on the 6N139) and ground - this was after swapping back to the 6N139X009.
Now it works!
Just wanted to share this in case someone comes across this problem in the future. I do not fully understand this, but here is the explanation:
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:
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).