pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: Opto-isolator

Fri Apr 06, 2012 12:08 pm

Hi - I would like to use my RPI for a robotics project and am keen to isolate it from secondary circuits to avoid catastrophy. I am also on a budget and would like to acheive this via an opto-isolator IC and mini-breadboard. Rather than buying a bulky 3rd party io board with functionality I don't need, could anyone recommend an opto-isolator IC that would work directly from the GPIO pins. This would be smaller and cheaper no?
Ostendo ignarus addo scientia.

User avatar
Burngate
Posts: 6061
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Opto-isolator

Fri Apr 06, 2012 3:54 pm

I was going to say "Google is your friend" but another thread made me think that wasn't as helpfull as I might wish.

So. Digikey have oodles of them, so do Farnell and RS, and Maplin has at least one.

As to which one, it depends on what it's going to feed. The ones I looked at seem to take ~5mA, well within the Pi's output capability, and have kV of isolation. In the reverse direction, it won't need to drive much current to pull a GPIO input down to deck, and driving its input with ~5mA would be a good starting point.

Price-wise, you're going to have to spend at least a few pence. Maybe as much as £1.

Quite how you attach it to the Pi, I don't know. I'd start by "rat's nesting" it to the GPIOs, but once it's working, Veroboard or similar

Or just get a Gertboard!

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: Opto-isolator

Fri Apr 06, 2012 7:15 pm

As much as £1?
Ostendo ignarus addo scientia.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12352
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Opto-isolator

Fri Apr 06, 2012 9:16 pm

£1?

A suitable optocoupler (for example the SFH690ABT) costs as little as € 0,34 (at Farnell, so probably even cheaper elsewhere)!

The SFH690ABT gives 3750 Volt isolation.

The LED of the SFH690ABT has a forward voltage of 1.15 volt, so the voltage drop over the (essential) serial resistor will be 3,3-1,15 Volt =  2.15 Volt, so if you want to drive 5mA through the LED (the rated LED current for the SFH690ABT) the resistor should be R=U/I = 430 Ohm, so a suitable series resistor would be 470 Ohm. Tie one end of the resistor to 3V3, the other end to the anode (pin1) and tie the cathode (pin 2) to a GPIO output.

Driving the pin low will turn the optocoupler on.

plugwash
Forum Moderator
Forum Moderator
Posts: 3464
Joined: Wed Dec 28, 2011 11:45 pm

Re: Opto-isolator

Fri Apr 06, 2012 11:00 pm

There are lots of isolator devices (both opto and transformer based) on the market with a huge range of prices but before chosing them you have to know what signals you need to isolate.

So the first  question you have to ask yourself is what exactly are you trying to interface to what?

Then you have to decide where in the system you are going to put your isolation barriers. Personally i'd try to keep isolation to digital lines unless I had a REALLY good reason not to (isolating analog lines opens up a massive can of worms).

Once you have decided what signals need isolating then you can pick appropriate devices to provide the isolation while maintaining the required performance for those signals.

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: Opto-isolator

Sat Apr 07, 2012 1:56 pm

Thanks you two – that"s useful information – I"ll start saving up.

First I will just be flashing led"s on and off to test my programming skills (or "scripting" as the kids call it). Then I anticipate switching some motors and reversing their direction via dpdt relays for a robot buggy. Once I got that licked I"ll need some sensor input – first I think I"ll try encoding the motors using the slotted wheels from an old mouse/trackball and a photo interupter from ebay so I can tell how far it"s travelled.

Eventially I would like to include an ultrasonic range finder and compass to help it map it"s environment…..

… can see the attraction of something like the gertboard but space is a premium and I might not need all the bells and whistles – plus, I"m a cheapscate – my aim is to make the pi board the most expensive component!
Ostendo ignarus addo scientia.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12352
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Opto-isolator

Sat Apr 07, 2012 2:48 pm

For a lot of things you do not need to interface them through opto couplers, as simple drivers would be enough. The things you must be careful with are putting input signals onto the R-PI, as all inputs do not tolerate voltages above 3,3 Volt, so do not put TTL level signals directly to inputs (also true for SPI, I2C and UART signals). In case you have a 5V signal that must be input, just use a resistor divider, often 2K2 between the 5V source and the pin, plus a 3K3 resistor between the pin and GND will do the trick. Its often smart to put a small resistor (1K) in series with a pin to protect it.

Other things to be careful with are relays, these may generate high voltages across the windings when switched. Do not use a simple transistor to switch them, but use a special relay driver IC, or at least put a diode across the relay windings (cathode on the supply side). Also take care not to connect long wires directly to the I/O pins, or the pins may be damaged by static electricity, at the very least put 1K resistors in series, or indeed use opto couplers. When using an opto coupler as input to the PI remember to still put a series resistor in between the optocoupler and the pin. If you accidentally program the pin as output, and output a "1", and the optocoupler shorts the pin to ground without the resistor you will blow up the GPIO.

So even with optocouplers without series resistors and other precautions you could still damage the SoC if you are not careful or do not know what you are doing.

All said, the exact same things also apply when interfacing to other microcontrollers, so the R-PI is hardly unique in this regard.

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: Opto-isolator

Sat Apr 07, 2012 3:44 pm

Thanks - so much useful info!

I didn't realise that each pin could be programmed as either an input or an output...

...tell me if this is crazy but could one somehow safely connect 2 opto-couplers to one pin in parallell but in oposite directions to make a bi-directional coupleing ?

... worth some further thought (scratches head) ... maybe I'll just buy a gert board ...?!
Ostendo ignarus addo scientia.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12352
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Opto-isolator

Mon Apr 09, 2012 3:49 pm

safely yes,you only need a transistor as (inverting) buffer for the sending led, with a high value base resistor (say 100K), and a 10K pull up on the input pin (might be optional) The receiver optocoupler can be connected to the input pin through a "safety resistor" of say 100E, so that the optocoupler can pull the input (GPIO) pin down.

but you need some kind of protocol to determine whether you are receiving or transmitting, as in this setup everything you send to the GPIO is also echoed to the output optocoupler.

Needing "arbitration" is also true for most other isolated buffer systems. For example isolated buffers for I2C do exist, but they generally need another control line to determine communication direction.

Obviously needing such a "protocol" is also true with general purpose I/O pins without opto isolation.

Opto isolation is also only needed when you expect that there can be a (very) high voltage difference between the PI and the peripherals. For most normal situations you need no more than a few TTL buffers (level converters), so that when things go wrong they blow up, not the raspi.

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: Opto-isolator

Wed Apr 11, 2012 9:35 am

Interesting - I found this:

http://www.electronicsweekly.c.....5Mbits.htm

Seems bi-directional opto-coupling is possible...

... will continue to investigate the cost and practical feasibility ...
Ostendo ignarus addo scientia.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12352
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Opto-isolator

Wed Apr 11, 2012 9:55 am

pygmy_giant said:


Interesting – I found this:

http://www.electronicsweekly.c.....5Mbits.htm

Seems bi-directional opto-coupling is possible…

… will continue to investigate the cost and practical feasibility …


Yes, these typically consists of two photo-diodes doubling as LEDs, unfortunately an optocoupler with a photo diode needs a sensitive opamp circuit to "decode" the small variations of the conductance of the photo-diode under influence of the light of the opposing LED, so it cannot normally be connected directly to input of a GPIO pin.

P.S. Ah, after opening the link I see this model has the receiver circuits inside, but it has different channels for transmitting and receiving, which makes it essentially no different from using two opamps. Only this solution switches much faster than solutions using photo transistors.

Return to “Other projects”