Home » ESP32 and a PCF8574 expander example

ESP32 and a PCF8574 expander example

by shedboy71

The PCF8574 is an 8 bits I/O port expander that uses the I2C protocol. Using this IC, you can use only the SDA and SCL pins of your Arduino board to control up to 8 digital I/O ports.

A0,A1,A2 are address pins
P0,P1,P2,P3,P4,P5,P6,P7 are digital I/O ports
SDA,SCL are the I2C pins

If we set pins A0 to A2 to GND, our device address in binary will be 0x20, thats exactly what I did in my example. To enable read and write there are different values required you can see these in the image below

Parts Required

Here are the parts I used

 

Name Link
ESP32
PCF8574
Connecting cables

Schematic

Note that the PCF8574 is a current sink device so you do not require the current limiting resistors

I have only shown 4 LEDs, also note that I have shown A0, A1 and A2 tied to GND, this is what my test module had selected.

esp32 and pcf8574 schematic

esp32 and pcf8574 schematic

Code

This example flashes the led's

 

#include <Wire.h>

// address of PCF8574 IC
#define PCF8574_ADDR (0x20)

void setup() 
{
  Wire.begin();
}

void loop() 
{

  
  //send the data
  Wire.beginTransmission(PCF8574_ADDR);
  Wire.write(0xAA);
  Wire.endTransmission();
  delay(1000);
  Wire.beginTransmission(PCF8574_ADDR);
  Wire.write(0x55);
  Wire.endTransmission();
  delay(1000);
}

 

 

Link

5PCS PCF8574P DIP-16 Remote 8-bit I/O Expander IC

You may also like

Leave a Comment

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.