PINE64
Using GPIO interrupts - Printable Version

+- PINE64 (https://forum.pine64.org)
+-- Forum: ROCKPRO64 (https://forum.pine64.org/forumdisplay.php?fid=98)
+--- Forum: RockPro64 Hardware and Accessories (https://forum.pine64.org/forumdisplay.php?fid=102)
+--- Thread: Using GPIO interrupts (/showthread.php?tid=14326)



Using GPIO interrupts - antonlyap - 06-30-2021

I'm experimenting with GPIO interrupts on my RockPro64. I used the "Watching buttons" example from here: https://www.npmjs.com/package/epoll, but I changed the pin number to 156 (GPIO4_D4, pin 31 on the header).

The hardware is as follows: there's a mechanical switch between the supply (a buck converter with 3V output) and GPIO4_D4 and a 10k pull-down resistor between GPIO4_D4 and ground.

My issue is that when the button is released, the script just constantly spits out "released" (falling edge) events as fast as it can. When I close the switch, I get a couple of rising edge events, then a few falling edge events and then again a few rising edges. Then rising edge events pop up occasionally while the switch is still closed. I also found out that if I connect GPIO4_D4 directly to ground (with the switch open), the falling edge interrupts aren't emitted as frequently.

I'm aware of the fact that mechanical switches have contact bouncing, but is it normal that the events are repeated several times? Has anyone made a working hardware and software setup to detect interrupts with RockPro64? I would appreciate if you share your experiences Smile Thanks!


RE: Using GPIO interrupts with sysfs and epoll - pgwipeout - 06-30-2021

(06-30-2021, 06:39 AM)antonlyap Wrote: I'm experimenting with GPIO interrupts on my RockPro64. I used the "Watching buttons" example from here: https://www.npmjs.com/package/epoll, but I changed the pin number to 156 (GPIO4_D4, pin 31 on the header).

The hardware is as follows: there's a mechanical switch between the supply (a buck converter with 3V output) and GPIO4_D4 and a 10k pull-down resistor between GPIO4_D4 and ground.

My issue is that when the button is released, the script just constantly spits out "released" (falling edge) events as fast as it can. When I close the switch, I get a couple of rising edge events, then a few falling edge events and then again a few rising edges. Then rising edge events pop up occasionally while the switch is still closed. I also found out that if I connect GPIO4_D4 directly to ground (with the switch open), the falling edge interrupts aren't emitted as frequently.

I'm aware of the fact that mechanical switches have contact bouncing, but is it normal that the events are repeated several times? Has anyone made a working hardware and software setup to detect interrupts with RockPro64? I would appreciate if you share your experiences Smile Thanks!

export is depreciated and was actually removed in the newer kernels.
gpiolib is the route you are supposed to take now.

You may want to consider enabling the internal pulldown resistor to see if that helps.


RE: Using GPIO interrupts with sysfs and epoll - antonlyap - 06-30-2021

I installed gpiolib packages (libgpiod2, libgpiod-dev, gpiod - all v1.6.2). Then I used `sudo gpiomon 4 28` and `sudo gpiomon -B pull-down 4 28` and they both give exactly the same output as sysfs. Also when I disconnect my whole button setup and touch the input with my finger, the command spits out RISING and FALLING interrupts no matter whether I enable pull-down or pull-up or disable them.


RE: Using GPIO interrupts - antonlyap - 06-30-2021

I've done some more testing and now the behavior is a bit different:

- The pin doesn't generate constant FALLING interrupts when pulled to ground
- However, when I touch the pin while the switch is open, it still picks up EMI and generates interrupts even though I have the 10k pull-down resistor connected, and I also tried it with the built-in pull-down - same results
- When I toggle the switch, the pin bounces (as expected) but generates several RISING/FALLING interrupts in a row (as before)

So my questions now are:
- Why does the pin pick up signals from my body despite the fact that I have pull-down resistors? How can I prevent this from happening? I'm probably asking at the wrong forum, but has anyone had a situation similar to mine?
- Is it normal that I register several interrupts with the same edge in a row? Common sense suggests that I can only get a FALLING interrupt after a RISING interrupt, but instead I get multiple RISING interrupts one after the other. I might be wrong, please correct me if so
Thanks!