Janion
Posts: 11
Joined: Tue Jul 17, 2012 7:28 pm

GPIO current limits

Sun Sep 02, 2012 12:45 pm

I wasn't sure exactly where to ask this.

I have looked around but I can't find what I am looking for.
Can anybody tell me what the lower current limit would be for the pi to sense an input from a gpio pin?

I want to use an LDR to sense a light source being covered but I need to know what the limits are of the inputs before I can build it.

Also am I correct with the 3v3 pin being able to output up to 50mA, and a simple pin being able to input up to 15mA?

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
Contact: Website

Re: GPIO current limits

Sun Sep 02, 2012 12:46 pm

I'm using an ORP12 LDR and it detects it light/dark fine (with the GPIO software controlled pull-up resistor enabled) :)

You really need to approach the GPIO pins as delicate little baby fingers - they really need coupling up to a buffer if you are going to so anything more than ideas testing - a ULN2003 buffer costs 0.37p :)

Yep - those are the limits but you don't want to be getting anywhere close to them as as you'll have a long wait to get another RPi :)

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

Janion
Posts: 11
Joined: Tue Jul 17, 2012 7:28 pm

Re: GPIO current limits

Sun Sep 02, 2012 3:35 pm

simplesi wrote:I'm using an ORP12 LDR and it detects it light/dark fine (with the GPIO software controlled pull-up resistor enabled) :)

You really need to approach the GPIO pins as delicate little baby fingers - they really need coupling up to a buffer if you are going to so anything more than ideas testing - a ULN2003 buffer costs 0.37p :)

Yep - those are the limits but you don't want to be getting anywhere close to them as as you'll have a long wait to get another RPi :)

Simon
Thanks for the reply but I'm afraid you are talking a little bit above my knowledge.
Could you please just define a few terms for me?
-Pull up resistor (and how do you control that with the gpio)
-buffer

Also where do you get components from? At the moment I could only think of Maplin

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
Contact: Website

Re: GPIO current limits

Sun Sep 02, 2012 4:00 pm

Pull up resistor
A pullup resistor just "pulls" the input up to 3.3V when its not connected to anything else. So you start off from a known state in that it is at 3.3V.

To change this, you connect a low resistance (330 ohm is a good value as it limits the max current to about 10ma) to the pin and other end to 0V (Pin 6 on the RPi).

This lower value resistor causes the voltage on the pin to go down to near 0V and your software can detect this.

Its generally held to be a good way to be nice to electronic components even though its usually the opposite way that a beginner would try to do things.
(and how do you control that with the gpio)
Your software usually has a setting to do this and in python ends up as

Code: Select all

import RPi.GPIO as GPIO

# to use Raspberry Pi board pin numbers
GPIO.setmode(GPIO.BOARD)

# set up GPIO input with pull-up control
GPIO.setup(11, GPIO.IN, pull_up_down=GPIO.PUD_UP)

# input from RPi board pin 11
input_value = GPIO.input(11)
buffer[/buffer]

A buffer protects the RPi from mistakes on the equipment side - search around here for info on ULN2003A for better people than me to tell you about it search for user joan :)
Also where do you get components from? At the moment I could only think of Maplin
Best way to get bits is online - cpc.co.uk are a cheap place but there are many others

Here is a link to a homebrew buffer board http://www.thebox.myzen.co.uk/Raspberry ... Board.html
Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

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

Re: GPIO current limits

Mon Sep 03, 2012 8:48 am

Janion wrote:... I could only think of Maplin
If you've got a Maplin shop near you the guys there are usually very helpful. Also their catalogue (although it costs) can be a fund of knowledge.

As Simon says, CPC (part of Farnell, MCM in the US) are good. And RS is another place.

Otherwise, for more out-of-the-ordinary parts, there are lots of places on line

TarjeiB
Posts: 157
Joined: Thu Jul 12, 2012 3:33 pm

Re: GPIO current limits

Mon Sep 03, 2012 6:11 pm

