The MCP23017 is a versatile I/O expander from Microchip that allows a microcontroller to control up to 16 additional digital inputs or outputs via a two-wire I2C serial interface. This component is particularly useful in applications where additional I/O pins are needed, such as in button matrices, LED control, or when interfacing with multiple sensors. Common applications include home automation systems, industrial controls, and hobbyist projects where expansion of I/O capabilities is required.
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!
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.
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.
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.
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.
I2C Addresses: 8 different addresses selectable via hardware (0x20-0x27)
Pin Configuration and Descriptions
Pin Number
Pin Name
Description
1-2
A0-A1
Hardware address pins to configure the I2C address
3
NC
No Connection (must be left unconnected)
4
VSS
Ground (0V) reference for the power supply
5-12
GPB0-GPB7
General Purpose I/O pins (Port B)
13
VDD
Positive power supply pin
14
SCL
Serial Clock Line for I2C communication
15
SDA
Serial Data Line for I2C communication
16-23
GPA0-GPA7
General Purpose I/O pins (Port A)
24
RESET
Active-low reset input
25-28
NC
No Connection (must be left unconnected)
Usage Instructions
Interfacing with a Microcontroller
Power Connections: Connect VDD to the microcontroller's power supply (1.8V to 5.5V) and VSS to ground.
I2C Connections: Connect SCL and SDA to the corresponding I2C clock and data lines on the microcontroller. Pull-up resistors may be required on these lines.
Address Selection: Set the hardware address by connecting A0 and A1 to either VDD or VSS. This will determine the I2C address of the MCP23017.
Reset (Optional): Connect the RESET pin to a digital output on the microcontroller if hardware reset functionality is desired.
I/O Configuration: Configure the I/O pins (GPA0-GPA7 and GPB0-GPB7) as inputs or outputs by writing to the IODIRA and IODIRB registers.
Important Considerations and Best Practices
Ensure that the power supply voltage is within the specified range for the MCP23017.
Use pull-up resistors on the I2C lines as required by the microcontroller's I2C specification.
Avoid exceeding the maximum current ratings for the I/O pins.
When using the MCP23017 with a microcontroller at a different voltage level, ensure proper logic level shifting for the I2C lines.
Example Code for Arduino UNO
#include <Wire.h>
// MCP23017 I2C address (configured by A0, A1 pins)
const int mcpAddress = 0x20;
// Registers addresses
const int IODIRA = 0x00; // I/O direction register for port A
const int IODIRB = 0x01; // I/O direction register for port B
void setup() {
Wire.begin(); // Initialize I2C
pinMode(13, OUTPUT); // Use onboard LED for output
// Set all GPA pins to output, all GPB pins to input
mcpWrite(IODIRA, 0x00); // All A pins as output
mcpWrite(IODIRB, 0xFF); // All B pins as input
}
void loop() {
// Toggle all GPA pins
mcpWrite(0x12, 0xFF); // Turn on all GPA pins
delay(500);
mcpWrite(0x12, 0x00); // Turn off all GPA pins
delay(500);
}
// Function to write data to a register on MCP23017
void mcpWrite(int reg, int data) {
Wire.beginTransmission(mcpAddress);
Wire.write(reg); // Register address
Wire.write(data); // Data to write
Wire.endTransmission();
}
Troubleshooting and FAQs
Common Issues
I2C Communication Failure: Ensure that the MCP23017 is powered correctly and that the SCL and SDA lines are connected properly with pull-up resistors.
Incorrect Pin Behavior: Verify that the I/O pins have been configured correctly by writing to the IODIRA and IODIRB registers.
Device Not Responding: Check the hardware address pins (A0, A1) and ensure they match the address used in the code.
Solutions and Tips for Troubleshooting
Use an I2C scanner sketch to confirm that the MCP23017 is detected on the I2C bus.
Check for solder bridges or cold solder joints that might be causing shorts or open circuits.
Ensure that the RESET pin is not inadvertently being pulled low during operation, which would reset the device.
FAQs
Q: Can I use multiple MCP23017 devices on the same I2C bus?
A: Yes, you can use up to 8 MCP23017 devices on the same I2C bus by configuring each with a unique hardware address (0x20-0x27).
Q: What is the maximum I2C clock frequency the MCP23017 can handle?
A: The MCP23017 supports a maximum I2C clock frequency of 1.7 MHz in HS mode.
Q: Do I need to use external pull-up resistors on the I/O pins?
A: No, external pull-up resistors are not required on the I/O pins unless you are using them in an open-drain configuration.