Blynk, 4xPCF8574 and 32 relay relay problem

I connected 4 pcs PCF8574 to control 32 relays. In principle it works too. But there is a problem after rebooting the ESP32. After successful connection with the Blynkserver I start the Blynkapp and press Button 1. Now all relays connected to the first PCF8574 switch on. I then have to turn on all 8 relays in the app and then switch off again, then it works correctly.

What have I already tried? I’ve set all the pins high (which you do not really need since they’re usually high already). But do not change the behavior.

What else could I do to make it work properly? Have read a lot, but can not get on. Please help. thanks

And please excuse my English is not my native language

Blynk runs on a local server on my Raspberry Pi 3+

ESP32 Dev v3 and power supply 220 volts to 5 volts 2 amps

PS: Have now again Blynk.virtualWrite HIGH rausgenommen. Same behavior. after reboot of the ESP32 are all relays off, but I press V1 or V9 in the app, all 8 or 16 relays have gone on. At the 2 channel relay this effect does not occur, here it goes as it should. Is only so with the two 16 channel relay modules.

#define BLYNK_PRINT Serial
#include <PCF8574.h> 
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <Wire.h>
#define SDA_PIN 21 //GPIO21 on ESP32
#define SCL_PIN 22 //GPIO22 on ESP32

PCF8574 addr1 (0x20);          // PCF8574 device (addr1) 1 ACHTUNG! Adresse 0x20 einstellen A0>0,A1>0,A2>0 Port-Bereich P0-P8 (addr Namen kann man frei wählen)
PCF8574 addr2 (0x21);          // PCF8574 device (addr2) 2 ACHTUNG! Adresse 0x21 einstellen A0>1,A1>0,A2>0 Port-Bereich P0-P8
PCF8574 addr3 (0x22);          // PCF8574 device (addr3) 3 ACHTUNG! Adresse 0x22 einstellen A0>0,A1>1,A2>0 Port-Bereich P0-P8
PCF8574 addr4 (0x23);          // PCF8574 device (addr4) 4 ACHTUNG! Adresse 0x23 einstellen A0>1,A1>1,A2>0 Port-Bereich P0-P8
//PCF8574 addr5 (0x24);        // PCF8574 device (addr5) 5 ACHTUNG! Adresse 0x24 einstellen A0>0,A1>0,A2>1 Port-Bereich P0-P8
//PCF8574 addr6 (0x25);        // PCF8574 device (addr6) 6 ACHTUNG! Adresse 0x25 einstellen A0>1,A1>0,A2>1 Port-Bereich P0-P8
//PCF8574 addr7 (0x26);        // PCF8574 device (addr7) 7 ACHTUNG! Adresse 0x26 einstellen A0>0,A1>1,A2>1 Port-Bereich P0-P8
//PCF8574 addr8 (0x27);        // PCF8574 device (addr8) 8 ACHTUNG! Adresse 0x27 einstellen A0>1,A1>1,A2>1 Port-Bereich P0-P8


char auth[] = "xxxxxxxxxx";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxxxxxxxxx";
char pass[] = "xxxxxxxxxx";


