

The MCP23017 is a 16-bit I/O expander that communicates via the I2C protocol, enabling microcontrollers to expand their input/output capabilities. This component is ideal for applications where additional GPIO pins are required but the microcontroller has limited I/O resources. It features programmable pull-up resistors, interrupt capabilities, and supports multiple devices on the same I2C bus by configuring its address pins.








The MCP23017 has 28 pins, but the breakout board simplifies connections. Below is the pin configuration:
| Pin Name | Type | Description |
|---|---|---|
| VDD | Power | Positive supply voltage (1.8V to 5.5V). |
| VSS | Ground | Ground connection. |
| SCL | Input | I2C clock line. Connect to the microcontroller's SCL pin. |
| SDA | Input/Output | I2C data line. Connect to the microcontroller's SDA pin. |
| A0, A1, A2 | Input | Address pins for configuring the I2C address (0x20 to 0x27). |
| INTA, INTB | Output | Interrupt outputs for GPIOA and GPIOB. |
| RESET | Input | Active-low reset pin. Pull high for normal operation. |
| GPA0-GPA7 | Input/Output | GPIO pins for Port A. Can be configured as input or output. |
| GPB0-GPB7 | Input/Output | GPIO pins for Port B. Can be configured as input or output. |
Below is an example of how to use the MCP23017 with an Arduino UNO to control LEDs and read button inputs:
#include <Wire.h>
#include "Adafruit_MCP23017.h"
// Create an MCP23017 object
Adafruit_MCP23017 mcp;
void setup() {
// Initialize I2C communication
Wire.begin();
// Initialize the MCP23017 at address 0x20
mcp.begin(0);
// Configure GPIOA0 as output (e.g., for an LED)
mcp.pinMode(0, OUTPUT);
// Configure GPIOA1 as input with pull-up resistor (e.g., for a button)
mcp.pinMode(1, INPUT);
mcp.pullUp(1, HIGH); // Enable pull-up resistor on GPIOA1
// Start serial communication for debugging
Serial.begin(9600);
}
void loop() {
// Turn on the LED connected to GPIOA0
mcp.digitalWrite(0, HIGH);
// Check the button state on GPIOA1
if (mcp.digitalRead(1) == LOW) {
Serial.println("Button Pressed!");
} else {
Serial.println("Button Released!");
}
delay(500); // Wait for 500ms
}
No Communication with MCP23017
GPIO Pins Not Responding
Interrupts Not Working
I2C Bus Errors
Can I use multiple MCP23017 devices on the same I2C bus? Yes, you can connect up to 8 MCP23017 devices by configuring their A0, A1, and A2 address pins.
What is the maximum current the GPIO pins can handle? Each GPIO pin can source or sink up to 25 mA, but the total current for all pins should not exceed 125 mA.
Do I need external pull-up resistors for the GPIO pins? No, the MCP23017 has programmable internal pull-up resistors, but you can use external ones if needed for specific applications.