Introduction to the MCP23017 I/O Expander IC
In a word, the MCP23017 I/O Expander IC allows you to have up to 16 additional I/O. Occasionally, in a project, the amount of I/O (Inputs and outputs) on your board is not enough. The MCP23017 is a good choice to increase the number of I/O available. As you can see, we have 2 banks of I/O that are 8 bits each. Additionally, you need to set the I2C address of the chip by manipulating pins A0, A1, and A2. In essence, this allows you to use multiple expander ic’s if you need them. You can place up to 25mA on each output pin.
In general, The MCP23017 I/O Expander IC will run anywhere from 1.8 volts to 5.5 volts DC. Vdd being power, and Vss being ground. You will find more information on this IC from this link. Emphatically always check the data sheet on your exact part number as some of the specs could vary from this post.
Connect your Power
Before we begin, we’ll connect the power. At this time, I’m going to place +5v on pin Vdd (Pin 9). Additionally, we’ll connect +5v to the RESET pin (Pin 18) since this is active low. Connect GND to Vss (Pin 10). Furthermore, connect GND to pins A0, A1, and A2. This sets the I2C address to 0x20. In brief, if you plan to add a reset button, then just use a 10K resistor between Vdd and RESET. This will keep the reset pin high until the button is pressed, then the pin will go to ground. Even so, we’re going to keep this simple, and just wire the reset pin directly to the power source.
I2C chart for MCP23107
In the event that you have multiple MCP23017’s, then you can set the address differently as the following chart shows:
Connect the Network
Meanwhile, for the I2C network, connect SCK and SDA on the MCP23017 to SCK and SDA on your microcontroller. Furthermore, we’ll add pull-up resistors to each line. To accomplish this, look at the diagram below.
A point often overlooked is that INTA and INTB are mirror pins, and could provide you with a level of redundancy, but for this post, we’ll just concentrate on making the I/O work.
Connect Your I/O
Obviously, you have the ability to connect up to 16 different devices, inputs or outputs. In this case, we’ll just connect a simple LED to GPA0. After that, we’ll turn on the LED from the microcontroller. Don’t forget to add a resistor in series with the LED. For this example, I’ll add a 1k resistor in series with an LED connected to GPA0. Likewise, the other end of the LED will go to GND. I’m just using an arduino nano compatible for the microprocessor unit.
As you can see, I’m using 10k pull up resistors, which are a little weaker than the recommended 4.7k resistors. They will work just fine for this project.
For this purpose, I’m just using the Adafruit MCP23017 library. Be aware that several other libraries exist, and could give you more flexibility, but this one is very easy to use. Once you install the library, you will see the button sketch under your examples list. Even though, we are using an indicator light, we’ll start with the button sketch, and simply make a few modifications.
In this case, we are not going to change anything in the head.
At this point, in Void Setup(), comment out the 2 lines configuring pin 0. We’ll add the line “mcp.pinMode(0,OUTPUT);”
At this time, we’ll change Void Loop() to the following code. In this situation, it will make the light blink.
At last, you are ready to upload your code! Obviously, be sure the board and port are set up correctly under “Tools”. Then upload your project. In this case, I also had to change the processor to “Old Bootloader” for the nano.f your LED is blinking, then you now have an additional 16 Inputs or outputs in your system! Simply, treat them as local I/O, except with “mcp.” before your commands.
Basically, if your LED is blinking, then your project is working!
For more information, visit the beginner’s category page!
— Ricky Bryce