dirkwillem
Posts: 10
Joined: Tue Feb 12, 2013 11:56 am

gpio with python - input voltage

Wed Feb 13, 2013 12:45 pm

Hello

I'm starting with GPIO programming in python, and I can light a led and do that in a pattern, but now I want to use the input with a button.

My question is: can I directly give the 3.3 volt the pi gives back to an input pin, or do I need to use a resistor(and how much ohm)?

DirkWillem

texy
Forum Moderator
Forum Moderator
Posts: 5162
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: gpio with python - input voltage

Wed Feb 13, 2013 12:59 pm

Hi Dirk,
a resistor would be safer, but not essential. The value is not too critical, anything from 1K to 10K would be sensible values. Also don't assume that the line will be at 0volts when not connect via the switch to 3v3. If the line is floating, it may give unpredictable results. I would recommend you use either internal or external pull up or down resistors to maintain the correct 'off' voltage level.
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

User avatar
Grumpy Mike
Posts: 943
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
Contact: Website

Re: gpio with python - input voltage

Wed Feb 13, 2013 10:08 pm

a resistor would be safer, but not essential.
You need a resistor somewhere. Read this, it was written for the Arduino but it applies to other things as well. Just replace 5V with 3V3.
http://www.thebox.myzen.co.uk/Tutorial/Inputs.html

texy
Forum Moderator
Forum Moderator
Posts: 5162
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: gpio with python - input voltage

Wed Feb 13, 2013 10:20 pm

Yes a pull up or pull down, either internal or external, I agree. But an inline series resistor? What are you thoughts?
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

Gustavo_Murta
Posts: 24
Joined: Thu Dec 20, 2012 10:04 am
Location: Brasil

Re: gpio with python - input voltage

Wed Feb 13, 2013 11:54 pm

Dirk if you wish to use only a button, use a pullup resistor of 10K ohms.
If you dont use it , the input will float.

IMPORTANT CAUTION: (from RPI Wiki page) :
GPIO voltage levels are 3.3 V and are not 5 V tolerant. There is no over-voltage
protection on the board - the intention is that people interested in serious interfacing
will use an external board with buffers, level conversion and analog I/O rather than
soldering directly onto the main board.

If you need interface 5V level circuits, use opto couplers or Buffers to down-converted to 3.3V logic levels. I think you can use 74HC4050, but source power must be 3,3V, not 5V.

Gustavo (Brasil)

sej7278
Posts: 249
Joined: Tue Jan 22, 2013 6:43 pm

Re: gpio with python - input voltage

Thu Feb 14, 2013 12:14 am

Gustavo_Murta wrote:Dirk if you wish to use only a button, use a pullup resistor of 10K ohms.
If you dont use it , the input will float.
yes i've noticed that - i followed quite a few tutorials which didn't use a 10k pull-up and it simply did not work - the button press was not detected.

i also use a 1k series resistor on gpio inputs but its not 100% needed as the gpio pins already have a small resistors inline as i understand, but hey its a 1k resistor, often easier to use than making up jumper wires on the breadboard :mrgreen:

User avatar
Grumpy Mike
Posts: 943
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
Contact: Website

Re: gpio with python - input voltage

Thu Feb 14, 2013 5:09 pm

sej7278 wrote:i also use a 1k series resistor on gpio inputs but its not 100% needed as the gpio pins already have a small resistors inline as i understand, :mrgreen:
No there is no internal series resistance for inputs. Maybe you are mixing this up with the concept of drive capacity for a pin when used as an output. This is often modeled by a theoretical series resistor but it is not real. See:-
http://www.thebox.myzen.co.uk/Raspberry ... tputs.html
I would go further and say that not only is a 1K series resistor not 100% needed, I would say it is not even 1% needed. The only protection it could offer is if you were dumb enough to set the pin as an output and then set that output high and then bush a button that grounded the pin. So that is three things going wrong, normal safety legislation only requires you to consider one thing going wrong.
Protection against that is best done with a 330R resistor as it minimizes the degradation of the input pin's characteristics.

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

Re: gpio with python - input voltage

Thu Feb 14, 2013 8:26 pm

Grumpy Mike wrote:
sej7278 wrote:i also use a 1k series resistor on gpio inputs but its not 100% needed as the gpio pins already have a small resistors inline as i understand, :mrgreen:
No there is no internal series resistance for inputs. Maybe you are mixing this up with the concept of drive capacity for a pin when used as an output. This is often modeled by a theoretical series resistor but it is not real. See:-
http://www.thebox.myzen.co.uk/Raspberry ... tputs.html
I would go further and say that not only is a 1K series resistor not 100% needed, I would say it is not even 1% needed. The only protection it could offer is if you were dumb enough to set the pin as an output and then set that output high and then bush a button that grounded the pin. So that is three things going wrong, normal safety legislation only requires you to consider one thing going wrong.
Protection against that is best done with a 330R resistor as it minimizes the degradation of the input pin's characteristics.
Total agreement from me, series resistors are for those who try to contact silly voltages to inputs..

For all other things it is overkill. Sometimes makes things worse as low signals do not go low enough at Pi pin to be recognised.
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

Return to “Python”