Pins 1-4 of the opto look very unevenly spaced. Or is that an optical illusion?
Hopefully the new opto will cure the problem.
Regarding the cable screening, although pin 2 of the DIN connector is not connected to Gnd at the MIDI IN point (your synth), it should be grounded at the MIDI OUT point (your keyboard).
I imagine it is grounded inside the keyboard, it's an E-MU XBoard-25 running on battery power... I've never opened it up though. The pins look unevenly spaced because of pin 2 being vertically lifted by a mm or so (the bend I was referring to) and although it's still physically connected and is apparently still passing *something* I'm betting the chip is damaged.
OK update, I was able to repeat the test on the UNO, I loaded up the midi sketch and probed the correct places this time, and it produces a nice, clean pulse train, which I fed into the midi in jack on the synth, and no sound comes out. However, you can trace the same beautiful midi signal all the way to pin 3 of the atmega... so that's good, at least. Doesn't explain why now all signals are being dropped, but whatever.
But I probed my keyboard (with gnd on pin 2 and probe on pin 4) and got the same shitty sharktoothed wave we've been seeing before. So I think the midi out is hosed on the keyboard.
Look at the timebase you have set in the first screenshot, I bet that you had incorrect bitrate set in the midi sketch which is why you didn´t get it to play.
I am starting to feel the same abuot that keyboard. You could try loading the output with say a 1k resistor and see if it gets any better, but so far it seems that the keyboard is the problem here.
That first pic is indeed a beautiful sight . So if simply swapping the UNO for your keyboard resulted in the second pic then I have to agree that the keyboard is now the suspect .
Do you have a schematic of the keyboard MIDI out section? Hopefully that section has a repairable MIDI driver stage.
Good catch! I still had that midi sketch set to 9600 for testing... but fixing its baud rate gave me a sharktoothed signal again. It did make noise, so I created a video showing the setup, probed at pin 6. Not all of the notes are being done correctly, and I'm guessing that's because of the sharktoothed waves, but it could also be damage to the soundgin chip? Anyway, we should be hearing a chromatic scale going up, and instead we're hearing random notes with some sub-bass in between.
(warning, the video is loud... turn your volume way down and use headphones if you don't want to disturb others)
Hmm, I just had a random idea, have you tried swapping the two pins coming from the midi cable? If that doesn´t help, when is the new optocoupler coming?
So... check this out on the datasheet for the 6N138... one of the test circuits looks exactly like my original schematic, and has a chart of some possible resistance values... which says that I should be getting 7mA for the 270 ohm resistor I originally had in there. Instead, I was getting 17.7mA... so I'm thinking that might be our confirmation that the chip is borked.
Replacement stuff arrived today... slapped in a new optocoupler... looks exactly the same.
However, building the midi in circuit on a breadboard allowed me to play with resistors until I got something resembling a square wave (I put a 3.3k resistor on the input side... I'm thinking about also putting a 100 ohm resistor on the output side, as that seemed to work best on the breadboard)... all note offs are still dropped, an occasionally note ons will be dropped, though:
I'm unclear what your scope is showing. If I understand the settings correctly, your vertical sensitivity is 2V per division, so you're seeing a signal going from 0V to nearly 5V? That bit looks ok. But what is the horizontal time base setting (50uS per division?)? None of the figures '10.64kHz', '94uS', '50uS' or '292uS' seem to have any relation to the MIDI clock rate of 31.2kHz (=32uS per bit) ??
Can you post the waveforms and peak-to-peak voltages you get (a) between pins 4 and 5 of the MIDI IN socket and (b) between pins 2 and 3 of the 6N138 ?
Yup, the time base setting was 50uS, the frequency and period calculated by the scope is completely off so just ignore that... and here are the waveforms:
Between pins 4 and 5 of the MIDI IN socket (5vpp):
Between pins 2 and 3 of the optocoupler (a little over a volt):
Between pin 6 of the optocoupler and ground (almost 5vpp):
And here's a video of what it sounds like currently. The arduino sketch is supposed to play a chromatic scale going up, with 3/10 of a second on and 7/10 of a second off (so should be silent). You can see that all the note offs are being dropped, and in the upper registers some of the notes are also being dropped.
At last, nice clean MIDI! Can both your keyboard and the Arduino produce that? What did you do to lose the shark teeth?
Looks like any problems now are due to the software rather than the hardware. Are interrupts disabled during the MIDI message send?
Just spotted your edit to post #54. So that's where the shark's teeth went . Looks like the MIDI OUT stage of your keyboard was being stressed driving the opto's LED via 220 Ohms. Given the spec of the 6N138 I'm surprised you're thinking 100 Ohms on pin 6. I would have thought 1k or even higher would do the job better, unless the micro's input pin has a high capacitance.
First of all, you were talking about grounds at one point. You're correct in that you want to avoid a ground loop between pieces of equipment. For that reason the convention is that the shield in a MIDI cable (if any) is grounded at the output device and the shell pin on the DIN connector MUST be left open on the receiver at the input device.
FYI, about the waveform at the MIDI output: MIDI is a current-loop protocol. The output is usually driven by an open-collector buffer through a 220 ohm resistor, and the return terminal goes through a 220 ohm resistor to 5V. Putting a scope on the midi output will see the scope capacitance charging up in a relatively slow ramp, and then pulled down to ground when it pulses. That's why you see the "shark tooth" pulses looking into the MIDI output. But not why you saw them on the output of your opto. The opto should be getting nice discrete pulses of current through the LED and the transistor on the output should be pulled easily by the 270K resistor to handle MIDI speeds with intelligible pulses (maybe not perfectly square but pretty darn good).
It sounds like you nailed it with the higher resistance on the input. However, it's a mystery because it shouldn't have been necessary. Sounds like a damaged output circuit on your keyboard? Hard to imagine.
The 6N138 is not too shabby. A 270 ohm resistor on the output will only cause 20mA of sink current and the device can handle 60mA, but only if there's enough current on the input. With 440 ohms in the transmitter and 1K on your receiver, 1.4K ohms with 5V-1.4V = 3.6V is only 2.5mA. With 660 ohms that would have been 5.5mA. I can't believe the keyboard output couldn't handle 5.5mA of drive but can handle 2.5mA... Anyway, 2.5mA times the current transfer ratio minimum of 3x puts you at 7.5mA output. Higher possible transfer ratios would put you well above the ability to deliver 20mA on the output... but how?
The Avago 6N138 datasheet gives a lot more information. I found these curves that show current transfer ratio maximized (see middle graph) when the forward current of the diode is limited to 1mA. So I think your reduction of the input resistor put your optocoupler in a higher current transfer mode and gave you a cleaner output, not because of the output of the keyboard, but because of the efficiency of the optocoupler and the load. At 5.5mA drive you would have been at a current transfer ratio of lower than 400% (4x) so you would have been right at the limit of driving the 270 ohm output load resistor and the 20mA sink.
Moral of story: Use a better optocoupler, like a Sharp PC900 with buffered output...