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

How to Use I2C expander: Examples, Pinouts, and Specs

Image of I2C expanderDesign with I2C expander in Cirkit Designer

Introduction

The PCF8574 is an I2C-based I/O expander that allows microcontrollers to interface with additional digital input/output (I/O) pins using the I2C communication protocol. This component is particularly useful when the number of GPIO pins on a microcontroller is insufficient for a given application. By connecting the PCF8574 to the I2C bus, up to 8 additional I/O pins can be added, which can be configured as either inputs or outputs.

Explore Projects Built with I2C expander

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 ESP32-Based I2C Communication Hub with Multiplexer and Expander: A project utilizing I2C expander 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 I2C expander 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 MCP23017-Expanded I/O Interface with ADS1115 ADC and ESP32 Control: A project utilizing I2C expander 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

Common Applications and Use Cases

Technical Specifications

Pin Configuration and Descriptions

The PCF8574 has 16 pins, with the following configuration:

Pin Number Pin Name Description
1 A0 Address selection bit 0 (used to set the I2C address)
2 A1 Address selection bit 1 (used to set the I2C address)
3 A2 Address selection bit 2 (used to set the I2C address)
4 P0 General-purpose I/O pin 0
5 P1 General-purpose I/O pin 1
6 P2 General-purpose I/O pin 2
7 P3 General-purpose I/O pin 3
8 GND Ground (0V reference)
9 P4 General-purpose I/O pin 4
10 P5 General-purpose I/O pin 5
11 P6 General-purpose I/O pin 6
12 P7 General-purpose I/O pin 7
13 INT Interrupt output (active low, triggered by input pin state changes)
14 SCL I2C clock line (connect to microcontroller's SCL pin)
15 SDA I2C data line (connect to microcontroller's SDA pin)
16 VCC Power supply (2.5V to 6V)

Usage Instructions

How to Use the PCF8574 in a Circuit

  1. Connect Power and Ground:

    • Connect the VCC pin to the power supply (e.g., 5V for Arduino).
    • Connect the GND pin to the ground of the circuit.
  2. Set the I2C Address:

    • Use the A0, A1, and A2 pins to configure the I2C address. These pins can be connected to GND (logic 0) or VCC (logic 1) to set the address. The base address is 0x20, and the address can range from 0x20 to 0x27.
  3. Connect the I2C Lines:

    • 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 if not already present.
  4. Connect I/O Devices:

    • Use the P0 to P7 pins to connect digital input or output devices. Configure these pins in your microcontroller code as needed.
  5. Write Code:

    • Use an I2C library (e.g., Wire.h for Arduino) to communicate with the PCF8574. Send or receive data to control the I/O pins.

Important Considerations and Best Practices

Example Code for Arduino UNO

#include <Wire.h> // Include the Wire library for I2C communication

#define PCF8574_ADDRESS 0x20 // Base I2C address of the PCF8574

void setup() {
  Wire.begin(); // Initialize I2C communication
  Serial.begin(9600); // Initialize serial communication for debugging

  // Set all pins (P0 to P7) as outputs and turn them off
  Wire.beginTransmission(PCF8574_ADDRESS);
  Wire.write(0xFF); // Write 0xFF to set all pins high (off for active-low devices)
  Wire.endTransmission();
}

void loop() {
  // Example: Toggle P0 every second
  static bool state = false;
  state = !state;

  Wire.beginTransmission(PCF8574_ADDRESS);
  Wire.write(state ? 0xFE : 0xFF); // Toggle P0 (0xFE = 11111110, 0xFF = 11111111)
  Wire.endTransmission();

  delay(1000); // Wait for 1 second
}

Troubleshooting and FAQs

Common Issues and Solutions

  1. I2C Communication Fails:

    • Cause: Incorrect wiring or missing pull-up resistors.
    • Solution: Verify connections and ensure 4.7kΩ pull-up resistors are present on the SCL and SDA lines.
  2. Device Not Responding:

    • Cause: Incorrect I2C address configuration.
    • Solution: Check the A0, A1, and A2 pin connections and calculate the correct address.
  3. Output Pins Not Driving High Current Devices:

    • Cause: PCF8574 has limited current sourcing capability.
    • Solution: Use external transistors or drivers for high-current loads.
  4. Interrupt Pin Not Working:

    • Cause: Interrupts not enabled or misconfigured.
    • Solution: Ensure the INT pin is connected to a microcontroller interrupt-capable pin and properly configured in the code.

FAQs