I'm working on a MIDI to cv interface for my modular synth, so far I've been successful getting the DAC to work but I'm stuck on a problem now. I'm using a 4N35 optocoupler using this schematic found on arduino forums [post]. When I tried it the RX led wouldn't light up at all even though I knew my keyboard worked (verified with my scope). I double checked pinouts, tried multiple ICs, redone the wiring from scratch multiple times to no avail. My MIDI keyboard outputs about 2v when high and 0v when low (while unconnected from the optocoupler). However, when I connect it to the optocoupler, the MIDI signal from my keyboard stays permanently high [2v] and the optocoupler output stays at about 5v (note: these measurements were taken while the opto out was not connected to arduino RX). The thread I've linked talks a lot about the pull up resistor (I think) and I've tried different values ranging from 500ohm to 1k, still no success. I've gone through a lot of searching without finding anyone having similar problems.
Thanks for reading my post, help would be greatly appreciated.
So you need to start some debugging of the circuit.
First check the 4n35. Look for continuity between pins 1 and 2 of the 4n35. It should conduct one way only (after all it's an LED inside the chip that connects them two pins)
Next check pins 5, 6 and 4 act as a simple NPN transistor (should appear as a pair of diodes to a multimeter).
If the 4n35 checks out remove the wires from your midi port and put 5v across where pins 4 and 5 would be connected. (+ to pin 1 of the 4n35). Check for the voltage at pin 5 of the 4N35. (with reference to GND of the arduino)
Remove the 5v from the input and check again.
If all of this checks out then the problem is probably with your sketch.
Thanks for the fast answer. At the moment I can't test the circuit, but I've tested the led part of the opto and it behaved normally. I'll check the transistor tomorrow.
However, when I connect it to the optocoupler, the MIDI signal from my keyboard stays permanently high [2v] and the optocoupler output stays at about 5v (note: these measurements were taken while the opto out was not connected to arduino RX).
That doesn't prove a heap. It might be 5v some of the time and 0v the rest of the time. You need a scope or logic analyzer. See what the logic levels are doing, particularly on the output of the optocoupler.
MIDI is current-driven, not voltage driven. When I tried to measure MIDI signals with a scope it wasn't very helpful.
Found my mistake, the 220 resistor was on pin 5 instead of 4 (of the midi jack). Midi jack is now properly hooked up to the optocoupler. I tried the testing method you described, and the opto now performs the desired action. 5v in = about 0.3v out, 0v in = 5.5v out. I then tested it with a 3.3v, which is closer to my keyboard's 2v and it works too.
I then connected my keyboard, the opto outputted a signal. However, the voltage is quite a bit lower. It stays at around 1v when low and goes to 0v when high. There is also a bit of slew but I'm pretty sure it's not too significant. There seems to be something similar to an inductance spike happening whenever the signal changes state. It looks like this. I haven't plugged it into my arduino because it kind of worries me it might break it.
Thanks for helping me so far! I'm getting pretty close to getting it done now!
Sorry if I was unclear. I did what KenF suggested; I tried the circuit by unplugging the keyboard and applying voltage on pin 4 (positive) and 5 (gnd) to see if the opto would respond. When 5v was applied (high signal), the opto out would go down to 0.3v, and at 0v (low signal) it went up a bit past 5v, which is the expected behaviour. Since I was a bit worried my keyboard wouldn't output enough voltage (high signal was at 2v, measured with a scope) to light up the led within the opto and that I might have to play around with the 220 ohm resistor. I tried a voltage close enough to 2v just to verify, and having easy access to a 3.3v rail I choosed that.
Right now the only thing I'm kind of worried about are the smal voltage spikes on the opto output when it transitions from a state to another (high/low) and the fact that it's only staying at around 1v when high. [pic] I'm pretty sure the Arduino expects something higher than that.
I was worried 2v would not be enough to turn on the optocoupler LED, which is why I was measuring the voltage.
Before plugging in the keyboard, while testing, I didn't know if the circuit was safe to plug in, so I just simulated high and low levels by plugging in 3.3v or 5v from my arduino directly where the midi in should have been. The reason why I tested it on 3.3v is that I wanted an estimate as of whether or not 2v would power the LED within the optocoupler. I've attached a schematic. Hope this helps