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:
First power down the Arduino and build the circuit below.
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.