

The MCP23017 is a 16-bit I/O expander that communicates via the I2C protocol. It allows microcontrollers to expand their GPIO capabilities by providing 16 additional general-purpose input/output (GPIO) pins. This makes it an ideal solution for applications requiring a large number of I/O pins without increasing the microcontroller's pin count.








The MCP23017 has 28 pins. Below is the pin configuration:
| Pin | Name | Description |
|---|---|---|
| 1-3 | A0, A1, A2 | I2C address selection pins (used to set the I2C address of the device) |
| 4 | RESET | Active-low reset input |
| 5 | INTB | Interrupt output for PORTB |
| 6 | INTA | Interrupt output for PORTA |
| 7 | VSS | Ground (0V) |
| 8-15 | GPA0-GPA7 | GPIO pins for PORTA |
| 16 | VDD | Power supply (1.8V to 5.5V) |
| 17-24 | GPB0-GPB7 | GPIO pins for PORTB |
| 25 | SCL | I2C clock input |
| 26 | SDA | I2C data input/output |
| 27 | NC | No connection |
| 28 | NC | No connection |
Below is an example of how to use the MCP23017 with an Arduino UNO to control LEDs connected to PORTA.
#include <Wire.h> // Include the Wire library for I2C communication
#define MCP23017_ADDRESS 0x20 // Default I2C address of MCP23017
void setup() {
Wire.begin(); // Initialize I2C communication
// Set all PORTA pins as outputs
Wire.beginTransmission(MCP23017_ADDRESS);
Wire.write(0x00); // IODIRA register address
Wire.write(0x00); // Set all pins on PORTA as outputs
Wire.endTransmission();
}
void loop() {
// Turn on all LEDs connected to PORTA
Wire.beginTransmission(MCP23017_ADDRESS);
Wire.write(0x12); // GPIOA register address
Wire.write(0xFF); // Set all PORTA pins high
Wire.endTransmission();
delay(1000); // Wait for 1 second
// Turn off all LEDs connected to PORTA
Wire.beginTransmission(MCP23017_ADDRESS);
Wire.write(0x12); // GPIOA register address
Wire.write(0x00); // Set all PORTA pins low
Wire.endTransmission();
delay(1000); // Wait for 1 second
}
MCP23017 Not Responding on I2C Bus:
GPIO Pins Not Functioning as Expected:
Interrupts Not Triggering:
I2C Communication Errors:
Q: Can I use multiple MCP23017 devices on the same I2C bus?
Q: What is the maximum current each GPIO pin can source or sink?
Q: Can the MCP23017 operate at 3.3V?
Q: Do I need external pull-up resistors for input pins?