I2C Relays not working after power cycle (work after ESP32 reset)

In my project I have 2 x MCP23017 expanders. One drives LEDs and the other drives Relays.

The LEDs work reliably.
The relays don’t work when the ESP32 is powered on.
The relays do work reliably after the ESP32 is reset (via the reset button on ESP32-DevKit4c).
If the ESP32 is power cycled the relays cease operating again

Clearly one wants the relays to work when powered on.

Given the LEDs work reliably, it could indicate an issue with the MCP23017 / relay hardware circuit that is the cause.
Given the relays work reliably after an ESP32 reset, it suggests that the issue could be with some difference between a power on cycle and a reset cycle.

Below is my test code that exhibits the issue:

#include <Arduino.h>
#include <IoAbstraction.h>
#include <IoAbstractionWire.h>
#include <TaskManagerIO.h>

#define I2C_SDA 22
#define I2C_SCL 21

#define EXPANDER_U3     100
#define EXPANDER_U4     116

#define LED_PIN         100
#define RELAY_PIN       116

MultiIoAbstractionRef multi_io = multiIoExpander(EXPANDER_U3);

/* **** standard setup() function **** */
void setup() {
Wire.begin(I2C_SDA, I2C_SCL);

// Add 2 x MCP23017 chips that allocates 16 more pins each to the dio_device, therefore it goes from 100..131
multiIoAddExpander(multi_io, ioFrom23017(0x22), 16);
multiIoAddExpander(multi_io, ioFrom23017(0x23), 16);

ioDevicePinMode(multi_io, LED_PIN, OUTPUT);
ioDevicePinMode(multi_io, RELAY_PIN, OUTPUT);
}

void loop() {
// toggle LED and Relay
ioDeviceDigitalWriteS(multi_io, LED_PIN, LOW);
ioDeviceDigitalWriteS(multi_io, RELAY_PIN, LOW);
delay(2000);
ioDeviceDigitalWriteS(multi_io, LED_PIN, HIGH);
ioDeviceDigitalWriteS(multi_io, RELAY_PIN, HIGH);
delay(2000);
}

I am looking for help with:

  1. any suggestions as to the root cause
    and / or
  2. potential workarounds (eg. is there a way force a reset the ESP32 once in code after a power on cycle)

*** I found the problem.
One of the address pins (A2) on the MCP23017 that drives the relays was floating due to issue with the PCB assembly. When I grounded the pin, the problem disappeared. This explains why it wouldn’t work, however I’m not sure why it consistently worked after a ESP32 reset. In any case the problem is fixed and I’ll leave this post here in case someone else has similar symptoms.

1 Like