IO Abstraction library fully supports the PCF8574 8-bit and PCF8575 16-bit IO expander chips on Arduino and mbed. It requires only two pins (three for interrupt mode) SDA, SCL, and optionally INT. Our driver integrates the interrupt support for you so you can attach interrupts very easily.
The PCF8574 provides 8 additional input or output ports, but there are few limitations around how the device can be used, and these are discussed below. This device can be used for switches, rotary encoders, and with LiquidCrystalIO.
There’s a few things to note about this device:
optionalInterruptPin
. Omit or set to 0xFF for when you don’t want interrupts.// simplest construction, 8 bit PCF8574 on an address with interrupt
PCF8574IoAbstraction ioExpander(i2cAddress, interruptPin);
// full construction, on Wire1, with 16bit device and inverted logic options.
PCF8574IoAbstraction ioExpander(i2cAddress, interruptPin, &Wire1, is16Bit, inverted);
// simple 16 bit exmaple
PCF8574IoAbstraction ioExpander(i2cAddress, interruptPin, &Wire, true);
We can see above that we simply create an instance of the class, the parameters are full explained in the PCF8574 reference documentation.
Once you have created an instance, simply use it like any other IoAbstraction they all work the same way.
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.