Hi, I've been working on creating a MIDI controller from my Arduino. I've bought a USB to MIDI device which is capable of sending and receiving a MIDI signal.
I have been able to get the sending of MIDI signals from the arduino to my computer working, now the receiving part from the computer to the Arduino is giving me trouble.
This is the way I wired up my test (BTW the IC is the 6N138 optocoupler in the correct orientation).
As you can see I did not wire the signal from the optocoupler to the Rx pin on the Arduino but to pin 7 instead. This is because I already had trouble connecting it to the Rx pin before and I wanted to troubleshoot.
I have the code tell me if the pin is either high or low. When I manually connect 5 Volt to pin 2 of the optocoupler (with a 220 Ohm resistor) and connect/disconnect GND to pin 3, this program tells me that pin 6 of the coupler is either HIGH or LOW. This works really well, but when I then connect the MIDI-out from my USB to MIDI converter, it always outputs HIGH. When I just hook up an LED to the MIDI-out, I can see it flashing when I send some data with Midi-ox.
I have no clue why I can see my manual input and cannot see the input of the MIDI-out. I have also tried to reverse the wiring from the MIDI-out to the optocoupler and that didn't work either and now I don't know for sure if it still works correctly or not. Atleast my manual approach still works fine.
MIDI is a current loop so no need for any pull-ups.
MIDI signals spend little time in the opposite state so it is very difficult to see with that program. Convert the program to light up the LED on pin 13 when you see activity on pin 7.
I am currently not in a position where I can test that circuit, but since I'm trying to learn about electronics. Would it be an inconvenience to explain why you used 1K resistors instead of what I did? I just made my design from multiple examples but I would like to know why things are the way they are.
I will try out your circuit as soon as I come home.
Grumpy_Mike:
The wiring of the opto isolater looks wrong.
Although it's a very very crappy Fritzing-mess and it's a bit weird to use two resistors in series as pull up it doesn't seem wrong to me. No need for a resistor inline with Vcc and the enable may be left floating.
I found an example which used a 470 Ohm resistor and I only had ones of 220 ohm laying around so I thougt 440 Ohm would be close enough. Even in the example they also used two 220 Ohm resistors in series.
440Ohm for a pull up is pretty high... I would change to use the internal pull up resistor on the Arduino via pinMode(pin, INPUT_PULLUP) and remove the external resistors as Grumpy_Mike suggested.
So I did excactly what Grumpy_Mike suggested now, but I got no result. The LED lights up constantly, even when I apply the input signal on the coupler manually. When I unplug the wire attached to pin 7, the LED goes off. But only then and in no other condition. No results with other 6N138's I have lying around either.
OK I can't see anything wrong with that. Mind you it doesn't show pin 6 and 5 going to the Arduino.
With nothing connected to the input, you seem to suggest that pin 6 going into the Arduino gives a low reading, and disconnected gives a high reading. That would suggest that the final transistor in the opto is shorting to ground in the absence of any light. This in turn suggests that it is broken.
Alright, yeah the wire coming from pin 5 goes back to the ground line, but it indeed isn't clearly visible, sorry for that. Now, I tried this circuit with a brand new out of the box opto and it still behaves the same. Anyway, thanks for the help. I guess I have to look for other ways to do this.
I cannot confirm, but it's really weird that I can make the optocoupler work when I put a signal in manually with my first design and the output actually acts like it's all working fine.
Did you ever get this going? I'm having the exact same issue, I suspect its the usb-midi device, I am having the same issue that the opto works fine if I manually trigger it but if I use the midi feed nothing! Hopefully you figured it out and can pass on the solution