In my last tutorial, I talked about the TCA9548A MUX which can be used to add at the max of 64 I2C or I²C sensors to your Arduino/ESP8266/ESP32.
In this tutorial, I am going to talk about the PCF8574 8-bit GPIO Port Extender. It is one of the many GPIO extenders available in the market.
This tiny little board becomes a life saver When you run out of pins on your Arduino. This "GPIO (General Purpose Input Output) pin extender" provides an additional 8 pins (P0 ~ P7) which can be used to 'output a signal' or 'read a signal as an input'.
These modules run on the I2C bus, and if daisy-chained you can connect upto 8 of these devices in a project. Each device will give us an additional 8-bits of GPIO enabling 64 GPIOs in total.
These ICs are ridiculously cheap and can be bought easily from eBay or AliExpress. If you don't want to worry about the wiring and just want to keep your project really "simple", then you can buy these fully assembled breakout boards. You just need to hook them up to the I2C bus and you are all ready to go.

Step 1: Hardware Requirement

Picture of Hardware Requirement

For this tutorial we need:

  • Breadboard
  • PCF8574 GPIO Extender IC
  • PCF8574 GPIO Extender Breakout Board
  • Arduino UNO/Nano whatever is handy
  • NodeMCU
  • Few LEDs and equal amount of 220 Ohms current limiting resistors
  • 2 x 10K Resistors
  • Jumper Cables, and
  • USB Cable to upload the code

Step 2: Topics Covered

Picture of Topics Covered

  • Overview of the I2C Technology
  • Closer look at the PCF8574 GPIO Extender IC and the Breakout Board
  • GPIO Addressing
  • Libraries To Use
  • Connecting PCF8574 to Arduino and NodeMCU
  • Finding address using I2C Scanner
  • How to program and use PCF8574 in your project
  • How to use the Interrupt Pin
  • Areas of Application

Step 3: I2C Technology

Picture of I2C Technology

Picture of I2C Technology

Inter-integrated Circuit pronounced I-squared-C (I²C) or I2C is a 'short distance', 'two wire bus technology' (well actually 4 wires because you also need the VCC and Ground) that is used for 'serial communication' between multiple processors and sensors.
If you want to know more about the I2C technology please check out my 'Tutorial Number 09'. For now we will just cover the basics of I2C and we will jump to our main topic. The two wires are:

  • SDA - Serial Data (data line) and
  • SCL - Serial Clock (clock line)

Both of these lines are open-drain, and are pulled-up with resistors. Usually there is one master and one or multiple slaves on the line, however there can be multiple masters aswell. Both masters and slaves can transmit or receive data.
PCF8574 GPIO Extender run on the I2C bus, extending the 'IO Pins' which can be controlled by a single host I2C bus. The Address range of PCF8574 is from 0x20 to 0x27 (7 bit address mode). at the max 8 of these devices can be connected in a project to the I2C bus.

Step 4: Closer Look/ Pinouts

Picture of Closer Look/ Pinouts

Picture of Closer Look/ Pinouts

Picture of Closer Look/ Pinouts

IC: (5 pieces for AUD $2.30)
****************************
Lets first checkout the pin-outs of the PCF8574 IC:

  1. Pin 16 of this IC is VCC which can operate on 2.5V to 6V
  2. Pin 8 is GND
  3. Pins 4~7 and 9~12 are the P0 to P7 8-Parallel (which means you can use all the 8 pins at once) I/O pins. Each of these bidirectional I/O pins can be used as an input or output without the use of a data-direction control signal. At power on, all these I/O pins are at HIGH state.
  4. Pin 15 is for the I2C serial data input or output (Connect to VCC through a pull-up resistor) and
  5. Pin 14 is for the I2C clock input (Connect to VCC through a pull-up resistor)
  6. Pins 1, 2, and 3 or the A0, A1 and A2 allows us to specify the address that the PCF8574 appears as on the I2C bus by turning them HIGH. Default address is 0x20. By default all these pins are grounded or LOW. Pull-up resistors are not needed for these pins.
  7. Pin 13 is for the Interrupt Output. Connect it to the VCC using a pull-up resistor.
  • These ICs have very "Low Standby-Current" Consumption of only 10μA.
  • The SDA, SLC and the Interrupt pins all need to be pulled up using pull-up resistors
  • There is a second variant of this IC available in the market called the PCF8574A. The major difference...
Read more »