The MCP23017, manufactured by AzDelivery, is a 16-bit I/O expander that communicates with microcontrollers via the I2C interface. It provides an easy way to add up to 16 additional GPIO pins to your project, making it ideal for applications where the number of available I/O pins on a microcontroller is insufficient. The MCP23017 is highly versatile and can be used for both input and output operations, supporting features such as interrupt handling and pin direction control.
The MCP23017 has 28 pins, with the following configuration:
Pin Number | Pin Name | Description |
---|---|---|
1 | GPA0 | General Purpose I/O Pin 0 (PORTA) |
2 | GPA1 | General Purpose I/O Pin 1 (PORTA) |
3 | GPA2 | General Purpose I/O Pin 2 (PORTA) |
4 | GPA3 | General Purpose I/O Pin 3 (PORTA) |
5 | GPA4 | General Purpose I/O Pin 4 (PORTA) |
6 | GPA5 | General Purpose I/O Pin 5 (PORTA) |
7 | GPA6 | General Purpose I/O Pin 6 (PORTA) |
8 | GPA7 | General Purpose I/O Pin 7 (PORTA) |
9 | VSS | Ground (0V) |
10 | INTB | Interrupt Output for PORTB |
11 | INTA | Interrupt Output for PORTA |
12 | SCL | I2C Clock Line |
13 | SDA | I2C Data Line |
14 | A2 | I2C Address Pin 2 |
15 | A1 | I2C Address Pin 1 |
16 | A0 | I2C Address Pin 0 |
17 | RESET | Active-Low Reset Input |
18 | VDD | Power Supply (1.8V to 5.5V) |
19 | GPB0 | General Purpose I/O Pin 0 (PORTB) |
20 | GPB1 | General Purpose I/O Pin 1 (PORTB) |
21 | GPB2 | General Purpose I/O Pin 2 (PORTB) |
22 | GPB3 | General Purpose I/O Pin 3 (PORTB) |
23 | GPB4 | General Purpose I/O Pin 4 (PORTB) |
24 | GPB5 | General Purpose I/O Pin 5 (PORTB) |
25 | GPB6 | General Purpose I/O Pin 6 (PORTB) |
26 | GPB7 | General Purpose I/O Pin 7 (PORTB) |
27 | OSC1 | Oscillator Input (optional, for external clock) |
28 | OSC2 | Oscillator Output (optional, for external clock) |
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
mcp.begin(); // Default address is 0x20
// Configure PORTA as outputs for LEDs
for (int i = 0; i < 8; i++) {
mcp.pinMode(i, OUTPUT);
}
// Configure PORTB as inputs for buttons
for (int i = 8; i < 16; i++) {
mcp.pinMode(i, INPUT);
mcp.pullUp(i, HIGH); // Enable internal pull-up resistors
}
}
void loop() {
// Read button states from PORTB
for (int i = 8; i < 16; i++) {
if (mcp.digitalRead(i) == LOW) { // Button pressed
mcp.digitalWrite(i - 8, HIGH); // Turn on corresponding LED
} else {
mcp.digitalWrite(i - 8, LOW); // Turn off corresponding LED
}
}
}
No Communication with MCP23017:
GPIO Pins Not Responding:
Interrupts Not Working:
Can I use the MCP23017 with 3.3V microcontrollers? Yes, the MCP23017 operates at voltages as low as 1.8V, making it compatible with 3.3V systems.
How many MCP23017 devices can I connect to a single I2C bus? Up to 8 devices can be connected by configuring the A0, A1, and A2 address pins.
What is the maximum I2C speed supported by the MCP23017? The MCP23017 supports I2C speeds up to 1.7 MHz.
This concludes the documentation for the MCP23017.