I have been looking for an interface into my programming language for manipulating the GPIO pins and I have found a good solution.
So I connected a relay board to the GPIO connector and all seemed to work well. However today I rebooted my Pi2 and it turned on the relays!
So it seems like the Pi comes out of boot with the GPIO pins driving the outputs.
How can I stop this? The relays must never all be on at the same time and they should be off until the program is started and decides what to do.
Right now I am using GPIO3 on pin 5 to drive the test relay. I have checked a number of other outputs when I debugged the I/O driver, but I never rebooted before with teh relay board connected.
Unfortunately I don't have any schematics for the board. Quite possibly it has a buffer transistor before the optocoupler...
I will have to trace it down and decode the schematics.
Otherwise I will have to use some kind of GPIO output to enable the whole board in a way that ensures it does not activate until my program starts.
OK, good to know!
I will move to another output, I tried GPIO14 (pin 8) which is the next one on the even numbered row but it was also high.
GPIO18 on pin 12 seems to work as expected though.
Is there a summary somewhere where one can see what the boot state of the pins are?
Just to complete the story...
I traced the schematics now and it is pretty simple:
The input control runs through a 1K resistor to the LED of an 817C opto-coupler.
The output of the coupler directly drives the relay coil (there is a protection diode also).
The relay coil is 70 ohms and supposed to be driven from 5V, that is nominally 71 mA.
The optocoupler data sheet says that it has a current transfer rate of 400%, so that means to get full coil voltage the input must get 18 mA.
But that is not even remotely possible given that the GPIO output is at 3.3 V and there is a 1K resistor and an LED in the circuit.
I would be surprised if the current is much more than 2.3 mA, a far cry from the 18 mA needed for the opto-coupler.
And I don't really understand why an opto coupler is used in the first place!
The needed isolation from the target system will anyway be provided by the relay contacts, right?
So the relay coil could be driven from the GPIO outputs using a MOSFET transistor instead and the current level discussion would be moot.
The only thing I could think of is that the designers wanted to have the relay drive isolated to protect against a kickback voltage spike propagating backwards into the controller via the power supply. But then they would have to have used a buffer transistor in the coil circuit too!
In the final solution I will probably design a board myself.
The Pi as you know outputs 3.3v on its GPIO. Whereas your relays on your board need 5v to operate. Not only that but the current requirements of the relay is also too much for the Pi. The Pi only has about 50mA for all its GPIOs (it is shared on the 3.3v rail)
This means you need an interface between the two.
A transistor would do. And in some cases that is all that is used. However, since it is a bridge to the outside world, it is better practice to use complete isolation with an optocoupler.