Simple PHP GPIOHelper library with sample



  • Using some methods found in a Python library and playing with an actual Omega, I've put together a PHP library that accesses the pins on the Omega via fopen rather than running shell commands. It seems to work pretty reliably, and doesn't have to dump out to shell.

    I put the whole project and instructions on Github here: https://github.com/ringmaster/GPIOHelperPHP

    It produces an interface in a browser that looks like this:
    upload-79eb7dcc-512b-4d6f-a036-24f1b8c9804f

    The Direction column lets you toggle the direction of the pin, and you can set 0/1 or toggle any pin. The current status of a pin is listed in the Status column.

    I'm looking for a reference that describes analog states for any pins, or what values can be fed to these filesystem objects so that more functionality can be exposed via this library. Any help there is appreciated.

    Pull requests welcome.



  • @Owen-Winkler Well, one of the things we are planning to work on is to get the edge interface to work. Edge interface basically is a file in the /sys/class/gpio/gpioX directory called edge that allows you to notify your software if the GPIO is changed (perhaps when a button is pushed).



  • @Boken-Lin How does this differ from setting a pin direction to "in" and reading it periodically? I don't know of a clean way, in PHP at least, to attach event handlers to filesystem changes without polling.

    I made another simple project using this library that lets me detect a button press and toggle an LED, but it proves out that inputs can work, too.

    I was thinking of maybe incorporating an event loop in the GPIOHelper class that would debounce and fire event handlers. Code that uses it would look something like:

    upload-1f94d54b-c621-4bce-a732-0b7ba3b5a12e

    How could the edge interface be used to improve this?



  • @Owen-Winkler There aren't any difference in the way it works. It's just that with the edge interface the kernel is monitoring the changes for you so the abstraction is a bit cleaner. I think it also tends to be a bit faster because the kernel is monitoring the lower-level registers rather than the files themselves.



  • @Boken-Lin @Owen-Winkler I am working on C/C++ code that could be used at the lower-level to intercept pin interrupts that may be useful here. See recent comments on https://community.onion.io/topic/125/using-netbeans-to-compile-c-c-code-for-omega/6


Log in to reply
 

Looks like your connection to Onion Community was lost, please wait while we try to reconnect.