Problemas con las Interrupciones

Buenas tardes, soy nuevo en programación y con Arduino.
Estoy intentando crear un proyecto con Mega 2560, usando varios expansores PCF8575, con sus interrupciones.
La interrupción de cada expansor, la conecto a los pines 2 y3 (posteriormente serán 4 expansores conectados a las interrupciones (pines: 2, 3, 19 y 18).
Al ejecutar el sketch, sea cual sea el conexionado de las interrupciones, solo funciona la primera, en el caso de este programa, solo funciona la del pin 2.
Necesito ayuda, me he estancado aquí y después de una semana haciendo cambios, no consigo avanzar.
Un saludo¡

/* Direccionamiento de los Expansores, HEXADECIMAL:
HEX-----DEC  A2  A1  A0  Correcto en simulador PROTEUS
0X20    32   0   0   0   SI
OX21    33   0   0   1   SI    
0X22    34   0   1   0   SI
0X23    35   0   1   1   SI
0X24    36   1   0   0   SI
0X25    37   1   0   1   SI   
0X26    38   1   1   0   SI   
0X27    39   1   1   1   SI
*/

#include <Wire.h>
#include "Arduino.h"
#include "PCF8575.h"


//Asignación de Interrupciones
//#define INTERRUPCION_EXPANSOR_PCF8575_EL1 2
const int INTERRUPCION_EXPANSOR_PCF8575_EL1 = 2; 
//#define INTERRUPCION_EXPANSOR_PCF8575_EL2 3
const int INTERRUPCION_EXPANSOR_PCF8575_EL2 = 3;

// Asignación de direcciones I2C a cada expansor
PCF8575 PCF8575_EL1(0x20);
PCF8575 PCF8575_EL2(0x21);

//Declaración de los pines de Salidas Digitales
const int PinLed = 50;

//Declaramos la variable del PinLed como volatile bool
volatile bool LuzLed = HIGH;

// Bandera de tecla presionada en Expansor
volatile bool teclaPresionadaExpansorPCF8575_EL1 = false;
volatile bool teclaPresionadaExpansorPCF8575_EL2 = false;

//Funciones de las Interrupciones
void ISRExpansor_PCF8575_EL1() {
  teclaPresionadaExpansorPCF8575_EL1 = true;
}

void ISRExpansor_PCF8575_EL2() {
  teclaPresionadaExpansorPCF8575_EL2 = true;
}

//SETUP
void setup() {
  //Serial.begin(115200);
  Wire.begin();  //Probar a ver cual es la velocidad idónea
  pinMode(INTERRUPCION_EXPANSOR_PCF8575_EL1, INPUT_PULLUP); // SEGURAMENTE HABRÁ QUE DESACTIVAR ESTA LÍNEA
  attachInterrupt(digitalPinToInterrupt(INTERRUPCION_EXPANSOR_PCF8575_EL1), ISRExpansor_PCF8575_EL1, FALLING); // FALLING   // RISING

  pinMode(INTERRUPCION_EXPANSOR_PCF8575_EL2, INPUT_PULLUP); // SEGURAMENTE HABRÁ QUE DESACTIVAR ESTA LÍNEA
  attachInterrupt(digitalPinToInterrupt(INTERRUPCION_EXPANSOR_PCF8575_EL2), ISRExpansor_PCF8575_EL2, FALLING);

//Entradas de cada uno de los expansores, en decimal a partir de 0
//ENTRADAS DEL EXPANSOR PCF8575_EL1
  PCF8575_EL1.pinMode(4,INPUT);   //Pulsador 4 DE EL1

//ENTRADAS DEL EXPANSOR PCF8575_EL2
  PCF8575_EL2.pinMode(10,INPUT); //Pulsador  10 DE EL2
  
  //Inicializamos los expansores de Entradas
  PCF8575_EL1.begin();
  PCF8575_EL2.begin();
}

//FUNCIONES PARA ENCENDER LAS LUCES , SALIDAS DIGITALES DEL ARDUINO MEGA 2560
void enciendeLuzLed(){
  LuzLed = !LuzLed;
  digitalWrite(PinLed,LuzLed);
}

//Entradas de cada uno de los expansores, en propiedades del IC
void loop() {
    //EXPANSOR PCF8575_EL1
  if (teclaPresionadaExpansorPCF8575_EL1) {
    PCF8575::DigitalInput Pin_EL1 = PCF8575_EL1.digitalReadAll();

    if (Pin_EL1.p4 == HIGH) {
      enciendeLuzLed();
     //Pulsador DE EL1
    }
    teclaPresionadaExpansorPCF8575_EL1 = false; // false
  }

  //EXPANSOR PCF8575_EL2
  if (teclaPresionadaExpansorPCF8575_EL2) {
    PCF8575::DigitalInput Pin_EL2 = PCF8575_EL2.digitalReadAll();

    if (Pin_EL2.p12 == HIGH) {
      enciendeLuzLed();
      //Pulsador DE EL2
    }
    teclaPresionadaExpansorPCF8575_EL2 = false; // false
  }
}

He trasladado su tema de una categoría de idioma inglés del foro a la categoría International > Español @tigre_1964.

En adelante por favor usar la categoría apropiada a la lengua en que queráis publicar. Esto es importante para el uso responsable del foro, y esta explicado aquí la guía "How to get the best out of this forum".
Este guía contiene mucha información útil. Por favor leer.

De antemano, muchas gracias por cooperar.

Moderador
No uses el foro en inglés publicando en español.
Lee las normas del foro, ya te las indicó el moderador @pert

Encontré un ejemplo en wokwi.com que usa el PCF8575 y lo expandí a dos dispositivos.

El código

#include <I2cDiscreteIoExpander.h>
#include <Wire.h> // No olvides incluir Wire explícitamente

#define PIN_PCF_INTERRUPT1_INPUT     2
#define PIN_GOT_INTERRUPT1_INDICATOR 9

#define PIN_PCF_INTERRUPT2_INPUT     3
#define PIN_GOT_INTERRUPT2_INDICATOR 10

// Direcciones I2C (Asegúrate que coinciden con tus jumpers)
// 0x20 -> pcf1
// 0x21 -> pcf2

I2cDiscreteIoExpander pcf1(0x20); 
I2cDiscreteIoExpander pcf2(0x21);

volatile bool haveInt1 = false; // Nombres coinciden con pcf1 y pcf2
volatile bool haveInt2 = false;

// Rutinas de Interrupción (ISR)
void isrPcf1() { haveInt1 = true; }
void isrPcf2() { haveInt2 = true; }

// Función  para leer y actualizar salidas
void mirrorInputOntoOutputs(I2cDiscreteIoExpander &dev, uint8_t id) {
    
    // 1. Realizamos la lectura I2C (esto limpia la interrupción en el chip)
    dev.digitalRead(); 
    uint16_t currentPorts = dev.getPorts();

    // 2. Extraemos las entradas (Bits 0-7)
    uint16_t inputs = currentPorts & 0x00FF;

    Serial.print("[PCF"); Serial.print(id); Serial.print("] Inputs=0x");
    Serial.print(inputs, HEX);

    // 3. Preparamos el valor a escribir.
    // - inputs << 8: Movemos lo leído en las entradas a las salidas (Bits 8-15)
    // - | 0x00FF: IMPRESCINDIBLE. Escribimos 1 en los bits de entrada para que
    //             sigan funcionando como entradas (Open Drain).
    uint16_t newValue = (inputs << 8) | 0x00FF;

    // 4. Escribimos
    dev.digitalWrite(newValue);

    Serial.print("  -> NewOutputs=0x");
    Serial.println(newValue, HEX);
}

void setup()
{
  Wire.begin();
  Serial.begin(115200);
  
  // Pines del Arduino
  pinMode(PIN_PCF_INTERRUPT1_INPUT, INPUT_PULLUP);
  pinMode(PIN_GOT_INTERRUPT1_INDICATOR, OUTPUT);

  pinMode(PIN_PCF_INTERRUPT2_INPUT, INPUT_PULLUP);
  pinMode(PIN_GOT_INTERRUPT2_INDICATOR, OUTPUT);

  // --- CONFIGURACIÓN PCF 1 (0x20) ---
  Serial.println("Configurando PCF1...");
  pcf1.disableBitwiseInversion(); // Aplicamos la config al objeto REAL
  pcf1.digitalWrite(0xFFFF);      // Todo a HIGH para empezar (modo entrada)
  
  // --- CONFIGURACIÓN PCF 2 (0x21) ---
  Serial.println("Configurando PCF2...");
  pcf2.disableBitwiseInversion(); // Importante hacerlo en ambos si son iguales
  pcf2.digitalWrite(0xFFFF);

  // Pequeño test visual inicial
  flashLED(pcf1, 3);

  // Limpieza inicial: Leemos para asegurar que la linea INT esté HIGH antes de activar interrupciones
  mirrorInputOntoOutputs(pcf1, 1);
  mirrorInputOntoOutputs(pcf2, 2);
  delay(100);

  Serial.println("ATTACHING INTERRUPTS...");
  // INT 0 es Pin 2 en Arduino Uno/Nano, verifica en ESP32
  attachInterrupt(digitalPinToInterrupt(PIN_PCF_INTERRUPT1_INPUT), isrPcf1, FALLING);
  attachInterrupt(digitalPinToInterrupt(PIN_PCF_INTERRUPT2_INPUT), isrPcf2, FALLING);

  Serial.println("Ready.");
}

void flashLED(I2cDiscreteIoExpander &dev, uint8_t n) {
  for (uint8_t i=0; i<n; i++) {
    // Parpadea solo la parte alta (Outputs), mantén la baja en 1 (Inputs)
    dev.digitalWrite(0x00FF); // LEDs ON (si son active high) o OFF (si active low) + Inputs Ready
    delay(100);
    dev.digitalWrite(0xFFFF); // Todo High
    delay(80);
  }
}

void loop() {

  // --- MÁQUINA DE ESTADOS PARA PCF 1 ---
  if (haveInt1) {
    Serial.println("!!! INT PCF 1 Detectada !!!");
    
    // Hacemos el espejo
    mirrorInputOntoOutputs(pcf1, 1);
    
    // Indicador visual en el Arduino
    digitalWrite(PIN_GOT_INTERRUPT1_INDICATOR, HIGH);
    
    // Resetear bandera
    haveInt1 = false;
  } else {
    digitalWrite(PIN_GOT_INTERRUPT1_INDICATOR, LOW);
  }

  // --- MÁQUINA DE ESTADOS PARA PCF 2 ---
  if (haveInt2) {
    Serial.println("!!! INT PCF 2 Detectada !!!");
    
    mirrorInputOntoOutputs(pcf2, 2);
    
    digitalWrite(PIN_GOT_INTERRUPT2_INDICATOR, HIGH);
    haveInt2 = false;
  } else {
    digitalWrite(PIN_GOT_INTERRUPT2_INDICATOR, LOW);
  }

  delay(50); // Pequeño delay para no saturar Serial
}

Expándelo a los 4 que necesitas usando el MEGA.

Buenas tardes.
Primero, les pido disculpas, no me dí cuenta que estaba en el foro en inglés, lo siento !!!
En cuanto al software facilitado, voy a estudiarlo a fondo, seguro que puedo adaptarlo a mis necesidades.
Muchas gracias por su inestimable ayuda !
Un saludo !!!

Lo que te pasé puede expandirse fácilmente a 4 interrupciones, indica los pines correspondientes.

#define PIN_PCF_INTERRUPT1_INPUT     2
#define PIN_GOT_INTERRUPT1_INDICATOR 9  // indicador optativo

#define PIN_PCF_INTERRUPT2_INPUT     3
#define PIN_GOT_INTERRUPT2_INDICATOR 10  // indicador optativo

#define PIN_PCF_INTERRUPT1_INPUT     18
#define PIN_GOT_INTERRUPT1_INDICATOR 11  // indicador optativo

#define PIN_PCF_INTERRUPT2_INPUT     19
#define PIN_GOT_INTERRUPT2_INDICATOR 12  // indicador optativo

Mucha atención en el direccionamiento de cada PCF8575

I2cDiscreteIoExpander pcf1(0x20); 
I2cDiscreteIoExpander pcf2(0x21);
I2cDiscreteIoExpander pcf3(0x22); 
I2cDiscreteIoExpander pcf4(0x23);

Agrega 4 variables volátiles para indicar cuando se producen las interrupciones.

volatile bool haveInt1 = false; // Nombres coinciden con pcf1 y pcf2
volatile bool haveInt2 = false;
volatile bool haveInt3 = false; // Nombres coinciden con pcf3 y pcf4
volatile bool haveInt4 = false;

// Rutinas de Interrupción (ISR)
void isrPcf1() { haveInt1 = true; }
void isrPcf2() { haveInt2 = true; }
void isrPcf3() { haveInt3 = true; }
void isrPcf4() { haveInt4 = true; }

Luego en el setup define los 4 pines como entradas pullup

  // Pines del Arduino
  pinMode(PIN_PCF_INTERRUPT1_INPUT, INPUT_PULLUP);
  pinMode(PIN_GOT_INTERRUPT1_INDICATOR, OUTPUT);

  pinMode(PIN_PCF_INTERRUPT2_INPUT, INPUT_PULLUP);
  pinMode(PIN_GOT_INTERRUPT2_INDICATOR, OUTPUT);

  pinMode(PIN_PCF_INTERRUPT3_INPUT, INPUT_PULLUP);
  pinMode(PIN_GOT_INTERRUPT3_INDICATOR, OUTPUT);

  pinMode(PIN_PCF_INTERRUPT4_INPUT, INPUT_PULLUP);
  pinMode(PIN_GOT_INTERRUPT4_INDICATOR, OUTPUT);

Y la cosas sigue del mismo modo y con el mismo criterio.

Usar NANO y usar MEGA no cambia mucho. Selecciona tu placa y funcionará.
Si tienes problemas nos consultas.

Buenas noches.
Creo que ya tengo la solución, voy a hacer unas pruebas reales, y si todo funcione correctamente, subiré el sotfware final.
Muchas gracias por vuestra ayuda.
Un cordial saludo de Miguel Llorca.