Micro:bit and PCF8575 I/O expander 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.


  • 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





Parts List

Part Link
Micro:bit Micro:bit Development Board
Edge Breakout I/O Expansio Edge Breakout I/O Expansion Extension Board for BBC micro:bit
Dupont cable Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire
PCF8575 PCF8575 IIC I2C I/O Extension Shield Module 16 bit SMBus I/O


Code examples

Output – switch LED on and off

#include <Wire.h>
// Set I2C address
int address = 0x20;
void setup()
  // Set all ports as output
void loop()
  // Set port P0 on
  // Set port P0 off
// Function for writing two Bytes to the I2C expander device
void pf575_write(uint16_t data) 


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