So wait... To get my GPIO pin at LOW to be 0V I need to bridge it to GND with a 330ohm resist?

I've just tested a relay and it turned on with 152mV on the GPIO pin which is it's LOW state, so I'm missing a resistor?

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
Contact: Website

Re: GPIO current limits

Tue Sep 04, 2012 9:30 am

So wait... To get my GPIO pin at LOW to be 0V I need to bridge it to GND with a 330ohm resist?
I am talking using a pin as an input :)
To prevent any disasters happenig, ITS ALWAYS a good idea to connect to the pins through a resistor that limits the amount if current that COULD flow 3.3/330 = 10mA which is safe if just using one pin

I've just tested a relay and it turned on with 152mV on the GPIO pin which is it's LOW state, so I'm missing a resistor?
If using your RPi to turn the relay on, then you need a resistor to limit the amount of current that could flow through the coil of the relay.

If your controlling the relay by something else and your connecting the switch contacts to your RPi then you need a resistor as explained above.

If in ANY doubt - stick a 330ohm resistor in - it might not need it but you'll never blow your RPi up :)

Simon
PS Not the world's greatest electronics engineer BTW but very experienced in blowing things up by not taking precautions and don't want to see anyone else crying :)
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: GPIO current limits

Wed Sep 05, 2012 1:48 pm

TarjeiB wrote:So wait... To get my GPIO pin at LOW to be 0V I need to bridge it to GND with a 330ohm resist?

I've just tested a relay and it turned on with 152mV on the GPIO pin which is it's LOW state, so I'm missing a resistor?
Hang on - you're connecting a relay directly to a GPIO pin? I'm guessing the other end of the relay is connected to +3.3v, so driving the GPIO pin low turns the relay on...

Have you checked the current going through the relay coil? I'd be VERY surprised it if were in the 16mA limit for the Pi's GPIO pins.

So unless it's a really really small, lightweight relay designed to be driven from 3.3v and take under 16mA then you shouldn't be directly connecting it to the Pi at all...

All this talk of randomly putting in resistors, really suggests that you don't actually know what's going on, and while I encourage experimentation, I'd really suggest you go out and get some basic electronics knowledge...

-Gordon
--
Gordons projects: https://projects.drogon.net/

TarjeiB
Posts: 157
Joined: Thu Jul 12, 2012 3:33 pm

Re: GPIO current limits

Wed Sep 05, 2012 1:56 pm

[email protected] wrote: So unless it's a really really small, lightweight relay designed to be driven from 3.3v and take under 16mA then you shouldn't be directly connecting it to the Pi at all...
-Gordon
Admittedly I do not have a clue, that's what I'm trying to get. I am, however, not playing randomly with the wires :) I read thoroughly beforehand, but alot of it is still difficult to grasp for now.

The relay coil is driven by the 5V pin to the collector of the transistor - the GPIO pin is connected to 1kohm then the base of the transistor. The Emitter is connected to the ground pin. I was quite confident this was how it was supposed to be.

Problem is, no matter the state of the GPIO pin, the transistor always seem saturated. Only if I set the pin direction to IN will it desaturate and relay will turn off.

techpaul
Posts: 1512
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
Contact: Website

Re: GPIO current limits

Wed Sep 05, 2012 3:20 pm

What transistor are you using?

Sounds to me like you have a PNP transistor in there (or other fault in your circuit)

You need an NPN transistor, for that type of switching I tend to use digital FETs like FDV303N which is capabling of handling 2A continuous current (Idd), and can be driven directly on the gate with a GPIO pin.

What are you switching with the relay?
Small signal switching or mains electricity?

The only relays I regularly use for 3V3 or 5V coil voltage (and buil-in diode) cannot handled large load voltages and currents Pickering relay series 101, coil current less than 8mA.
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

TarjeiB
Posts: 157
Joined: Thu Jul 12, 2012 3:33 pm

Re: GPIO current limits

Wed Sep 05, 2012 4:20 pm

