Automation Hat - Input - Interrupt driven?


#1

I’ve just started to play around with the Automation HAT and Python (newbie, but have coded in various things previously).

Is there any way to have the inputs interrupt driven to run some specific code, or do I have to sit in a loop and continually poll and check for changes in values?

The scenario I’m looking for is to have a rain sensor trigger one of the inputs that would then fire off an email (and do some other stuff) when rain is detected, and also when the rain clears, etc.

Is this possible at all?


#2

This is possible in Python with RPi.GPIO, which supports interrupts (they’re actually polling under the hood IIRC) and also in C with WiringPi with WiringPiISR which sets up a sleeping worker threat that asks the kernel to wake it up on a pin state change (closer to a real interrupt).

This series by Alex of Raspi.tv covers the RPi.GPIO stuff well: http://raspi.tv/2013/how-to-use-interrupts-with-python-on-the-raspberry-pi-and-rpi-gpio