As the title says... Chat on...

User avatar
By hydrofoor
#27659 in my project I use GPIO2 as a user button by pulling it up with a 10K resistor and a push button connected to ground to pull down.
It always works fine just after module reset, but stops responding after some time (within a few hours or less; hard to figure out an exact period). But returning the next day the system might respond again, while I'm sure it did not reset. It drives me nuts.
I now have a breadboard setup with an ESP01 and an ESP201 where the GPIO2's are connected to the same button. The ESP201 is flashed with NodeMCU 0.9.5 and the ESP01 with a fairly recent 0.9.6 dev. I reduced the timeline to init.lua below and run it on both modules, looking for the blue TX led flashing on the button push as a result of the print statement.

To my utter amazement both modules respond to the push button or neither. Never only one responding and the other one dead.
It feels like there might be an obvious reason, but so far I did not have any luck in finding any.
Could anyone enlighten me?
Thanks.

code reproducing my issue
Code: Select allfunction debounce (func)
    local last = 0
    local delay = 5000
    return function (...)
    local now = tmr.now()
    if now - last < delay then return end
     last = now
     return func(...)
    end
end

function OnSwitch(level)
   print("->switch event<-")   
end

gpio.mode(4,gpio.INT)
gpio.trig(4, 'up',debounce(OnSwitch))