Cannot start with PCF8574 - no reaction to code


I'm trying to make a specific game controller (with 24 buttons) so i need to use PCF8574 to get more inputs. Firstly i'm trying to just to connect it to arduino leonardo and for start control just LEDs. And I'm stuck right on first try :frowning:

Here is how i made connections:

Modified blink code:

#include <PCF8574.h>
#include <Wire.h>

PCF8574 expN(0x20);

void setup() {

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);
  digitalWrite(LED_BUILTIN, LOW);

I'm using this library: - PCF8574

After uploading code to board nothing happens. Even builtin LED does not blink. Any advice? Cant understand whats is wrong here.

Thanks for using code tags, but please read the forum guidelines in the sticky post about posting images correctly.

Please post a schematic. We need to know how you connected the pcf chip.

Have you tried the i2c scanner sketch? That will tell you if the chip is connected correctly and responding as it should.

The I/O pins on this chip only source 100µA.

You should read the data sheet on how they are 'quasi bi-directional'.
In a nutshell:

When you set them high, they are pulled up to VCC with a 100µA source.
This means they can 'easily' be pulled low externally.
To use them as input, you set them high and then read back the actual state.

When you drive them low, you connect them to ground.
So they can not source more than 100µA, but they may sink 20mA.

If you turn your LEDs around, connect your I/O pins to the cathodes of your LEDs, and the anodes to +5V, (and have those series resistors in there) they should blink.

By the way ...   expN.write8(HIGH); I would guess that this function takes an 8 bit argument, 1 bit for each pin, and passing HIGH would only blink P0.

Jobi-Wan is correct. You must connect your LEDs & series resistors between 5V and the pcf pins, otherwise the current will be so small that the LEDs will not be visible.

But the fact that the built-in led does not flash indicates that there is a problem with i2c communications, so try the i2c scanner.

the fact that the built-in led does not flash

Ah yes, overlooked that minor insignificant little detail... :-[

If the scanner indicates that the chip is alive at the expected address, see if the library comes with any examples. You may have to do some initialisation in setup()

Hey! Thanks for replies. I figured out that testing with LEDs when i want to use it to handle buttons is a little bit pointless so connected button instead and began testing more. And the problem with not even blinking was that there was needed one extra line of code:

expN.begin(); :slight_smile:

And i didnt know about that i2c scanner, great thing!

You should also put a 0.1uf ceramic cap between the Vcc and Gnd pins of the PCF' (generally, you need to do this for any digital integrated circuit unless the datasheet specifies otherwise), and this cap should be right next to the chip, as close as possible. Without it, under some conditions, the PCF' may unexpectedly reset or otherwise misbehave - the sort of unpredictable behavior this results in is extremely difficult to debug - including the cap is a very cheap defense against wasting hours debugging intermitant misbehavior due to insufficient decoupling.