I have a nodemcu wired to a bank of five optocoupled 5V relays that are active low. My problem is that during the boot sequence GPIO16 goes low and momentarily activates one of the relays.
I'm guessing that GPIO16's default upon bootup is as an output and is low, Very early in my code I set GPIO16 to an output and to high, but nonetheless the relay has time to momentarily activate.
I think that GPIO15 also exhibits this problem, but I'm not sure about the others. Most other GPIO pins are already wired and changing that wiring would be a little inconvenient, but doable.
Is there any simple software solution to this problem?
Alternatively is there a simple hardware solution? I'm thinking that an RC circuit with a TC of maybe 250ms might work although this would be a little awkward to apply to all five relays if that turns out to be necessary. Maybe the power to the relay bank could be delayed but the 200-300 ma current makes a simple RC circuit impractical without an associated transistor switch circuit. Again, doable but inconvenient.
frank2644:
I have a nodemcu wired to a bank of five optocoupled 5V relays that are active low. My problem is that during the boot sequence GPIO16 goes low and momentarily activates one of the relays.
Have you tried:
Test that with a very simple program that does noting at all apart from blink an LED or something. Don't configure those outputs at all.
That will confirm if the outputs are driven low and maybe stay low during boot.
Then try setting the pins output/high as the very first thing.
If they still go 'click', you will have to do something in hardware.
You say they are 'optocoupled'... do you have opto-isolators, transistors, relays or are you using some 'optocoupled relay' board ?
If so, what type are they ?
I tried loading the blink sketch as suggested and the same problem still exists. That is, during bootup GPIO16 sinks current and then goes high.
I also noticed that GPIO15 has a similar problem and perhaps even worse as it sinks current even after the bootup finishes. It seems to constantly sink current until the program sets it high. And with the blink sketch that never happens so GPIO15 is constantly sinking current, of course assuming it is attached to a source.
I didn't explicitly check any other GPIO's but i have some of them also connected to relays and did not see those relays activate.
BTW, it is Chinese optocoupled relay board and I don't have much information about it. I did confirm that the problem is not related to the relay board by substituting an ohmmeter.
It looks like the solution is to bite the bullet and rewire to avoid using GPIO15 & 16.
frank2644:
BTW, it is Chinese optocoupled relay board and I don't have much information about it. I did confirm that the problem is not related to the relay board by substituting an ohmmeter.
If it is one of those opto-relay boards where you can separate the +5V for the optos and the supply to the relays - you could use a PNP transistor to switch the opto 5V, if it's only 2 optos you might get away with just driving a pin high.
Of course, to drive a transistor you'd need a pin that doesn't get pulled low during boot
TonyWilk:
If it is one of those opto-relay boards where you can separate the +5V for the optos and the supply to the relays - you could use a PNP transistor to switch the opto 5V, if it's only 2 optos you might get away with just driving a pin high.
Of course, to drive a transistor you'd need a pin that doesn't get pulled low during boot
Yours,
TonyWilk
Thanks for a really good idea. I was especially optimistic that it might work because GPIO15 didn't seem to sink very strongly because the assassinated opto LED wasn't very bright.
I tried what I believe to be a fairly aggressive pullup resistor(1.2k), but unfortunately it didn't work for either of the GPIO pins.
TonyWilk:
If it is one of those opto-relay boards where you can separate the +5V for the optos and the supply to the relays - you could use a PNP transistor to switch the opto 5V, if it's only 2 optos you might get away with just driving a pin high.
Of course, to drive a transistor you'd need a pin that doesn't get pulled low during boot
Yours,
TonyWilk
After dropping this project for a couple of months I'm looking at it again. Re-reading this thread I noticed that my response to you didn't really apply to your last message. Sorry about that, I don't know that I was thinking.
Anyway, taking your suggestion to separate the +5V supply for the optos, I then used another nodemcu output to drive the optos directly as you suggested. Surprisingly the optos required only 1 or 2 ma per activated relay. No problem since to nodemcu can supply 12 ma. Also the nodemcu only supplies 3.3v, but the optos seem to work just fine at that lower voltage.