# Detect multiple button presses on circuit

I am totally new to using the Raspberry Pi. Right now I am trying to determine if a Pi could be used to solve my problem or not.

I am trying to detect multiple buttons pressed. With this I also want to know which button was pressed, if multiple buttons were pressed at the same time, and I want to know all the buttons that were pressed. I also need a breadboard or some components where I can possibly connect up to 100 or 200 buttons or what is the max number of buttons I can connect and detect the changes?

How could I do this and what are physical components that I would need?

• you could connect more than 100000 buttons ... you said nothing about how responsive the buttons should be Jun 22, 2019 at 3:01
• How many simultaneous presses do you need to be able to reliably identify? Jun 22, 2019 at 6:53

Question

1. How can Rpi be used to detect multiple buttons?

2. Can Rpi detect 200 butons or even more?

Now problem for Rpi to detect 256 keys or even more.

The EE guys usually wire the buttons, say 256, into a 16 x 16 button/key matrix. A couple of years ago I read a MagPi article introducing an GPIO expander called MCP23008. I found MCP23008 very interesting and read the datasheet and application note. The app note explains in details how to use MCP23008 to detect a 4 x 4 keypad, and the program to scan the keypad. I goggled one and also found many Arduino C++ programs using GPIO or MCP23017 for 8 x 8 key pads.

For newbies, I usually recommend not to start with MCP23008/MCP23017, because their learning curve is very steep.

I would suggest to:

start testing as simple as possible:

using only 2 Rpi GPIO pins to detect 4 buttons.

The principle of doing 2 x 2 = 4 keys is exactly the same for 16 x 16 = 256 keys. You might like to read my answers to the following posts to get a rough idea of what I am talking about.

Multiple GPIO Buttons

Connecting 32 Magnetic Sensors

There are many solutions you can use, as far as the number it is not realy limited. The maximum depends on the solution you pick. A keyboard matrex gets complicated as the number of keys pressed increases. For this you want to look at N-key rollover as you want to detect many switches closed concurrently. The "n" might be replaced with a number, that is the number of simultaneous key presses it will resolve.

Another option is a port expander such as the PCF8574 etc which use the I2C. There are other chips that will expand I believe upto 64 inputs. For example the MC33972 will do I beleive 22 switches using the SPI interface.

A simple and inexpensive way is to use lots of shift registers. You can cascade them to as many bits as you want. These work very well and can be bitbanged or setup with the SPI.