Electronic – How to extend a microcontroller GPIO to ~300 inputs

firmwaremicrocontroller

I need to find out the address of buttons pushed. Say I need about 300 Input port required dedicated for individual buttons. Then I would need 300 I/O pins to read the address of a pushed button which is not feasible for Microcontroller without using any sort of Integrated Circuit.

My question is is there any IC that would dedicate an individual address for push button so whenever I push button it would send/give me an address like 0xA ? Or is there work around?

Best Answer

If 256 buttons will be enough, you can use two MCP23017 (16 port I2C GPIO): the first one as 16 outputs, the second one as 16 inputs, of course with 16x16 matrix of buttons. If not enough, you can use three of them, or "borrow" additional three lines form MCU (so, it will make 16x19 = 304 buttons possible).

As @jonk mentioned, if you want to detect multiple buttons pressed at the same time, you need to add diodes (1N4148, 1N914) to each button, like below:

button matrix (w/ diodes for each button)

If you don't need to handle multiple pressed buttons, you need to protect only the output lines by diodes, like below:

button matrix (w/ diodes on output lines only)

MCP23017 is pretty cheap and works very well.