go-rpio
go-rpio copied to clipboard
Interrupt/event based edge detection
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?
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