PCF8574

PCF8574 8-Bit I/O Expander

View on GitHub

PU2CLR - PCF8574 Arduino Library

It is an Arduino Library to control the PCF8574 8-Bit I/O Expander.

The PCF8574 device provides 8-bit, general purpose, parallel I/O expansion. It can be controlled via I²C bus applications. It is a great and inexpensive device that allow you to add more peripherals to be controlled by your Arduino board via I²C protocol.

Some Arduino projects may require more pins than the Arduino actually has. In these cases, you can use up to 8 PCF8574 devices using only the I²C bus (two Arduino pins) and add up to 64 input / output ports to your project.

This Arduino implements the most important functions available on PCF8574 device and can be freely distributed using the MIT Free Software model. See NXP Semiconductors datasheet - PCF8574; PCF8574A - Remote 8-bit I/O expander for I2C-bus with interrupt for more information about the PCF8574 device.

Copyright (c) 2021 Ricardo Lima Caratti.

If you find this project useful, consider making a donation so that the author of this library can purchase components and modules for improvements and testing of this library. Click here to donate.

About Me

I hold a Master’s degree in Educational Technology from the Federal University of Ceará, where I delved into the ways technology can enhance learning experiences. My passion for computer science led me to specialize in it, focusing on Distributed Systems Development with an Object-Oriented approach, at the University of Brasília. My academic journey began with a Bachelor’s degree in Information Systems from the União Pioneira de Integração Social (UPIS-Brasília). Outside the classroom, my main hobbies are electronics and Amateur Radio.

Contents

  1. License Copyright
  2. Thanks
  3. Labrary Features
  4. Library Installation
  5. Other Arduino Libraries developed by the Author
  6. API documentation
  7. Basic Schematic
  8. Internal Interrupt setup
  9. PCF8574 reset control
  10. References

MIT License

Copyright (c) 2019 Ricardo Lima Caratti

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE ARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Thanks

Labrary Features

This library uses the I²C communication protocol and implements most important functions offered by PCF8574 device from MicroChip. It also has primitive functions that make it easier to implement commands that may not have been implemented yet. The main features implemented can be seen below:

Demo video

PCF8574 Input/output setup with Arduino Nano Atmega 168

See on Youtube

Library Installation

Under construction..

You can install this library on your Arduino environment using different methods. The best ways to do that are described below.

Installing via Arduino IDE

This is the easiest method to install this library.

On Arduino IDE, select the “Manager Libraries…“ item and look for PCF8574. Finally select “PU2CLR PCF8574”.

More information

See also Installing an Arduino Library

Installing via this repository

First, you have to download this library in zip format. After, unzip the PCF8574-master.zip file in your Arduino Library folder.

With that approach, you will have the most current version of the library. However, it may not be the most stable version. This is because the current version is always in development. Prefer releases. Do you need some old version (release) of this library? If yes, check here.

Other Arduino Libraries developed by the Author

More Arduino Projects developed by author

PCF8574 pinout

DIP16 SO16 SSOP20
DIP16 SOP16 SSOP20

The table below shows the pin descriptions used by DIP16, SO16 and SSOP20

Pin Label pin number (DIP16/SO16) pin number (SSOP20) Description
A0 1 6 (*1) I2C address setup
A1 2 7 (*1) I2C address setup
A2 3 9 (*1) I2C address setup
P0 4 10 (*2) bidirectional I/O
P1 5 11 (*2) bidirectional I/O
P2 6 12 (*2) bidirectional I/O
P3 7 14 (*2) bidirectional I/O
GND 8 15 ground
P4 9 16 (*2) bidirectional I/O
P5 10 17 (*2) bidirectional I/O
P6 11 19 (*2) bidirectional I/O
P7 12 20 (*2) bidirectional I/O
INT 13 1 interrupt output (active LOW)
SCL 14 2 I2C serial clock
SDA 15 4 I2C serial data
VDD 16 5 +VCC - supply voltage
NC 3,8,13,18 not connected  

Basic schematic

The image below shows a basic PCF8574 application with LEDs and Buttons. You can control up to 8 LEDs or 8 buttons or a mix of them with this device. The I²C bus address is set to 0x20. You can select another I²C address by dealing with the A0,A1 and A2 pins (from 0x20 to 0x27). This circuit uses two LEDs connected to the ports P0 and P1 and the buttons connected to the port P4 to P7. All examples sketch use this setup.

PCF8574 Arduino setup and circuit


You may need to use external pull up or pull down resistors when you are using the ports as input to avoid unwanted voltage floating.

Prototype

The prototype below implements the circuit above.

PCF8574 prototype

Interrupt setup

Every time a port changes its status, PCF8574 sets the INT pin to a low logic level (0). You can use it to deal with Arduino interrupts.

References