Page 1 of 1

GPIO and Buttons

Posted: Tue Mar 25, 2014 11:35 am
by PhillyNJ
Hi,

I have seen a few tutorials online on hooking up a button to a GPIO pin. Some use a pull-up resistor and some don't. If I'm sending 3.3v to the GPIO pin, do I need a resistor or not?

Thanks

Phil

Re: GPIO and Buttons

Posted: Tue Mar 25, 2014 11:44 am
by joan
You don't need one but it will be safer if you use one. If the gpio is mistakenly configured as an output you may short 3V3 to ground without a resistor.

Re: GPIO and Buttons

Posted: Tue Mar 25, 2014 11:49 am
by PhillyNJ
joan wrote:If the gpio is mistakenly configured as an output you may short 3V3 to ground without a resistor.
Thanks. if that was to happen, what damage to the Pi would/could happen?

Re: GPIO and Buttons

Posted: Tue Mar 25, 2014 11:55 am
by Burngate
If the button (switch) is connected between the GPIO and ground, when it's pressed, there'll be 0v on the GPIO.
But when it's not pressed, there's nothing to tell the GPIO what voltage to be at - it could be 0, it could be 3v3, it could be somewhere in between.

The pull-up resistor tells the GPIO what to do if the switch isn't closed.
In that respect, the tutorials that aren't using a pull-up are wrong - though they could be relying on the Pi's built-in pull-ups

Re: GPIO and Buttons

Posted: Tue Mar 25, 2014 12:01 pm
by Burngate
PhillyNJ wrote:
joan wrote:If the gpio is mistakenly configured as an output you may short 3V3 to ground without a resistor.
Thanks. if that was to happen, what damage to the Pi would/could happen?
Best case, nothing. Worst case, the transistors inside the SoC driving the pin would be overloaded, and the silicon would melt. No more Pi.
The latter is more likely than the former.

1) Use a pull-up, either real or the internal software-controlled.
2) Put a resistor between the Pi and your button

Re: GPIO and Buttons

Posted: Tue Mar 25, 2014 12:06 pm
by joan
PhillyNJ wrote:
joan wrote:If the gpio is mistakenly configured as an output you may short 3V3 to ground without a resistor.
Thanks. if that was to happen, what damage to the Pi would/could happen?
I don't know. At a guess something between a Pi reset (caused by the 3V3 supply falling too low to power the CPU) to a burned out gpio to a burned out bank of gpios to a burnt out Pi.

Re: GPIO and Buttons

Posted: Tue Mar 25, 2014 12:28 pm
by pluggy
There will be a pull up/down resistor involved in the circuit. Some will use a physical resistor and some will use the internal software pull up/down resistor. Without either the pin is floating and the condition of the pin with the switch open circuit is ambiguous.

It all depends if you want it to work or not.

The pull up/down resistor isn't going to save anything if you program it as output, set the pin high and then have a hard switch pulling it low. (Or vice versa). The resistor doesn't enter into the equation, its a short circuit with or without it.

Re: GPIO and Buttons

Posted: Tue Mar 25, 2014 1:00 pm
by iinnovations
To be clear, OP, a pullup or pulldown is not in series with your button/ peripheral. It is attached at the point where the button would connect to your gpio, either internally or externally. The other end of the pullup/down is then connected to 3.3v (pullup) or ground (pulldown). This defines logic state when the button is not pressed. The other end of the button is connected to the logical opposite of the pull-up / down resistor. If you're using a pull-up, for example, this would be ground.

The resistor used to protect the gpio is a current-limiting resistor. It is placed in series with the button (between the gpio and button or between the button and 3.3v or ground).

The value of either if these resistors can be quite high unless you are also trying to drive something like an led that requires some current. Typical pull-up and pulldown values are 10k, and an inline current limiter in this case just needs to be small enough to overcome the pulldown and get the input voltage suitably low or high. From very preliminary googling it appears these values are 0.8V and 1.3V. A 1k resistor would bring you 0.3V or 3.0V, so you'd be good there and limit you to 3.3mA on a button press to ground. Just make sure to keep it under 15mA!

Colin

Re: GPIO and Buttons

Posted: Tue Mar 25, 2014 1:11 pm
by PhillyNJ
Thanks all. I will go the safe route and add resistors. Better safe than sorry.

Re: GPIO and Buttons

Posted: Tue Mar 25, 2014 1:38 pm
by pluggy
If you're making it safe with a resistor then its not a pull up, its a current limiter and is wired differently. A pull up won't save you if you screw up the in/out bit.

Image

Re: GPIO and Buttons

Posted: Tue Mar 25, 2014 1:44 pm
by trippes
Hi all
this is a similar post to mine - but with many more answers - which is great :-). I have no intention/desire to hijack this post but I would like to add in my thoughts

I think I now understand - the resistor offers protection to the pi in case voltage "in/out" is configured correctly. However, if the configuration of the pi is never going to change - (all it will do is run some code when the button is pressed) - then, providing it is configured correctly the first time, am I right in saying the risk is minimal ?

obviously if people were able to access the pi and change parameters - I think the resistor would be essential

Or have I fundamentally misunderstood .... again :-)
cheers

Re: GPIO and Buttons

Posted: Tue Mar 25, 2014 1:54 pm
by pluggy
trippes wrote:Hi all
this is a similar post to mine - but with many more answers - which is great :-). I have no intention/desire to hijack this post but I would like to add in my thoughts

I think I now understand - the resistor offers protection to the pi in case voltage "in/out" is configured correctly. However, if the configuration of the pi is never going to change - (all it will do is run some code when the button is pressed) - then, providing it is configured correctly the first time, am I right in saying the risk is minimal ?

obviously if people were able to access the pi and change parameters - I think the resistor would be essential

Or have I fundamentally misunderstood .... again :-)
cheers
Nope, a resistor wired as a pull up has no protection value whatever. The pin is wired directly to ground if the switch is closed.

Image

Now if you had a larger value pullup resistor and a smaller value current limiter, that would be a different story. You have to be careful with the values because its a voltage divider when the switch is closed.

Re: GPIO and Buttons

Posted: Tue Mar 25, 2014 2:09 pm
by iinnovations
trippes wrote:Hi all
this is a similar post to mine - but with many more answers - which is great :-). I have no intention/desire to hijack this post but I would like to add in my thoughts

I think I now understand - the resistor offers protection to the pi in case voltage "in/out" is configured correctly. However, if the configuration of the pi is never going to change - (all it will do is run some code when the button is pressed) - then, providing it is configured correctly the first time, am I right in saying the risk is minimal ?

obviously if people were able to access the pi and change parameters - I think the resistor would be essential

Or have I fundamentally misunderstood .... again :-)
cheers
Please read my post above. Both are defined.