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

How to Use MCP23017: Examples, Pinouts, and Specs

Image of MCP23017Design with MCP23017 in Cirkit Designer

Introduction

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.

Explore Projects Built with MCP23017

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 MCP23017 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 I2C-Controlled Relay Switching with ESP32 and MCP23017 for Home Automation: A project utilizing MCP23017 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
Image of ESP32-Based I2C Communication Hub with Multiplexer and Expander: A project utilizing MCP23017 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 ESP32-Based Vibration Motor Controller with I2C IO Expansion: A project utilizing MCP23017 in a practical application
ESP32-Based Vibration Motor Controller with I2C IO Expansion

This circuit features an ESP32 Wroom Dev Kit microcontroller interfaced with an MCP23017 I/O expansion board via I2C communication, utilizing GPIO 21 and GPIO 22 for SDA and SCL lines, respectively. A vibration motor is controlled by an NPN transistor acting as a switch, with a diode for back EMF protection and a resistor to limit base current. The ESP32 can control the motor by sending signals to the MCP23017, which then interfaces with the transistor to turn the motor on or off.

Open Project in Cirkit Designer

Common Applications and Use Cases

Technical Specifications

Pin Configuration and Descriptions

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

Usage Instructions

How to Use the MCP23017 in a Circuit

  1. Powering the MCP23017: Connect the VDD pin to a power source (1.8V to 5.5V) and the VSS pin to ground.
  2. I2C Address Configuration: Use the A0, A1, and A2 pins to set the I2C address. Each pin can be connected to VDD (logic high) or VSS (logic low), allowing up to 8 unique addresses.
  3. Connecting to a Microcontroller:
    • Connect the SCL pin to the microcontroller's I2C clock line.
    • Connect the SDA pin to the microcontroller's I2C data line.
    • Use pull-up resistors (typically 4.7kΩ) on the SCL and SDA lines.
  4. GPIO Configuration:
    • Configure each GPIO pin as input or output by writing to the IODIRA and IODIRB registers.
    • Enable internal pull-up resistors for input pins by writing to the GPPUA and GPPUB registers.
    • Read or write to GPIO pins using the GPIOA and GPIOB registers.

Important Considerations and Best Practices

Example: Using MCP23017 with Arduino UNO

Below is an example of how to use the MCP23017 with an Arduino UNO to control LEDs connected to PORTA.

Circuit Diagram

Arduino Code

#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
}

Troubleshooting and FAQs

Common Issues

  1. MCP23017 Not Responding on I2C Bus:

    • Cause: Incorrect I2C address or wiring.
    • Solution: Verify the A0, A1, and A2 pin configuration and ensure proper connections to SDA and SCL.
  2. GPIO Pins Not Functioning as Expected:

    • Cause: Incorrect configuration of IODIR, GPPU, or GPIO registers.
    • Solution: Double-check the register settings for input/output modes and pull-up resistors.
  3. Interrupts Not Triggering:

    • Cause: Interrupts not enabled or misconfigured.
    • Solution: Ensure GPINTEN, INTCON, and DEFVAL registers are configured correctly.
  4. I2C Communication Errors:

    • Cause: Missing or incorrect pull-up resistors on SDA/SCL lines.
    • Solution: Add 4.7kΩ pull-up resistors to the SDA and SCL lines.

FAQs