Controlling some relay board with PCF8574


I want control some relay board with some PCF8574.

For the first relay board (8 relay) its ok my sketch is running (8 relay activate one by one), but now i

want add one more PCF8574 and one more relay board (8 relay) but this doesnt run.

Sorry for my english.

You can find in attachement my sketch

Could you help me to control the second relay board?

sketch_may07b.ino (6.85 KB)

Get the PCF8574 library and use it. Then you can easily create one object for each PCF8574.

Some code from a test I have done (it controls LEDs for the test):

#include "Arduino.h"
#include "PCF8574.h"  //

const int iCtrlLed = 8;

PCF8574 chips[2] = {PCF8574(0x20), PCF8574(0x21)};
void setup()
  for (int i = 0; i < 8; i++) {
    chips[0].pinMode(i, OUTPUT);
    chips[1].pinMode(i, OUTPUT);

  pinMode(iCtrlLed, OUTPUT);
  digitalWrite(iCtrlLed, LOW);

void loop()
  static int  loop = 0;
  static int  pin = 0;
  static int  port = 0;
  static int  sleepTime = 30;
  char        buffer[30];

  sprintf(buffer, "#%d: Pin %d-%d ON", ++loop, chip, pin);

  digitalWrite(iCtrlLed, HIGH);
  chips[port].digitalWrite(pin, HIGH);

  sprintf(buffer, " OFF\n");

  digitalWrite(iCtrlLed, LOW);
  chips[port].digitalWrite(pin, LOW);

  if (++pin > 7) {
    pin = 0;
    if (++port > 2) {
      port = 0;