Setting up the I2C port expander
Now that we have built our port expander, we need to get it ready to connect our sensors to. First, we need to install the tools on the Raspberry Pi to allow us to use the I2C bus and program devices connected to it, including the MCP23017 chip that makes up our port expander.
Note
Don't connect your port expander to the Raspberry Pi until after you've set up the I2C bus on your system.
Enabling the I2C Bus
It's highly likely that the module for using the I2C bus hasn't been loaded by default. Fortunately, doing this is fairly straightforward and can be done using the Raspberry Pi configuration tool. Perform the following steps:
Launch the Raspberry Pi configuration tool with the following command:
$ sudo raspi-config
Select option 8:
Advanced Options
.Select Option A7:
I2C
.Select
<Yes>
.Reboot your Raspberry Pi for the setting to take effect.
Now that the I2C bus has been enabled, we need to set up the operating system so that the required modules are loaded...