Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

How to Use Adafruit MCP23017 I2C GPIO Expander Breakout: Examples, Pinouts, and Specs

Image of Adafruit MCP23017 I2C GPIO Expander BreakoutDesign with Adafruit MCP23017 I2C GPIO Expander Breakout in Cirkit Designer

Introduction

The Adafruit MCP23017 I2C GPIO Expander Breakout (Part ID: 5346) is a versatile and easy-to-use module that allows you to expand the number of GPIO pins available to your microcontroller. It provides 16 additional GPIO pins via the I2C interface, making it ideal for projects that require more input/output options than your microcontroller can natively support. Each pin can be configured as an input or output, and the module supports features like internal pull-up resistors and interrupt capabilities.

Explore Projects Built with Adafruit MCP23017 I2C GPIO Expander Breakout

Use Cirkit Designer to design, explore, and prototype these projects online. Some projects support real-time simulation. Click "Open Project" to start designing instantly!
Image of MCP23017-Expanded I/O Interface with ADS1115 ADC and ESP32 Control: A project utilizing Adafruit MCP23017 I2C GPIO Expander Breakout in a practical application
MCP23017-Expanded I/O Interface with ADS1115 ADC and ESP32 Control

This circuit features two MCP23017 I/O expanders interfaced with multiple switches, allowing for the expansion of input capabilities. The MCP23017s are connected via I2C to an Olimex ESP32-EVB microcontroller, which likely manages the input states from the switches. Additionally, an Adafruit ADS1115 16-bit ADC is included, suggesting that some analog inputs are being monitored, with the ADC also interfaced with the ESP32 via I2C.

Open Project in Cirkit Designer
Image of ESP32-Based I2C Communication Hub with Multiplexer and Expander: A project utilizing Adafruit MCP23017 I2C GPIO Expander Breakout in a practical application
ESP32-Based I2C Communication Hub with Multiplexer and Expander

This circuit features an Olimex ESP32-EVB microcontroller unit (MCU) for processing and connectivity, interfaced with an MCP23017 I/O expander and an Adafruit TCA9548A I2C multiplexer to expand the number of I/O lines and allow multiple I2C devices to communicate with the MCU over the same bus. Pull-up resistors are connected to the I2C lines for proper bus operation, and both the MCP23017 and TCA9548A have their reset lines pulled high, likely for normal operation without external reset control.

Open Project in Cirkit Designer
Image of I2C-Controlled Relay Switching with ESP32 and MCP23017 for Home Automation: A project utilizing Adafruit MCP23017 I2C GPIO Expander Breakout in a practical application
I2C-Controlled Relay Switching with ESP32 and MCP23017 for Home Automation

This circuit appears to be a control system utilizing two MCP23017 I/O expanders interfaced with an Olimex ESP32-EVB microcontroller via I2C communication, as indicated by the SDA and SCL connections with pull-up resistors. The MCP23017 expanders control an 8-channel relay module, allowing the microcontroller to switch various loads, potentially for home automation or industrial control. Additionally, there is an Adafruit ADS1115 16-bit ADC for analog signal measurement, and several heating actuators and a thermostat are connected, suggesting temperature control functionality.

Open Project in Cirkit Designer

Common Applications and Use Cases

Technical Specifications

The following table outlines the key technical details of the Adafruit MCP23017 I2C GPIO Expander Breakout:

Specification Details
Manufacturer Adafruit
Part ID 5346
GPIO Pins 16 (configurable as input or output)
Communication Interface I2C (up to 1.7 MHz)
Operating Voltage 1.8V to 5.5V
Maximum Current per Pin 25 mA
Total Maximum Current 125 mA
Internal Pull-Up Resistors Configurable (100 kΩ typical)
Interrupt Pins 2 (INTA and INTB)
Addressing 7-bit I2C address (configurable via 3 address pins, up to 8 devices on bus)
Dimensions 25.5mm x 18mm x 2mm

Pin Configuration and Descriptions

The MCP23017 breakout board has the following pin layout:

