In this example we connected a Raspberry Pi 3 with 3 relay boards via MCP23017 I2C port expander and switch the relays.
You can control 16 relays via MCP23017. Via the I2C port of the Raspberry Pi you can control up to 8 MCP23017 (you can assign 8 different addresses to the MCP23017). So you could easily control 128 relays.
The Raspberry Pi does not have enough power to switch 16 relays !! An additional power supply must be connected. We have connected an additional breadboard power supply.
To control the relays with the Raspberry Pi via a port expander MCP23017 must be activated on the Raspberry Pi I2C. This can be done by the raspi-config by command line or via the desktop Raspberry PI Configuration.