stianeikeland / go-rpio

:electric_plug: Raspberry Pi GPIO library for go-lang
MIT License
2.18k stars 221 forks source link

Interrupt/event based edge detection #88

Open wjessop opened 1 year ago

wjessop commented 1 year ago

I'm trying to detect a pulse on a GPIO pin (the tacho from a fan). Right now I have to poll, something like this:

for {
  if rpmPin.EdgeDetected() {
    doTheThint()
  }
}

This busy loop takes 100% of a CPU core. I can add a sleep in there but at 10k pulses per minute the sleep has to be small and the program still uses a lot of CPU. Would it be possible to use some sort of hardware based interrupt notification for edge detection to ease the load on the CPU?

peritonow commented 11 months ago

this information/link might be useful https://www.i-programmer.info/programming/hardware/14114-raspberry-pi-iot-in-c-events-a-interrupts.html?start=1