techpaul wrote:What transistor are you using?
I have no idea - the writing is not visible and the manufacturer of the relay doesn't specify. However, it's a ready-made one and I can't find any solder flaws or other connection problems to my limited knowledge, on the board. It's this board.
I am also half-assuming it works correctly since disconnecting the GPIO pin turns the relay off, and also changing the direction to "in". But as long as it's "out" it will turn the relay on without fail.
techpaul wrote: Sounds to me like you have a PNP transistor in there (or other fault in your circuit)

You need an NPN transistor, for that type of switching I tend to use digital FETs like FDV303N which is capabling of handling 2A continuous current (Idd), and can be driven directly on the gate with a GPIO pin.

What are you switching with the relay?
Small signal switching or mains electricity?

The only relays I regularly use for 3V3 or 5V coil voltage (and buil-in diode) cannot handled large load voltages and currents Pickering relay series 101, coil current less than 8mA.
I'm currently switching nothing, just hearing the "click" and observing the LEDs. I will be switching 12v 1-2A if I can make it work...

*EDIT* somehow this got spread out on two threads - I meant to discuss it here: http://www.raspberrypi.org/phpBB3/viewt ... 00#p166700
since that's talking about the similar board :)

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: GPIO current limits

Wed Sep 05, 2012 4:43 pm

TarjeiB wrote:
techpaul wrote:What transistor are you using?
I have no idea - the writing is not visible and the manufacturer of the relay doesn't specify. However, it's a ready-made one and I can't find any solder flaws or other connection problems to my limited knowledge, on the board. It's this board.
I am also half-assuming it works correctly since disconnecting the GPIO pin turns the relay off, and also changing the direction to "in". But as long as it's "out" it will turn the relay on without fail.
techpaul wrote: Sounds to me like you have a PNP transistor in there (or other fault in your circuit)

You need an NPN transistor, for that type of switching I tend to use digital FETs like FDV303N which is capabling of handling 2A continuous current (Idd), and can be driven directly on the gate with a GPIO pin.

What are you switching with the relay?
Small signal switching or mains electricity?

The only relays I regularly use for 3V3 or 5V coil voltage (and buil-in diode) cannot handled large load voltages and currents Pickering relay series 101, coil current less than 8mA.
I'm currently switching nothing, just hearing the "click" and observing the LEDs. I will be switching 12v 1-2A if I can make it work...

*EDIT* somehow this got spread out on two threads - I meant to discuss it here: http://www.raspberrypi.org/phpBB3/viewt ... 00#p166700
since that's talking about the similar board :)
OK. The way it's wired is to be active low. So set the GPIO to output and write 0 to turn the relay on, and write 1 to turn it off..

HOWEVER.... It's being fed from a 5v supply and that 5V will sink into a GPIO pin at 3.3v and likely destroy it (in time - you might be "getting away" with it for now).

You really need to undo that jumper and connect the input side to +3.3v and the drive side to +5v.

And is the module you have the same as those photos on ebay? I'm guessing there are compnents on the underside as there are not enough on the top side to match the circuit diagram given...

-Gordon
--
Gordons projects: https://projects.drogon.net/

TarjeiB
Posts: 157
Joined: Thu Jul 12, 2012 3:33 pm

Re: GPIO current limits

Wed Sep 05, 2012 5:06 pm

[email protected] wrote: OK. The way it's wired is to be active low. So set the GPIO to output and write 0 to turn the relay on, and write 1 to turn it off..

HOWEVER.... It's being fed from a 5v supply and that 5V will sink into a GPIO pin at 3.3v and likely destroy it (in time - you might be "getting away" with it for now).

You really need to undo that jumper and connect the input side to +3.3v and the drive side to +5v.

And is the module you have the same as those photos on ebay? I'm guessing there are compnents on the underside as there are not enough on the top side to match the circuit diagram given...

-Gordon
Thanks for the input - putting the reply here:
http://www.raspberrypi.org/phpBB3/viewt ... 00#p166700

Return to “HATs and other add-ons”