python gpio events?
-
Hello,
I have written a small program to read GPIO status on my light switches, and this in turn activates relays to activate the lights.
The reason is I want to automatically activate the light at certain times.
Now the problem is that the way I have written it, a python program loops constantly and reads the GPIO status. It would be preferable to wait for an interrupt or an event or something like this.
How can I go about doing this?
Thanks for the help guys!
-
@Samuel-Mathieson While I know little about Python, I do know a fair bit about accessing GPIO and interrupt handling.
If you are accessing the GPIO pins by running the Omega supplied fast-gpio program, you may be interested in my new-gpio program (see reference below). This does everything fast-gpio does and can additionally run any shell command by catching interrupts on GPIO pin changes.
Alternatively, if you know how to call C/C++ code from Python, my C/C++ library libnew-gpio may be of use to you - as well as general GPIO access it provides methods for handling interrupts on GPIO pins.
(FYI: I have also written code that provides Java wrappers to libnew-gpio including interrupt handling from within Java - I will be posting this as soon as I have it tidied up and documented).If you are interested in new-gpio and libnew-gpio, all sources, binary files and documentation can be found on GitHub at: https://github.com/KitBishop/new-gpio
-
Also, I have a doubt. It might be obvious but...
Once a gpio is set to input then it carries across reboots?
If I have 2.7V connected to the GPIO, and then the Onion reboots it should be no problem, is that correct?
-
Kit,
Thanks, I will have a look at that!
-
@Samuel-Mathieson In relation to your last question:
So long as the GPIO pin remains connected, the input state will remain over a reboot - the signal on the input pin is external to the Omega. However, there is no guarantee that the pin direction will remain as an input pin over a reboot - this is internal to the Omega - you should always ensure that the direction is set to input after a reboot.
-
Ok, so from what I understand, there will be no damage across a reboot to the Onion. We should set the GPIO state, but don't need to worry if the GPIO is connected to the 2.7.
Thanks.
-
Correct