0

I need to detect an falling edge on a gpio pin and have my code wait until it does that. I also need a way to stop the code from waiting for the falling edge and end the program. If anyone knows of any solutions or libraries I could use?? I'm coding in C.

I have a Raspberry Pi 4 2GB Ram.

  • There is some special-purpose code in the kernel for detecting edges (on both GPIO pins and serial port modem control lines) specifically for the purpose of synchronizing the clock to PPS pulses. I'm not sure whether that code would be any use to you, though. – Steve Summit Jul 15 '19 at 15:38
  • Generically, what you're looking for is one of two concepts: polling and interrupts. Polling is simpler from a conceptual standpoint; you just keep checking the inputs in a loop, along with doing everything else you need to do (this is old-style "main loop" programming, where everything a program does is driven by a single main loop). Interrupts provide better responsiveness and, once you understand them and how to set them up, result in a simpler overall program. But not all GPIO can be configured as interrupts; you'd have to research in your hardware documentation. – phonetagger Jul 15 '19 at 16:22
  • 1
    libgpiod https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree/include/gpiod.h#n813 https://linuxpiter.com/system/attachments/files/000/001/532/original/Linux_Piter_2018_-_New_GPIO_interface_for_linux_userspace.pdf?1541021776 https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree/README – KamilCuk Jul 15 '19 at 16:31
  • Since you are using wiringPi (a library written to access GPIO) you literally just have to detect the transition on the GPIO pins. If the are digital then detect the logic flip. If it's analog find the peak voltage and check if its going downhill. – Bayleef Jul 15 '19 at 17:34
  • I put in an interrupt and have it running in a separate Pthread, is there any way to trigger the interrupt without pressing the button so I can stop it from waiting if need be? – Connor Siem Jul 18 '19 at 14:32

0 Answers0