Choosing the right optocoppler for your midi-in project (e.g. Arduino)
The headlines almost says it all: when building an midi-input device for an µC-project e.g. an Arduino or an Raspberry Pi project, the first thing the MIDI cable “sees” is the optocoupler. And is important to choose the right one.
A lot of ciruits relate to the “4N28”. This is a passive optocoupler and to be frank it causes a lot of problems in the standard setup which mostly are not identified as an electrical problem.
- no midi input at all
- random loss of midi notes
- random playing of other midi notes
The problem is that midi gear has very different electrical outputs. So your input module might work with one hardware, but switching to another keyboard or interface might not work anymore.
User [pichenettes] reported 4N28 related problems with: Akai MPK25, Alesis x25, Axiom 49, Midisport 1×1, M-Audio Oxygen 8.
a) One is simple and might work in 80% of the cases: Replace the resistance from the 220Ohm with a lower value. In the data sheet one can see that the 4N28’s diode needs 1.3V at a current 50mA which gives a series resistor of 74 Ohms, so 100Ohm should work. For me 150Ohm was ok but 100Ohm as calculated above didn’t work anymore.
b) Switch to another optocoupler. Many people report good results with the CNY17 which also is pin-compatible to the 4N28. And one should also consider optocouplers like the 6N137 and 6N138 which have are active and are probably a better choice.