PCF8575 I/O expander and ESP8266 examples

This 16-bit I/O expander for the two-line bidirectional bus (I2C) is designed for 2.5-V to 5.5-V VCC operation.

The PCF8575 device provides general-purpose remote I/O expansion for most microcontroller families by way of the I2C interface [serial clock (SCL), serial data (SDA)].

The device features a 16-bit quasi-bidirectional input/output (I/O) port (P07–P00, P17–P10), including latched outputs with high-current drive capability for directly driving LEDs. Each quasi-bidirectional I/O can be used as an input or output without the use of a data-direction control signal. At power on, the I/Os are high. In this mode, only a current source to VCC is active.

Features

  • I2C to Parallel-Port Expander
  • Open-Drain Interrupt Output
  • Low Standby-Current Consumption of 10 µA Max
  • Compatible With Most Microcontrollers
  • 400-kHz Fast I2C Bus
  • Address by Three Hardware Address Pins for Use of up to Eight Devices
  • Latched Outputs With High-Current Drive Capability for Directly Driving LEDs

 

Connection

This example shows only one LED, I had a special LED test board with 6 LEDs fitted to it

esp8266 and PCF8575
esp8266 and PCF8575

 

Parts List

Here are the parts I used

 

Name Links
Wemos Mini
PCF8575
Connecting cables

Code examples

Output – switch LED on and off

 

#include <Wire.h>

// Set I2C address
int address = 0x20;

void setup()
{ 
  Wire.begin();
  // Set all ports as output
  pf575_write(word(B11111111,B11111111));
} 

void loop()
{
  // Set port P0 on
  pf575_write(word(B00000000,B00000001));
  delay(1000);
  // Set port P0 off
  pf575_write(word(B00000000,B00000000));
  delay(1000);
} 

// Function for writing two Bytes to the I2C expander device
void pf575_write(uint16_t data) 
{
  Wire.beginTransmission(address);
  Wire.write(lowByte(data));
  Wire.write(highByte(data));
  Wire.endTransmission();
}

 

Output – switch LEDs on and off

 

#include <Wire.h>
 
byte address = 0x20;   // address of PCF8575
 
void setup()
{
   Wire.begin();       // join i2c bus as master
}
 
 
void loop()
{
  unsigned char x;
  unsigned char y;
 
  for (x=0, y=255; (x+y)==255; x++, y--)
  {
      Wire.beginTransmission(address);   // send the address and the write cmnd
      Wire.write(x);                      // pack the first byte
      Wire.write(y);                      // pack the second byte
      Wire.endTransmission();            // send the data
      delay(150);     
   }
}

 

Link

https://www.ti.com/lit/ds/symlink/pcf8575.pdf?ts=1703941571187

1 COMMENT