Go Down

Topic: Cannot start with PCF8574 - no reaction to code (Read 525 times) previous topic - next topic


May 27, 2018, 06:48 pm Last Edit: May 27, 2018, 09:02 pm by ndd12

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 :(

Here is how i made connections:

Modified blink code:
Code: [Select]
#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:
github.com - PCF8574

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


May 27, 2018, 08:30 pm Last Edit: May 27, 2018, 08:32 pm by PaulRB
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 ...
Code: [Select]
  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.


May 27, 2018, 08:43 pm Last Edit: May 27, 2018, 08:49 pm by PaulRB
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:

Code: [Select]
expN.begin(); :)

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.
ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

Go Up