Is there any way to interface 4×4 matrix keypad using 2 IO lines

I have two IO lines and wants to interface 4×4 matrix keypad. Using MUX ICs I need 4 IO lines. Is there any method to achieve it using 2 IOs?



3 Answers


I have done it by using an I2C GPIO expander chip. I used the Microchip MCP23017, but there are others out there as well.



This would be the most straightfoward solution. These particular chips come in 8 bit and 16 bit versions, and the pins can be configured individually as inputs or outputs so you can easily scan an entire 4×4 keypad with one chip.
– alex.forencich
Sep 15 ’14 at 3:56

A serial interface could do the trick. An I2C-like interface could operate on only two I/O lines (Data and Clock). Utilizing shift registers would be possible using three I/O lines (Data-in, Data-out and Clock) in an SPI like mode (assuming to skip any chip select lines).



How would you do that without second shift register for column excitation?
– venny
Sep 14 ’14 at 23:01



Sorry, I was mistaken. Obviously you’d need three line data out, data in (MOSI/MISO) and clock in an SPI like mode. Two or more shift regs could be cascaded to do the column selection. However I2C should provide a two IO solution.
– Ghanima
Sep 14 ’14 at 23:14



I thought about it more and it is actually possible with two shift registers. One for column excitation has data_in connected to IO pin directly, the other one for row read has data_out is connected to the same IO through a series resistor. At leading edge of clk the pin is set as output, otherwise it is an input.
– venny
Sep 14 ’14 at 23:38

Use one GPIO as an Output and toggle it while timing the rise and fall times of the other GPIO set to input. Choose resistor values to separate the timings for each key as much as possible while accounting for component variations and uController logic input threshold variation with temperature.

Leave a Reply

Your email address will not be published. Required fields are marked *