Controlling some relay board with PCF8574

Hello,

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"  // https://github.com/xreef/PCF8574_library


const int iCtrlLed = 8;

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

  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);
  Serial.print(buffer);

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

  sprintf(buffer, " OFF\n");
  Serial.print(buffer);

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

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