I am currently using a
raspberry pi zero, which I connect directly to my computer via usb. I have connected eight
MCP23017 GPIO expander chips, which is the maximum amount you can connect to a single i2c bus by changing the chip address with the supplied
a2 pins (2^3).
I would like to have access to even more GPIO pins, while also reducing the amount of time it takes the raspberry pi to iteratively set the on-off values of the newly added GPIO pins. Each
MCP23017 controls 16 GPIO pins. Currently, accessing and changing the value of a pin on the
MCP23017 GPIO expander chip takes around 0.0005-0.0008 seconds, which means that changing the value of 100 pins already takes 0.05+ seconds in total. I would like to avoid connecting more
MCP23017 chips to my current setup, where the single raspberry pi is already struggling to effectively manage the 8*16 GPIO pins I want to control. I would also be able to control the timing of when a pin is set with an accuracy of ~0.001s, even when multiple pins are set at once.
One idea I had was to connect multiple arduino nano/ arduino pro micros to my raspberry pi and distribute the GPIO pins across those, so the strain on a single i2c bus is reduced and the accuracy when setting multiple pins at once is improved. So far the only way I have found to do this is by having them read the stdout of my raspberry pi, which might also cause performance problems. I was also thinking about simply using multiple raspberry pi zeros for this purpose, though I am not sure how to connect them all to my computer, which is currently using a single raspberrypi.local address to connect via usb and eliminate possible ping from a wifi connection.
Is this a recommeded approach for this problem? I am using all those GPIO pins to control motor driver chips, which is why I need this setup to be as accurate as possible. What would be the best way to achieve a setup where I am able to control those chips using multiple i2c busses instead of just one? There are also chips that multiply a single i2c bus by eight like the TCA9548A, but I don't know if this is a recommended way to potentially control over 200 GPIO pins in a parallel manner, especially when timing accuracy and parallelization plays a role.
I am controlling the pins on my raspberry pi with a python script as following:
import board import busio import adafruit_mcp230xx from time import sleep i2c = busio.I2C(board.SCL, board.SDA) mcp_addresses = [0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27] mcps =  for address in mcp_addresses: mcps.append(adafruit_mcp230xx.mcp23017.MCP23017(i2c,address = address)) # MCP23017 pins =  for iter,mcp in enumerate(mcps): for i in range(0,15): pin = mcp.get_pin(i) pins.append(pin) pins.value=True sleep(0.01) pins.value=False
I am also open to implementing this in c for performance reasons.