GPIO PHP Pulse detection
-
I am trying to detect a 100ms pulse using php. The idea is that I want to count these pulses. Below is the PHP script I am currently using. Unfortunately this leaves the omega 0% idle so this approach probably won't work. My guess the biggest hog is the rapid spanning of the fast-gpio binary. I read some posts about a value file in the sysfs mount but this unfortunately only seems to be filled for gpio8. It would be neat if I could just get an interrupt / event on a pin change. Is there anyone who can give me a nudge in the right direction or should I just invest some time in getting a C compiler for cross compiling up and running?
<?php $shadow=0; $debounce=0; for(;;) { $input=substr(exec("fast-gpio read 0"),-1); if($shadow!=$input) { $debounce=2; $shadow=$input; } if($debounce>0 && $shadow=="1") if(!--$debounce) echo "1"; usleep(45); } ?>
-
Whoops, my bad. I just multiplied the usleep by 1000 so I am actually looking at ms... The omega now has time to come up and breath for air during the polling. It still is somewhat taxing with only 66% idle time remaining, but that's fine for now...
-
@Paul-Koene In your post, you say:
- It would be neat if I could just get an interrupt / event on a pin change. Is there anyone who can give me a nudge in the right direction or should I just invest some time in getting a C compiler for cross compiling up and running?
If it is of any interest to you, I am working on some alternative C/C++ code for access to GPIO as I posted in https://community.onion.io/topic/143/alternative-c-code-for-gpio-access
As part of this work, I will be producing the ability to attach some C/C++ code to hardware interrupts on pin changes. This will be based off code found here https://github.com/OnionIoT/gpio-irq and here https://github.com/OnionIoT/gpio-test
When done, I will be psoting the code.
-
The GPIO pulse counting seems to be working @Kit-Bishop I'll keep an eye out for your project. Would still be neat if I could hook this on hardware interrupts.
-
Hi @Paul-Koene, This is something we are working on. To wrap the irq into the
edge
file for thesysfs
API of GPIO. You can take a look at what's already available here: https://github.com/OnionIoT/gpio-irq. You can already receive a hardware interrupt signal from the kernel, however we just have to wrap that into a better interface to make it accessible via PHP, Pythong, etc.