I/O expander, PCF8574
Eight more pins on two wires. No registers: a byte out is the pins, a byte in is what they read.
- 13 pins
- 1 setting
- In 2 projects
- In 1 lesson
The I/O expander, PCF8574 in brief
What it is, and every setting the properties panel gives it.
The PCF8574 adds eight pins to a board over two I2C wires, and it is the same chip that sits on the back of every I2C LCD backpack. It is about as simple as a chip can be: there are no registers. Each byte written after the address appears on its eight pins, P0 in bit 0; each byte read is their levels. A pin written 0 pulls hard to ground and can sink an LED’s current; a pin written 1 is only held up weakly, so anything outside can pull it down, which is how a pin becomes an input. The board’s jumpers set the address from 0x20 to 0x27, or 0x38 to 0x3F on the PCF8574A. Mokxi models the port in both directions, power-up with every pin high, and the INT pin falling when an input changes and releasing on the next read or write.
- Family
- Logic
- Pins
- 13
- address
- 32
13 pins
Named as the editor names them, so a wire lands where you expect it.
How to add eight pins to an Arduino with a PCF8574
VCC to 5 V, GND to ground, SDA to A4 and SCL to A5. The More pins project leaves the address at 0x20 and puts an MCP23017 on the same bus, so you can compare the two expanders side by side.
No library is needed. Wire.beginTransmission(0x20), Wire.write() one byte, Wire.endTransmission(), and the eight pins take its bits. The project writes a byte with one 0 in it and moves that 0 along P0 to P3 every 250 ms; the other pins stay at 1. To see it, add LEDs that run from 5 V through a resistor into P0 to P3, since a PCF8574 lights an LED by pulling its pin low. To read buttons, write 1 to their pins first, wire each button from the pin to ground, and Wire.requestFrom(0x20, 1) returns a byte where a pressed button is a 0.
The chip runs from 2.5 to 6 V, so on a 3.3 V board power it from 3.3 V and use the board’s own SDA and SCL; the bytes are the same.
Wire.beginTransmission(0x20);
Wire.write((uint8_t)~(1 << step)); // one pin low, the rest high
Wire.endTransmission();
step = (step + 1) % 4;Common I/O expander, PCF8574 errors and fixes
Questions and answers
Does the PCF8574 need a library?
No. Wire is the whole driver: one byte out sets all eight pins and one byte in reads them. Libraries such as Rob Tillaart’s PCF8574 add per-pin calls on top.
How many PCF8574 boards can I put on one bus?
Eight of the PCF8574 and eight of the PCF8574A, since their address ranges do not overlap: up to 128 extra pins on two wires.
Is the PCF8574 the chip on an I2C LCD backpack?
Yes. The backpack wires its eight pins to the display’s data and control lines, which is why those displays usually show up at 0x27 or 0x3F.
Can a PCF8574 pin drive an LED from the pin to ground?
Not usefully. A high pin only supplies about 100 µA, so the LED barely glows. Sink the current instead: LED from VCC into the pin.
What is true about the I/O expander, PCF8574, here
In its help article’s own words: what the simulation gets right, and where it stops.
Modeled
The port, both ways, as above; power-up with every pin high. INT goes low when a
pin's level stops matching what it was at the last read or write, and a read or write
lets it go, which is the datasheet's rule. A write's own pins settling do not raise
it.
Not modeled
The brief strong pull-up a real chip gives a pin as it is written from 0 to 1. The weak pull-up is a 50 kΩ resistor here rather than a current source. The 25 mA sink limit: a pin pulled low sinks whatever the circuit asks.
From PCF8574 I/O expander, in full.
See the I/O expander, PCF8574 in a project
2 built-in projects use it. Each opens in the editor, already wired.
Where it turns up in a lesson
One lesson places it in its own circuit.
The boards it is shown on
This board has a built-in project with the I/O expander, PCF8574 in it.
Arduino libraries for the I/O expander, PCF8574
Built in, so the sketch compiles with nothing to install. Each page has the calls, the wiring and an example to run.
The rest of the bench
Every one of these is drawn and simulated the same way.
Wire up the I/O expander, PCF8574
Open the editor and push it into the breadboard. It is free, and it runs on your own machine.