Bosse_B
Posts: 757
Joined: Thu Jan 30, 2014 9:53 am

GPIO state at boot turns relays on

Tue Oct 13, 2015 8:28 am

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.
Bo Berglund
Sweden

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: Korea

Re: GPIO state at boot turns relays on

Tue Oct 13, 2015 8:46 am

Try using a different GPIO. Some of them have a hard-wired pull-up resistors.

Or maybe you need to install a pull-up or pull-down resistor.

Do you have a schematic of your relay board?

Bosse_B
Posts: 757
Joined: Thu Jan 30, 2014 9:53 am

Re: GPIO state at boot turns relays on

Tue Oct 13, 2015 9:08 am

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.
Bo Berglund
Sweden

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: Korea

Re: GPIO state at boot turns relays on

Tue Oct 13, 2015 9:40 am

Ok, that pin (GPIO3, pin 5) has a 1.8k pullup resistor on board. If your relay control is active high then the pullup will pull the GPIO pin high and the relay will turn on.

Bosse_B
Posts: 757
Joined: Thu Jan 30, 2014 9:53 am

Re: GPIO state at boot turns relays on

Tue Oct 13, 2015 9:56 am

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?
Bo Berglund
Sweden

Massi
Posts: 1691
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: GPIO state at boot turns relays on

Tue Oct 13, 2015 9:59 am

Bosse_B wrote:Is there a summary somewhere where one can see what the boot state of the pins are?
i'll not fall in the lmgtfy temptation, but the theme has been discussed a lot of times here in the forum

for example here
viewtopic.php?f=44&t=35321

but you can do a more specific search..

btw, a hardware pulldown would be a good idea anyway

Bosse_B
Posts: 757
Joined: Thu Jan 30, 2014 9:53 am

Re: GPIO state at boot turns relays on

Tue Oct 13, 2015 12:42 pm

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.
Sketchy design!
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.
Bo Berglund
Sweden

pretoriano
Posts: 3
Joined: Tue Jan 12, 2016 4:03 pm

Re: GPIO state at boot turns relays on

Tue Jan 12, 2016 4:11 pm

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.

Bosse_B
Posts: 757
Joined: Thu Jan 30, 2014 9:53 am

Re: GPIO state at boot turns relays on

Tue Jan 12, 2016 6:05 pm

This thread is a bit old...
I finalized my prototype setup by buying a 4-channel relay board with transistor drivers etc.
Works just fine.
Bo Berglund
Sweden

Return to “General discussion”