About This Project
The Raspberry Pi comes in the last models with 40 gpio pins and supports many protocols. For project, maybe in the area of homeautomation or industrial applications, the 40 gpio pins are not enough. An port expander can help in this situation. The most port expanders are connected via I2C or SPI to the Raspberry Pi or microcontroller. The expander provides many input / outputs. Over I2C or SPI (depends on IC) you can access the ports from the expanders - set ouputs and read inputs.
In my case i use a Raspberry Pi 3 with Cayenne. The pi is connected via ethernet to the local network and internet. As port expander i use the MCP23017. This model is supported by Cayenne und must be connected via I2C to the pi. The MCP23017 provides Up to 16 I/O ports. More information in the datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/21952b.pdf
To use the port expander you must activate I2C on the raspberry pi. You can easily setup i2c via the configuration menu of the raspberry pi. Otherwise you can setup and activate i2c over SSH using “sudo raspi-config”. With the “add device” context we can search for the MCP23017 and setup it on the i2c address 20. This is the standard address (pins A0,A1 and A2 connected to ground). To use more then one expanders, each expander must have a different address. To setup the address it is important to setup a high - low combination on the address pins (like a binary code that represents the address number). For testing a added a led with pre-resonator to port 1.
Once added, the MCP23017 is available unter the extensions menu.