If the application is to read a large number of push buttons, then I would consider wiring them in a diode matrix instead, then you may not need any shift registers. For example, a 5 x 5 matrix and 25 diodes (or 5 diode networks) will let you connect 25 push buttons using 10 pins, and some of those pins can usually be shared with other devices such as LCDs.

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

I will have at least one 4x4 keypad, most likely two, so yes, a diode matrix might be more suitable. I've never worked with one, I just used code to scan trough the 4 rows one column at a time, not sure if the diode matrix has advantages?

Or maybe I should use one shift register per one 4x4 keypad matrix? i.e. hook up the matrix's 4 row and 4 column pins to the 8 pins on the shift register and then have Arduino code translate the output of the shift register?

I will have at least one 4x4 keypad, most likely two, so yes, a diode matrix might be more suitable. I've never worked with one, I just used code to scan trough the 4 rows one column at a time, not sure if the diode matrix has advantages?

The reason for using diodes is that with them, you can handle multiple keys being down at the same time. If you don't care about that, then you can omit the diodes. 4x4 keypads are typically wired internally as a matrix (without diodes) anyway. See the keypad library for how to drive them.

Or maybe I should use one shift register per one 4x4 keypad matrix? i.e. hook up the matrix's 4 row and 4 column pins to the 8 pins on the shift register and then have Arduino code translate the output of the shift register?

To drive a 4x4 matrix you need 4 outputs and 4 inputs, so you can't use a single 8-bit SIPO or PISO shift register.

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

The reason for using diodes is that with them, you can handle multiple keys being down at the same time. If you don't care about that, then you can omit the diodes.

Well you can do it without diodes as long as your code checks each row and column one at a time, i.e. row 1 column 1, row 1 column 2, row 1 column 3..... etc.... at least that's how I did it. Of course if you can press, hold and let go of multiple buttons simultaneously faster than the Arduino can run through all the row/column combination you'll have a problem... but can you be that fast?

Quote

To drive a 4x4 matrix you need 4 outputs and 4 inputs, so you can't use a single 8-bit SIPO or PISO shift register.

The reason for using diodes is that with them, you can handle multiple keys being down at the same time. If you don't care about that, then you can omit the diodes.

Well you can do it without diodes as long as your code checks each row and column one at a time, i.e. row 1 column 1, row 1 column 2, row 1 column 3..... etc.... at least that's how I did it. Of course if you can press, hold and let go of multiple buttons simultaneously faster than the Arduino can run through all the row/column combination you'll have a problem... but can you be that fast?

That doesn't completely work if 3 buttons are down and 2 of them are attached to the same row. For example, if buttons R1C1, R1C2 and R2C1 are pressed, then C1 is shorted to C2, so that both C1 and C2 activate both R1 and R2. So the code can tell that at least 3 of R1C1, R1C2, R2C1 and R2C2 are pressed, but not which ones. However, you can still detect that a problem exists, and stop registering keypresses until it goes away.

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Joe Young has a library that uses two SPI port expanders for matrix keypads.https://github.com/joeyoung/arduino_keypads/tree/master/Keypad_I2C

He includes documents, spec. sheets, and examples on how to connect and use the port expanders. Also, if you need to press more than one key at a time it might be wise to follow dc42's advice and use diodes. However, most people are just fine using keypads without diodes.

Note: If you only need a single key returned then use the Keypad_I2C getKey() method instead of the getKeys() method which is multi-key.