Pin Name Description
VCC Power supply input (1.8V to 5.5V).
GND Ground connection.
SDA I2C data line. Connect to the SDA pin of your microcontroller.
SCL I2C clock line. Connect to the SCL pin of your microcontroller.
A0, A1, A2 Address pins for configuring the I2C address (connect to GND or VCC).
INTA, INTB Interrupt output pins for Port A and Port B.
GPA0-GPA7 GPIO pins for Port A (can be configured as input or output).
GPB0-GPB7 GPIO pins for Port B (can be configured as input or output).
RESET Active-low reset pin. Pull low to reset the MCP23017.

Usage Instructions

How to Use the MCP23017 in a Circuit

  1. Power the Module: Connect the VCC pin to your microcontroller's power supply (1.8V to 5.5V) and the GND pin to ground.
  2. Connect I2C Lines: Connect the SDA and SCL pins to the corresponding I2C pins on your microcontroller.
  3. Set the I2C Address: Use the A0, A1, and A2 pins to configure the I2C address. Each pin can be tied to GND (0) or VCC (1), allowing up to 8 unique addresses.
  4. Configure GPIO Pins: Use the MCP23017's registers to set each GPIO pin as an input or output. You can also enable internal pull-up resistors for input pins.
  5. Handle Interrupts (Optional): If needed, connect the INTA and/or INTB pins to your microcontroller to handle interrupts from the MCP23017.

Example: Using MCP23017 with Arduino UNO

Below is an example of how to use the MCP23017 with an Arduino UNO to control LEDs and read button inputs.

Circuit Setup

Arduino Code

#include <Wire.h>
#include "Adafruit_MCP23017.h"

// Create an MCP23017 object
Adafruit_MCP23017 mcp;

void setup() {
  // Initialize I2C communication
  mcp.begin(); // Default address is 0x20

  // Configure GPA0 and GPA1 as outputs for LEDs
  mcp.pinMode(0, OUTPUT); // GPA0
  mcp.pinMode(1, OUTPUT); // GPA1

  // Configure GPB0 as input for a button
  mcp.pinMode(8, INPUT);  // GPB0
  mcp.pullUp(8, HIGH);    // Enable internal pull-up resistor on GPB0

  Serial.begin(9600);
}

void loop() {
  // Read the button state
  bool buttonState = mcp.digitalRead(8); // Read GPB0

  if (buttonState == LOW) {
    // Button pressed, turn on LED on GPA0
    mcp.digitalWrite(0, HIGH);
  } else {
    // Button not pressed, turn off LED on GPA0
    mcp.digitalWrite(0, LOW);
  }

  // Blink the LED on GPA1
  mcp.digitalWrite(1, HIGH);
  delay(500);
  mcp.digitalWrite(1, LOW);
  delay(500);
}

Important Considerations and Best Practices

Troubleshooting and FAQs

Common Issues

  1. I2C Communication Failure

    • Cause: Incorrect wiring or I2C address mismatch.
    • Solution: Double-check the connections and ensure the I2C address matches the configuration of the A0, A1, and A2 pins.
  2. GPIO Pins Not Responding

    • Cause: Incorrect pin configuration or insufficient power supply.
    • Solution: Verify the pin mode (input/output) and ensure the power supply voltage is within the specified range.
  3. Interrupts Not Triggering

    • Cause: Interrupt pins not connected or improperly configured.
    • Solution: Connect the INTA or INTB pin to a valid interrupt-capable pin on your microcontroller and configure it correctly.

FAQs

  1. Can I use multiple MCP23017 modules on the same I2C bus?

    • Yes, you can connect up to 8 MCP23017 modules by configuring their I2C addresses using the A0, A1, and A2 pins.
  2. What is the maximum current I can draw from the GPIO pins?

    • Each GPIO pin can source or sink up to 25 mA, with a total maximum current of 125 mA for all pins combined.
  3. Can I use the MCP23017 with 3.3V microcontrollers?

    • Yes, the MCP23017 is compatible with both 3.3V and 5V logic levels.
  4. Do I need external pull-up resistors for the GPIO pins?

    • No, the MCP23017 has configurable internal pull-up resistors for input pins. However, external pull-ups may be used if needed for specific applications.