int pinValue1;
BLYNK_WRITE(V1){
  int pinValue1 = param.asInt();
  addr1.digitalWrite(0, pinValue1);
}
int pinValue2;
BLYNK_WRITE(V2){
  int pinValue2 = param.asInt();
  addr1.digitalWrite(1, pinValue2);
}
int pinValue3;
BLYNK_WRITE(V3){
  int pinValue3 = param.asInt();
  addr1.digitalWrite(2, pinValue3);
}
int pinValue4;
BLYNK_WRITE(V4){
  int pinValue4 = param.asInt();
  addr1.digitalWrite(3, pinValue4);
}
int pinValue5;
BLYNK_WRITE(V5){
  int pinValue5 = param.asInt();
  addr1.digitalWrite(4, pinValue5);
}
int pinValue6;
BLYNK_WRITE(V6){
  int pinValue6 = param.asInt();
  addr1.digitalWrite(5, pinValue6);
}
int pinValue7;
BLYNK_WRITE(V7){
  int pinValue7 = param.asInt();
  addr1.digitalWrite(6, pinValue7);
}
int pinValue8;
BLYNK_WRITE(V8){
  int pinValue8 = param.asInt();
  addr1.digitalWrite(7, pinValue8);
}
int pinValue9;
BLYNK_WRITE(V9){
  int pinValue9 = param.asInt();
  addr2.digitalWrite(0, pinValue9);
}
int pinValue10;
BLYNK_WRITE(V10){
  int pinValue10 = param.asInt();
  addr2.digitalWrite(1, pinValue10);
}
int pinValue11;
BLYNK_WRITE(V11){
  int pinValue11 = param.asInt();
  addr2.digitalWrite(2, pinValue11);
}
int pinValue12;
BLYNK_WRITE(V12){
  int pinValue12 = param.asInt();
  addr2.digitalWrite(3, pinValue12);
}
int pinValue13;
BLYNK_WRITE(V13){
  int pinValue13 = param.asInt();
  addr2.digitalWrite(4, pinValue13);
}
int pinValue14;
BLYNK_WRITE(V14){
  int pinValue14 = param.asInt();
  addr2.digitalWrite(5, pinValue14);
}
int pinValue15;
BLYNK_WRITE(V15){
  int pinValue15 = param.asInt();
  addr2.digitalWrite(6, pinValue15);
}
int pinValue16;
BLYNK_WRITE(V16){
  int pinValue16 = param.asInt();
  addr2.digitalWrite(7, pinValue16);
}
int pinValue17;
BLYNK_WRITE(V17){
  int pinValue17 = param.asInt();
  addr3.digitalWrite(0, pinValue17);
}
int pinValue18;
BLYNK_WRITE(V18){
  int pinValue18 = param.asInt();
  addr3.digitalWrite(1, pinValue18);
}
int pinValue19;
BLYNK_WRITE(V19){
  int pinValue19 = param.asInt();
  addr3.digitalWrite(2, pinValue19);
}
int pinValue20;
BLYNK_WRITE(V20){
  int pinValue20 = param.asInt();
  addr3.digitalWrite(3, pinValue20);
}
int pinValue21;
BLYNK_WRITE(V21){
  int pinValue21 = param.asInt();
  addr3.digitalWrite(4, pinValue21);
}
int pinValue22;
BLYNK_WRITE(V22){
  int pinValue22 = param.asInt();
  addr3.digitalWrite(5, pinValue22);
}
int pinValue23;
BLYNK_WRITE(V23){
  int pinValue23 = param.asInt();
  addr3.digitalWrite(6, pinValue23);
}
int pinValue24;
BLYNK_WRITE(V24){
  int pinValue24 = param.asInt();
  addr3.digitalWrite(7, pinValue24);
}
int pinValue25;
BLYNK_WRITE(V25){
  int pinValue25 = param.asInt();
  addr4.digitalWrite(0, pinValue25);
}
int pinValue26;
BLYNK_WRITE(V26){
  int pinValue26 = param.asInt();
  addr4.digitalWrite(1, pinValue26);
}
int pinValue27;
BLYNK_WRITE(V27){
  int pinValue27 = param.asInt();
  addr4.digitalWrite(2, pinValue27);
}
int pinValue28;
BLYNK_WRITE(V28){
  int pinValue28 = param.asInt();
  addr4.digitalWrite(3, pinValue28);
}
int pinValue29;
BLYNK_WRITE(V29){
  int pinValue29 = param.asInt();
  addr4.digitalWrite(4, pinValue29);
}
int pinValue30;
BLYNK_WRITE(V30){
  int pinValue30 = param.asInt();
  addr4.digitalWrite(5, pinValue30);
}
int pinValue31;
BLYNK_WRITE(V31){
  int pinValue31 = param.asInt();
  addr4.digitalWrite(6, pinValue31);
}
int pinValue32;
BLYNK_WRITE(V32){
  int pinValue32 = param.asInt();
  addr4.digitalWrite(7, pinValue32);
}
  // Debug console
