11

In most examples I've seen of wiring buttons to GPIO inputs, the button is wired so that when closed, a circuit is completed between the pin and ground, producing a low input on the pin. A pull-up resistor is used to default the input value to high. Code on the Pi can then detect low as a button push.

I've been connecting the buttons to +3.3v so the signal is high as this seems to make more sense and keeps the code more logical but there must be a reason that most people favour connecting to ground. What are the advantages?

  • Note: When I say 'pull up resistor' I meant either a physical external resistor or the internal pull-up resistor, configured in code. – howard10 Sep 10 '13 at 9:15
15

One of the main reasons why wiring buttons and logic to GND is favoured (and then copied all over the internet) is because of power optimization.

  • Pulling a pin LOW with resistor to GND costs 0 watts.
  • Pulling a pin HIGH with resistor to +Vcc costs power.

On complex circuits or circuits that rely on batteries this power is very precious.

Other reasons include low EMF generation. On Wireless devices pulling logic high will cause unnecessary cross talk on extremely sensitive RF receivers. On such transceivers there is a GND plane used to filter noise and this is where all logic gets pulled down to. The processor then uses the GND plane to filter switching noises.

  • 2
    How does pulling up or down with a resistor cost any power? The current is flowing to a very high impedance input on the Pi, which is going to reduce any current down to sub-microAmps, which is microWatts of power. – stefandz Aug 13 '15 at 16:45
  • OK, but just tell me if I am wrong. pulling a pin down, which is 0v = 0watts usage, but pulling a pin up >0watts - any kind, micro, milli, nano, doesnt matter. As is mentioned, on battery power every nano watt helps. But as already answered here... on USB it means nothing. Am I mistaken? – Piotr Kula Aug 13 '15 at 16:48
  • 1
    Not necessarily true. Digital inputs are high impedance to ground - true. But they are not just resistors. They are input gates, normally to FETs and these gates are non-ideal. They have leakage currents, and these leakage currents can be in either direction, in or out. Hence your pulldown could well consume a microwatt or two, just as much as a pullup could. – stefandz Aug 13 '15 at 16:52
  • If you had to design an embedded device that ran on 2AA batteries and the customer demands it runs for at least 12 months. And you have to pull down/up a GPIO. Which would you use to save the most power. (We talking micro management here) – Piotr Kula Aug 13 '15 at 16:55
  • 3
    For what it is worth, I did some measurements on this - and pulldown wins (for power consumption) but only just. 10k pullup to 3.3V = 9fW (yes femtowatts) - 10k pulldown to ground = 5fW. This is certainly not even in saving a bit of battery territory. – stefandz Aug 14 '15 at 15:39
8

There are complex historical reasons why electrical engineers typically pulled inputs high with resistors, and used switches to ground them.

However these reasons are not particularly relevant to the hobby use of the Raspberry Pi. Use whatever makes sense to you.

If you are making a commercial product, or want your design to be slightly better, you'll choose pull-ups with a grounding switch for the following practical reasons:

  • A long ground wire poses less EMI/EMC radiation risk than one connected to power
  • Grounding something, and finding a ground point to connect to, is easier than a power line
  • If the switch or wiring, typically placed some distance away from the circuit, becomes damaged and either shorts the wire or internal switch parts to the case or the user, no harm is done - it's all at ground
2

Strictly there is no need for a pull-up resistor, the BMC GPIO has internal pull-up resistors which are activated when programmed as an input, although it does no harm.

It is poor practice to connect a GPIO pin directly to either 3V3 or GND. The GPIO is bidirectional, and if programmed as an input this would cause no problems. On the other hand if programmed as an output will cause excessive current to be drawn.

Good (safe) design would use a series resistor ( 1 kΩ ) in series with the pushbutton to limit current. For the reasons made by Adam Davis, it is preferable to connect the pushbutton to ground, and locate the protective resistor close to the GPIO pin.

  • The only problem is that during boot phases 1-3 these pins are floating (GPU to CPU handover) then on Phase 4 during Linux Kernel boot the PINs are set to the correct state. This can cause serious issues with gates waiting for logic. So it is advisable to pull them down anyway so that the floating period during boot does not make your circuits go mental! – Piotr Kula Sep 11 '13 at 15:51
1

I don't think there is a reason to prefer one over the other on the RPi. Most people are probably just copying or porting circuits they have seen elsewhere.

When connecting up the circuit (with wires or PCB) it's fine to just pick whichever is more convenient and translate it to the right meaning in your software.

0

In the old days of TTL it took far more current to pull a pin low than to pull it high. So a pullup resistor could be higher resistance (and hence less power-wasting) than a pulldown resistor. It doesn't matter with modern CMOS but old habits die hard.

-1

Connecting the pin to ground with an internal pullup resistor means you use less parts. All you need is a button; don't need an external resistor to limit current.

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.