# Best way to get 256 io pins?

I'm connecting to an arduino or raspberry pi and would like to have 256 io pins. I found a 16bit io expander which has 8 unique addresses for 128 but that's the max I can do on i2c. Any other thoughts on how to expand my io ports?

• ... another I2C bus? Dec 24 '14 at 20:03
• @Majenko To be fair, I think this question would still hold if you replace Raspberry Pi or Arduino with MSP430 or some such appropriate μC. Dec 24 '14 at 20:24
• Can you describe your application in more detail? There might be a way that doesn't require 256 i/o pins. Dec 25 '14 at 0:35
• -1 for lack of detail. Dec 25 '14 at 1:29
• Do you need I/O pins, or unidirectional inputs or outputs? Dec 25 '14 at 2:00

You can put an I2C Multiplexer in there between the Arduino and your devices, then only put one of each address on each downstream bus. A 1-to-2 Multiplexer that I've used with Arduino before is PCA9540BD,118. That will get you to 256 with the hardware and interfaces you are already using with the addition of one more component.

There are inexpensive CPLDs available with lots of I/O pins. It's a good tool to have in your toolbox. For example, XC2C32A with 33 I/O for $1.25. Or slap down a$50-ish XC2C512 with 270 I/O and it's all over but the programming.

This is a solution if all you are looking for is low-speed output-only: 74HC595. http://www.nxp.com/documents/data_sheet/74HC_HCT595.pdf

I once used this chip for animating a lot of LEDs.

You can connect a chain of these chips together, so that the output of a Q7S goes to it's neighbor's DS. Then, take an SPI output of your main micro and connect it to the chain. The micro's SPI-MOSI should connect to the free DS chip and then SPI-CLK should connect, in parallel, to all of the SHCP pins. Then, use a free I/O to pulse all of the STCP pins. Your transmission should look like this:

1. Transmit 8 bytes on SPI.
2. Pulse STCP

Once you pulse the STCP line, all of the outputs will change.

The MCP23S17 has 16 I/O pins and uses SPI. Throw in a 4:16 demux for the select and you get 256 I/Os.

Both MCP23017 and 23S17 have addresses so 8 23017's on I2C and 8 23S17's sharing one SPI bus.