TheWalkingCactus
Posts: 14
Joined: Fri Mar 29, 2013 7:53 pm

3.3v pins supply more amps than other 'Controllable Pins'

Sat Jul 27, 2013 4:50 pm

I've started building a remote-controlled car. I have a couple of relays with a 5v coil that I'm using. (The motors run off of 9v)

I tested the relays on the 3.3v pins in the GPIO header, and they worked! So I thought that I didn't need to buy any level shifters or anything. However, when I tried it on any of the controllable pins, it made a barely audible hum when depowering it, instead of a loud click when powering. This didn't make any sense: Why would it work on the 3.3v pins and not the other ones?

I got out a multi-meter and tested the voltage.
Both pins were just over 3 volts.

Next I tried the amps, and this is where I found results.
The 3.3v pin supplied more than the 250mA my meter can test
The other pins supplied around 35-40mA


HUGE difference. Is anyone else getting this? And can anyone explain why this happens?

Also, now I think I either need to get relays with a 3.3v coil, or some level shifters. :(

User avatar
joan
Posts: 15949
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: 3.3v pins supply more amps than other pins

Sat Jul 27, 2013 4:53 pm

On the Pi there are gpios and there are power rails and there are ground rails.

A power rail such as the 3.3V and 5V pins are nothing to do with the gpios.

You may well damage the gpios if you try to drive relays or motors directly from them.

smithg400
Posts: 152
Joined: Sat Dec 24, 2011 3:37 pm

Re: 3.3v pins supply more amps than other 'Controllable Pins

Sat Jul 27, 2013 5:05 pm

The 3.3V and 5V rails come directly from the output of the power supply. The power supply is capable of providing a reasonable amount of current.

The GPIO pins come directly from the processor on the Raspberry Pi and inside the processor are effectively two switches (transistors) which connect the GPIO pin to either the GND rail or the 3.3V rail depending which one is switched on. However they are quite small transistors and can't carry a great deal of current - as joan says, if you try and take too much current they will overheat and blow up and may take other parts of the processor with them (=dead Raspberry Pi). You need some circuitry designed to drive relays between the GPIO pin and the relay.

TheWalkingCactus
Posts: 14
Joined: Fri Mar 29, 2013 7:53 pm

Re: 3.3v pins supply more amps than other pins

Sat Jul 27, 2013 5:06 pm

joan wrote:On the Pi there are gpios and there are power rails and there are ground rails.

A power rail such as the 3.3V and 5V pins are nothing to do with the gpios.

You may well damage the gpios if you try to drive relays or motors directly from them.

So I should have the positive line coming from one of the 3.3v pins, but how would I control it? I know nothing about the GPIO inputs, can they act as a toggle-able ground?

And thanks for the quick reply

TheWalkingCactus
Posts: 14
Joined: Fri Mar 29, 2013 7:53 pm

Re: 3.3v pins supply more amps than other 'Controllable Pins

Sat Jul 27, 2013 5:10 pm

smithg400 wrote:If you try and take too much current they will overheat and blow up and may take other parts of the processor with them (=dead Raspberry Pi). You need some circuitry designed to drive relays between the GPIO pin and the relay.
I was looking into buying these relays: http://www.sainsmart.com/arduino-compat ... logic.html

and I saw that they had some circuit diagrams for rasp-pi capatability. (https://docs.google.com/file/d/0B5-HND9 ... VyODA/edit)

Is that the sort of thing you are talking about?

User avatar
joan
Posts: 15949
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: 3.3v pins supply more amps than other 'Controllable Pins

Sat Jul 27, 2013 5:12 pm

You can't control the power rails. They are on as long as the Pi is switched on.

http://elinux.org/Rpi_Low-level_peripherals

The gpios can be on or off but you should aim to use only a few milliamps from them. You should use the gpios to control transitors or other ICs or driver boards etc.

masterdrain
Posts: 36
Joined: Fri Jun 07, 2013 7:44 pm
Location: Isle of Wight

Re: 3.3v pins supply more amps than other 'Controllable Pins

Sat Jul 27, 2013 6:10 pm

I use a ULN2003A as a buffer (commonly used for driving stepper motors). On my setup, each pin takes 0.8mA at 3V3 and thus does not harm the GPIO. The IC is rated at 500mA total but a single channel can sink up to 500mA - they are open-collector, so a 3.3V high on the input takes the output low so that it can sink the current. I built the lot on a Humble Pi board along with four monitor LEDs (transistor driven so general purpose), a 555 monostable so that I can see very short pulses and a 3V3 regulated supply. It's not pretty but it works as a prototype!

Iain Johnstone

TheWalkingCactus
Posts: 14
Joined: Fri Mar 29, 2013 7:53 pm

Re: 3.3v pins supply more amps than other 'Controllable Pins

Sat Jul 27, 2013 8:03 pm

joan wrote:You can't control the power rails. They are on as long as the Pi is switched on.
Sorry, I meant how can I open/close the circuit. Can the GPIO inputs act as a ground that can be turned on and off? Or do they only test for an input?

smithg400
Posts: 152
Joined: Sat Dec 24, 2011 3:37 pm

Re: 3.3v pins supply more amps than other 'Controllable Pins

Sat Jul 27, 2013 8:22 pm

The GPIO pins can be configured as inputs which allow you detect what you input to them is either high or low (but the input should not go outside the 0V-3.3V range else you'll probably damage he chip), or configured as outputs which can be switched high (~3.3V) or low (~0V). The circuit diagram you posted the link to shows an external transistor being used as a switch - which is controlled by the GPIO output from the Pi. When the GPIO output is high the transistor is on and the current flows, when the GPIO is low the transistor is off and no current flows. The one resistor (2.2k) limits the current flowing out of the GPIO pin, making sure it is not too much for the GPIO to source but enough to turn the transistor on, the second (10k) makes sure the relays stay off if the Pi is not connected. The transistor is just much 'beefier' than the ones in the Pi's cpu so can carry more current. The ULN2003A that masterdrain mentions is effectively just 7 quite beefy trasnsistors in a single package which is useful if you have several relays to control. They also have a diode which helps protect the circuit when the relay turns off from the potential large voltage spike that can occur due to back EMF. Hope that helps.

TheWalkingCactus
Posts: 14
Joined: Fri Mar 29, 2013 7:53 pm

Re: 3.3v pins supply more amps than other 'Controllable Pins

Sat Jul 27, 2013 8:37 pm

smithg400 wrote:The GPIO pins can be configured as inputs which allow you detect what you input to them is either high or low (but the input should not go outside the 0V-3.3V range else you'll probably damage he chip), or configured as outputs which can be switched high (~3.3V) or low (~0V). The circuit diagram you posted the link to shows an external transistor being used as a switch - which is controlled by the GPIO output from the Pi. When the GPIO output is high the transistor is on and the current flows, when the GPIO is low the transistor is off and no current flows. The one resistor (2.2k) limits the current flowing out of the GPIO pin, making sure it is not too much for the GPIO to source but enough to turn the transistor on, the second (10k) makes sure the relays stay off if the Pi is not connected. The transistor is just much 'beefier' than the ones in the Pi's cpu so can carry more current. The ULN2003A that masterdrain mentions is effectively just 7 quite beefy trasnsistors in a single package which is useful if you have several relays to control. They also have a diode which helps protect the circuit when the relay turns off from the potential large voltage spike that can occur due to back EMF. Hope that helps.
Alright, thanks a ton. I think I'm all set now :)

User avatar
Tage
Posts: 287
Joined: Fri May 24, 2013 2:29 am
Location: St Thomas, Ontario Canada

Re: 3.3v pins supply more amps than other 'Controllable Pins

Sat Jul 27, 2013 9:29 pm

I had a look at the data sheet for the relays that are shown in the pictures, and I do not recommend anyone to use these relays in any circuit that has the relay contacts connected to the mains voltage.

The dielectric strength is listed as 1500Vac while the safety requirement is 3000Vac (or 4242Vdc). The hipot test is to be done from relay contacts to the coil pins. It is also unlikely that the creepage/clearance distances inside the relay or on the circuit board meets the minimum 4mm that is required by electrical safety regulations.

It would be OK to use these relays for controlling loads powered by a 12V battery but it is definitely not OK to control loads connected to the mains ac voltage. The circuit does not have the necessary isolation. This type of relay may be used inside a machine where no one can access the circuitry that connects to the relay coil. In an application such as using the Pi to control ac loads, reinforced isolation must be used. If the relay board is placed in a location where dust can accumulate, or there is high humidity, even 4mm creepage/clearance is not enough.

I also looked at the schematic for these relay boards, and to me the circuit looks weird. For example, who would connect an opto isolator in this way? Unless the power supply for the coil is kept isolated from the Pi, it does not make much sense. And there is no path for the leakage current in the opto isolator transistor. if the leakage current is high enough it can turn on the npn transistor. there should at least be a resistor from base to emitter on the npn driver for the relay coil.

the opto isolator can easily have a micro ampere or more leakage current even if there is no current in the input LED. if the npn driver has high current gain (and there is no resistor from base to emitter) we could have a situation where the relay coil gets enough current so that it will not drop out and open the contact. most relays are such that once you have applied enough coil current so that the contact closes, you have to drop the coil current to a very low value (10% or less of the normal current) before the contact will open.

Return to “Interfacing (DSI, CSI, I2C, etc.)”