void setup() 
{  
   Blynk.begin(auth, ssid, pass, IPAddress(192, 168, 0, 19), 8080);
  
   addr1.begin();
   addr2.begin();
   addr3.begin();
   addr4.begin();
   addr1.pinMode (0, OUTPUT);
   addr1.pinMode (1, OUTPUT);
   addr1.pinMode (2, OUTPUT);
   addr1.pinMode (3, OUTPUT);
   addr1.pinMode (4, OUTPUT);
   addr1.pinMode (5, OUTPUT);
   addr1.pinMode (6, OUTPUT);
   addr1.pinMode (7, OUTPUT);
   addr2.pinMode (0, OUTPUT);
   addr2.pinMode (1, OUTPUT);
   addr2.pinMode (2, OUTPUT);
   addr2.pinMode (3, OUTPUT);
   addr2.pinMode (4, OUTPUT);
   addr2.pinMode (5, OUTPUT);
   addr2.pinMode (6, OUTPUT);
   addr2.pinMode (7, OUTPUT);
   addr3.pinMode (0, OUTPUT);
   addr3.pinMode (1, OUTPUT);
   addr3.pinMode (2, OUTPUT);
   addr3.pinMode (3, OUTPUT);
   addr3.pinMode (4, OUTPUT);
   addr3.pinMode (5, OUTPUT);
   addr3.pinMode (6, OUTPUT);
   addr3.pinMode (7, OUTPUT);
   addr4.pinMode (0, OUTPUT);
   addr4.pinMode (1, OUTPUT);
   addr4.pinMode (2, OUTPUT);
   addr4.pinMode (3, OUTPUT);
   addr4.pinMode (4, OUTPUT);
   addr4.pinMode (5, OUTPUT);
   addr4.pinMode (6, OUTPUT);
   addr4.pinMode (7, OUTPUT);
   Blynk.virtualWrite(V1, HIGH);
   Blynk.virtualWrite(V2, HIGH);
   Blynk.virtualWrite(V3, HIGH);
   Blynk.virtualWrite(V4, HIGH);
   Blynk.virtualWrite(V5, HIGH);
   Blynk.virtualWrite(V6, HIGH);
   Blynk.virtualWrite(V7, HIGH);
   Blynk.virtualWrite(V8, HIGH);
   Blynk.virtualWrite(V9, HIGH);
   Blynk.virtualWrite(V10, HIGH);
   Blynk.virtualWrite(V11, HIGH);
   Blynk.virtualWrite(V12, HIGH);
   Blynk.virtualWrite(V13, HIGH);
   Blynk.virtualWrite(V14, HIGH);
   Blynk.virtualWrite(V15, HIGH);
   Blynk.virtualWrite(V16, HIGH);
   Blynk.virtualWrite(V17, HIGH);
   Blynk.virtualWrite(V18, HIGH);
   Blynk.virtualWrite(V19, HIGH);
   Blynk.virtualWrite(V20, HIGH);
   Blynk.virtualWrite(V21, HIGH);
   Blynk.virtualWrite(V22, HIGH);
   Blynk.virtualWrite(V23, HIGH);
   Blynk.virtualWrite(V24, HIGH);
   Blynk.virtualWrite(V25, HIGH);
   Blynk.virtualWrite(V26, HIGH);
   Blynk.virtualWrite(V27, HIGH);
   Blynk.virtualWrite(V28, HIGH);
   Blynk.virtualWrite(V29, HIGH);
   Blynk.virtualWrite(V30, HIGH);
   Blynk.virtualWrite(V31, HIGH);
   Blynk.virtualWrite(V32, HIGH);
 }

  

void loop()
{
  Blynk.run();
//  timer.run();
}

Not really related to your problem (I don’t think so anyway), But doing 32 sequential Blynk.virtualWrites in the void setup probably isn’t a good idea.
I assume that this is related to what you said here:

but setting the widgets to 1 (HIGH or On) isn’t the same as setting the pins HIGH.
I would have expected something like…
addr1.digitalWrite (0, HIGH);
addr1.digitalWrite (1, HIGH);

to be used to set the pins HIGH.

Pete.

The pins of the PCF8574 modules are automatically all high on startup. That’s why I took it out again.

All relays are off after a restart, as it should. But if I press a butt in the app, all relays will go to the connected PCF8574. I have to then turn on the app all first and then turn off again. Afterwards it works properly again as it should. The first press in the app, the pins are set to low and therefore all 8 relays are also on.

How could one prevent that? What must / can I change in the sketch?

hello i have a question about the pcf8574. I recreated the project and wanted to change 2 inputs per IC. I would like to connect 2 buttons.
can you help me? example: with WidgetLED led?
i liked two leds and 6 Switches on aApp.
now there are 8 switches

Thanks

hello i have a question. do you have time?
about your program?

@magnum1795 last visited the forum in October 2020.
By tagging him in this topic he’ll get an email, assuming that he has email notifications turned on, so he may respond

In the meantime, re-posting the same question isn’t going to help.

Pete.