2

I am trying to take input from twelve different buttons with my Raspberry Pi Zero W.

I have enough GPIO Pins for this, but not enough GND pins, so I decided to make some of the pins pulled low by default so that I could also make use of the 3v3 pins.

Even so, I fell two pins short. How could I use twelve buttons?

I considered using an always on GPIO pin as a 3v3 pin. Would this be safe? I read that using a GPIO pin that's off as GND is unsafe, that's why I am asking. If not, is there some HAT or something else I could do?

asked Apr 8, 2023 at 19:57

3 Answers 3

6

You can connect all the grounds to one pin. There is no need to have a separate ground for each GPIO.

answered Apr 8, 2023 at 20:17
4
  • Oh, lol, silly me. Commented Apr 8, 2023 at 20:21
  • Wait, so in what scenario may I need more than one GND? I ask because I am wondering why RPi even built in eight GNDs when you only need one. Commented Apr 9, 2023 at 21:31
  • They provided the grounds for convenience. It might have been more convenient to provide more 5V and 3V3 power pins instead. Commented Apr 9, 2023 at 21:52
  • 1
    @XboxOne Convenience mainly, but a little bit also for signal isolation. For low speed GPIO it doesn't matter at all. But when you use IO ports like SPIO, serial or I2C you usually want to dedicate one GND solely for each, so their high speed switching doesn't interfere with the ground returns of other signals and vice versa. It is not strictly necessary, but generally a good idea because it increases reliability. But the grounds are all ultimately connected together on the RPi PCB. Commented Apr 9, 2023 at 21:54
1

Key question: Do the buttons have to operate totally independently? Or are they all for input by one user or in some other way reasonably certain that only one will be pressed at a time?

If you only need one at a time (think: computer keyboard, telephone keypad) then the general solution to this problem, going back to the first 8-bit computers in the 1970s, is to use a keyboard matrix. For 12 buttons, that is a matrix of 3x4, so 7 GPIO pins instead of 12. 8 GPIO pins gets you 4x4 = 16 buttons, etc.

A quick search found an example of this here.

answered Apr 9, 2023 at 18:23
1
  • 1
    Oh this is cool, yes only one will be pressed at a time. A keyboard matrix will help me reduce the number of wires I will need, but now that I know that I only need one GND, it doesn't relate to that issue. +1 Commented Apr 9, 2023 at 21:29
1

You could use a MCP3008 (MCP3008 and Raspberry Pi Zero) and a single analog input for as many buttons as you want (limited by the commercial values of resitors: https://fritzenlab.net/2024/04/01/analog-input-keypad-with-arduino/ ).

The "secret" I explain in the blog post is to make every button cause a different voltage to the AD converter, so that you can programmatically determine which was pressed.

answered Apr 25, 2024 at 13:46
1
  • You can also use a sledgehammer to crack a nut but it is overkill. Commented Apr 26, 2024 at 6:40

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.