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

User avatar
By nodeio
#39897 Hi,

Has anyone had issues with GPIO interrupts not firing?

I've used 'both' trig mode to trigger on rising and falling edge:

Code: Select alllocal PIN1 = 4
local PIN2 = 2

function debounce (func)
    local last = 0
    local delay = 200000

    return function (...)
        local now = tmr.now()
        if now - last < delay then return end

        last = now
        return func(...)
    end
end

function onChange ()
    print('Pin1= '.. gpio.read(PIN1) .. ', Pin2= ' .. gpio.read(PIN2))
end

gpio.mode(PIN1, gpio.INT)
gpio.mode(PIN2, gpio.INT)
gpio.trig(PIN1, 'both', debounce(onChange))
gpio.trig(PIN2, 'both', debounce(onChange))


It frequently doesn't trigger when one of the pins toggles.

However if I read the GPIO pin manually later, I can see that the pin state has changed. But no interrupt was generated (or at least didn't make it through the debounce function).

I've had to resort to polling the GPIO every few seconds on a timer in order to capture any changes in GPIO state. Any hints would be appreciated.