Device is responsive, but periodically pin(s) are not responsive

Hello, we’ve got an imp004m ( impOS 40.7 ) that is being used to control a 2 channel 5v relay ( with an external power source ). Periodically, we’ve noticed that the two pins appear to stop working. Unfortunately, the device is not directly accessible by me which makes troubleshooting a bit difficult.

What we’ve seen is that the imp will work fine for most of the day, but at some point the output pins appear to stop working. The device will receive the message from the agent, log that it got the message with server.log(), set two pins LOW, sleep and log again when it wakes. At no point does the device disconnect or appear to be unresponsive, but the pins seem to not get set to a low state.

We’ve found that most of the time the device will self recover after a few hours or if someone physically disconnects/reconnects power that resolves the issue. During troubleshooting we have also tried restarts via the cloud console, and that doesn’t appear to resolve the issue either.

The code running on the device is very simple. It configures the pins, and listens for a message from the agent and triggers the relays.

relay_pin_1 <- hardware.pinM
relay_pin_1.configure(DIGITAL_OUT, 1)
relay_pin_2 <- hardware.pinN
relay_pin_2.configure(DIGITAL_OUT, 1);

function latch(msg) {
relay_pin_1.write(0);
relay_pin_2.write(0);
imp.sleep(8);
relay_pin_1.write(1);
relay_pin_2.write(1);
}

function handleLatchMsg(msg) {
// simplified
latch();
}

agent.on(“latch”, handleLatchMsg);

I’m not sure what “easy” answers exists, but I’m hoping to get some pointers as to where to look next. At this time we think that it’s a code issue or maybe an issue with the imp. We’ve ruled out shoddy pin header solders, and issues with the relay / associated wiring.

Thanks in advance for any ideas!

Your example code indicates that the relay pins are driven low for 8 seconds when a message comes from the server. If the relay isn’t opening then this sounds like an electrical issue with the relay driver circuitry, though the only way to confirm that is to actually check the pin levels with a meter when it’s not doing the right thing. Can you link to the exact relay board you’re using?

Also, can you say what you mean by “sleep”? Entering deep sleep will cause all pins to be tristated. Idling, though, ie your code just having nothing to do, will preserve I/O states.

Does that 2 channel 5V relay board allow, or accept a 3V signal? Typically there would be some transistors involved to protect the imp pins from the 5V relay coils. Also don’t rule out the possibility that the imp is driving the relay correctly but the actual relay contacts themselves are dirty or poorly conducting. This of course depends on the load (current, voltage) across those relay contacts. Pitting from arcing for example would cause failure on the relay side, not the imp side. A schematic would be nice to see.