I am using a BeagleBone Black to trigger an ultrasonic sensor and expecting the Echo pin-connected GPIO to be sensed as HIGH by my program, but it almost crashes the system.
while(1)
{
// Reset
system("echo 0 > /sys/class/gpio/gpio44/value");printf(ret);
// Trigger
system("echo 1 > /sys/class/gpio/gpio44/value");
usleep(10); // 10us
system("echo 0 > /sys/class/gpio/gpio44/value");
// read value
result = read(pollfds[0].fd, readBuf, MAX_BUFFER_SIZE);
if (result > 0){
// read data ... do something
}
else{
// do something else
}
usleep(1000*10); // sleep for 5ms
}
}
On running it, the CPU usage spikes all the way from 3% to 72% and above. I noticed that significantly increasing the delay (usleep()) solves the problem but I can't afford delay more than a few ms.
Am I doing something wrong or is this a limitation of the device?