3

I saw a tutorial here that shows wiring a button without a resistor. I have heard that this is bad if you set the pin as an output by mistake and press the button because it shorts the pin to ground.

Besides that issue, can this be done with multiple buttons as long as I make sure to code it correctly? I read somewhere else that this only works with the I2C pins and thus can only work with a maximum of 2 buttons.

I am working with a Raspberry Pi b+, but I also have a Pi 3 available.

enter image description here

  • "I have heard that this is bad if you set the pin as an output by mistake" -> Probably. Note though that you can connect an output GPIO driven high directly to an input GPIO without a short...though this will end up gobbling up twice as many GPIOs. Resistors are cheap. You can probably get a lifetime supply online for $10. – goldilocks Jul 12 '16 at 19:17
  • I don't understand what you plan to do. Do you plan to connect multiple buttons to the same GPIO, so that any button press registers at the GPIO? You don't need external resistors although they do make thing safer. – joan Jul 12 '16 at 19:31
  • @joan I am doing multiple buttons each on separate GPIO. – NULL Jul 13 '16 at 18:19
  • @goldilocks I have a lifetime supply of resistors already but I have been wondering if I really needed them so I wanted to clear this up before I kept using them because it does save time and makes circuits simpler without them. – NULL Jul 13 '16 at 18:21
2

If the code is written correctly such that the GPIO pins are input only, you should not have an issue. However, the use of resistors may still be warranted ... but not to limit the current in case of bad coding but instead to pull the default state of a button to a logic level. When the button is "up", it is effectively an open circuit. What then is the logic level on the GPIO? If you don't have pull-up or pull-down resistors, then the logic level will "float" and you could have un-expected results which appear to be button presses when no button is pressed. You can code around that with the PI's logical pull-up and pull-down resistors. I believe the GPIOs allow us to say that a pin is input and should have a pull-up or pull-down resistor (logically) attached. I am guessing that in the circuitry there is the ability to engage internal resistors to achieve that capability.

  • "What then is the logic level on the GPIO?" -> I think possibly this is why NULL has the impression only I2C pins should be used this way (because of the big internal resistors)...although none of the pins in the diagram are such. – goldilocks Jul 12 '16 at 19:19
2

I know it's an old question, but I've been reading into the RPi's internal resistors. I'm hoping to use them in order to make my circuit a little bit simpler.

According to this answer there are pull up/down resistors on all of the GPIO pins on the Raspberry Pi B+ and later.

The circuit and program in the tutorial uses an internal pull-up resistor on an input pin. This means current is constantly supplied from the resistor which sets the open circuit to a logical HIGH. When the switch is engaged, it grounds the pull-up voltage which drops the circuit to a logical LOW. This is the opposite logical sequence to what most other circuits use where their buttons switch on the voltage, not the ground.

Tutorial (Button on GND):
HIGH: Open Circuit
 LOW: Closed Circuit

Typical (Button on 3V3):
HIGH: Closed Circuit
 LOW: Open Circuit

Now that being said, for the purposes of safety, I would still recommend a small resistor between the switch and pin if you can't be 100% confident in the software. Just in case the pin gets set to output, the resistor will be there to not let it short circuit to GND.

  • 2
    Hello and welcome! It is still noteworthy that it is two different things. 1) the pull-up/-down resistor is required to prevent the floating of the input pin (this resistor could be internal or external). 2) a series resistor between the pin and the switch. The latter is the one that prevents a short if the pin is configured output and the button is pressed. That is a feat the pull-up/-down cannot do. – Ghanima Feb 9 '18 at 17:46
  • Thanks for the welcome :) I apologize for not making that a clear distinction in my response. My last paragraph was meant to be a comment on the tutorial the original poster mentions. It shows no use of the safety resistor between the switch and pin. But yes, the two resistors serve completely different purposes. – flamewave000 Feb 9 '18 at 18:21
  • The GPIO are identical on all current Pi models. They all have internal pull-ups and pull-downs. – joan Feb 9 '18 at 18:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.