The PCF8574 is a ‘remote 8-bit I/O expander’, a parallel I/O chip controlled over an I2C bus interface: see Figure 2. It comes in two variants, which differ only in their I2C slave address. In the case of the PCF8574 the upper four bits of the address are 0100, while in the case of the PCF8574A they are 0111. This means that it is possible to connect up to sixteen PCF8574-series devices to a single I2C bus.
Internally there is just one register, which is directly connected to the port. When a bit pattern is written to the register, the port pins change state; if a bit is set to ‘1’, then the pin can also be used as an input. When the register is read the device returns the logic levels on the external I/O pins. Figure 3 shows how to connect a PCF8574 with an LED wired to port pin P0 to a Raspberry Pi. If a ‘1’ is written to the PCF8574:
i2cset -y 1 0x40 0x01
the LED will light. If a ‘0’ is written:
i2cset -y 1 0x40 0x00
the LED will extinguish. Strictly speaking we are here setting the register number to 0x01 or 0x00, since, according to the manual and online guides the i2cset command expects a register number after the device address. However, the port expander interprets the number as a data value representing the desired bit pattern on its outputs.
It is sometimes desirable to use a device like this to provide a degree of isolation between a computer and a peripheral: if an output pin should accidentally be shorted to 12 V, for example, then it is only the PCF8574 that is likely to suffer any harm. The PCF8574 is also used on simple LCD interface boards, allowing an I2C bus to drive the common one- or two-line LCD panels that employ the HD44780 controller IC. The LCD is operated in four-bit mode, and three further pins on the PCF8574 are connected to the LCD panel’s E, RS and R/W signals. The one remaining port bit is sometimes used to control the LCD backlight. Some of these boards include pull-up resistors on the bus lines to 5 V. These should normally be removed, or not fitted in the first place.