By dave | October 20, 2017

PCF8574 i2c - IO Abstraction library example

Here we demonstrate the IO Abstraction library on an Arduino with a PCF8574 i2c 8-bit IO expander chip. We use the device in order to receive input from a switch and light an LED. It’s about the most basic example possible that has both input and output. To use this example, first download the IoAbstraction library.

Devices such as the PCF8574 provide an easy way to expand both input and output capabilities using a single chip, and because it’s on i2c, needs only two pins from the Arduino (SDA and SCL). Further, when used with the IO Abstraction library, it’s almost as easy to use as Arduino pins.

There’s a few things to note about this device:

  • When it is an output it can only really sink current, so can provide more power in the low state. (that is why the LED connects from 5V to the chip).
  • When it is an input, the pin should be high. You can then pull to LOW.
  • This device cannot operate in high speed mode. Therefore, the safe maximum bus speed is 100Khz. Use an MCP23017 if this is a problem.

Building the circuit and getting the sketch

First power down the Arduino and build the circuit below.

Circuit example for PCF8574 i2c

Schematic for connecting PCF8574 to Arduino

In the circuit below, we connect the PCF8574 IO expansion device to the power (5V-pin16 and GND-pin8) with a 0.1uF decoupling capacitor near the chip between the power rails. Also, note that we must select an address that the chip answers on using A0-A2. Notice that the LED must be connected from 5V to the pin through a resistor, this is the only way it will work, as this chip cannot source very much current, but it can sink a lot more.

To find your i2c device address use this i2c address scanner, this sketch will tell you every address on which it finds an i2c chip.

Example showing use of PCF8574 and regular IO. One of the IoAbstraction library examples.

Go back to the IoAbstraction page

Other pages within this category

comments powered by Disqus

This site uses cookies to analyse traffic, serve ads by Google AdSense (non-personalized in EEA/UK), and to record consent. We also embed Twitter, Youtube and Disqus content on some pages, these companies have their own privacy policies.

Our privacy policy applies to all pages on our site

Should you need further guidance on how to proceed: External link for information about cookie management.