Page 1 of 1

Process of getting MIDI input to my Raspberry PI through UAR

PostPosted: Wed Jan 24, 2018 11:18 am
by Woen
I'm currently in the process of getting MIDI input to my Raspberry PI through UART, and in order to follow the standards, I should optically insulate the MIDI cable from the RPI by using an optocoupler in such a way that then there is no current flow, I get logic HI, and when there is current flow, I get logic LOW, so probably the optocoupler is also inverting the signal.

Please note I'm kind of a layman here. I'm currently studying physics, and have always been very interested in electronics, but have never dug deep into this realm. However, I'm interested not only in getting things to work, but understanding why and how they work.

I'm currently planning on using the 6N138 optocoupler. In the diagram provided in the datasheet: http://www.kynix.com/uploadfiles/pdf/6N138.pdf, there is a diode which I don't get the usefulness of.

ZRT9z.png
ZRT9z.png (6.29 KiB) Viewed 1949 times


The diode in question in the one that connects the base of the phototransistor to Vcc. If I understand correctly, the diode is in reverse bias when Vcc is at a higher voltage than the base of the transistor.

My guess is that this diode allows the base to discharge when there is no longer light arriving from the LED between pins 2 and 3. This, of course it just a guess, but it certainly seems that I'm missing something big here.

Re: Process of getting MIDI input to my Raspberry PI through

PostPosted: Wed Jan 24, 2018 12:03 pm
by james
I get logic HI, and when there is current flow, I get logic LOW, so probably the optocoupler is also inverting the signal.


This is correct. The serial signal is also like this: high = idle, low = active. The LED in the optocoupler is connected between +5V (from the sending device) to the logic signal. When the logic is high, no current can flow; thus it needs to be low to get a signal through the optocoupler.

The diode in question in the one that connects the base of the phototransistor to Vcc. If I understand correctly, the diode is in reverse bias when Vcc is at a higher voltage than the base of the transistor.

My guess is that this diode allows the base to discharge when there is no longer light arriving from the LED between pins 2 and 3. This, of course it just a guess, but it certainly seems that I'm missing something big here.


It is a photodiode - there isn't a phototransistor.

The photodiode is reversed-biassed, which is typically how you operate photodiodes. When light hits it, it can conduct current which is then amplified by the pair of transistors.

It is also a good idea to include an external diode across the "A"and "C" pins of the input, but in reverse polarity to the LED. This protects the optocoupler's LED from reverse polarity. (D1 as shown here: https://www.midi.org/specifications/ite ... cification.)

Also, although the MIDI spec says 5V, most MIDI devices (especially modern ones) will work ok at 3.3V. It can simplify testing. But to be fully compliant with the spec, 5V is better.

Re: Process of getting MIDI input to my Raspberry PI through

PostPosted: Wed Jul 31, 2019 10:02 am
by Asmitasant10
Thank you for the information.