HoverSky I have not forgotten that I asked for code. Note: I can not use this code directly as the equivalent device I have is a Ping which only has one IO pin. But can use it to help to debug.
I ran into the code that I extracted yesterday after you posted and ran into an issue, with the main loop, where it could actually miss the pulses. But just now thought I would point out what I found, and extracted the code, and used Arduino IDE to reformat the text and then used the c++ formatter (>> on the advanced edit). It looks like the code has changed?
Some of the issues may be with the actual code here. For example:
for (;;) { time_s = 0; time_e = 0; mraa_gpio_write(gpio_out, HIGH); usleep(STARTDELAY); mraa_gpio_write(gpio_out, LOW); for (;;) { if (mraa_gpio_read(gpio_in) == HIGH) { time_s = micros2(); break; } } for (;;) { if (mraa_gpio_read(gpio_in) == LOW) { time_e = micros2(); echotime = time_e - time_s; break; } } }
In the main function,
Am I right that the code has been updated? If so did the edits fix the issue?
Note: In my own version, I was going to do something similar, except I was probably going to add some form of timeout, so if I miss the pulse it does not hang. Also I was probably going to add yield calls to the loop as to not totally consume the processor...