On Thu, 28 Sep 2017 22:42:50 -0700 (PDT),
jithu...@gmail.com declaimed the
following:
You'll likely have to write code for the PRU since these sensors use a
variable length pulse to indicate the distance (I'm presuming it is similar
to the Parallax PING))) sensor:
https://www.parallax.com/product/28015 ).
That makes it very difficult to get accurate pulse timing using the sysfs
access to the pins (especially as, besides timing the return pulse length,
you need to rapidly switch the pin from output [to send the "start
measurement" pulse] to input [to read/time the return pulse] NOTE:
four-lead versions -- HC-SR04 -- may be easier as the trigger and echo are
on separate pins).
Most of the Parallax documentation is based on BASICStamp's
pulsin/pulsout commands. The rest are Propeller based (which, for this
discussion, could be looked at as an 8-core PRU equivalent)
I did find a site that was using one with a Raspberry-Pi... First step
-- plug in an Arduino board with Grove sockets <G>. Granted, the R-PI
doesn't have quite the GPIO capability of the BBB, but it also has the
overhead of Linux. Even if you memory map the port to bypass the sysfs you
might run into erratic timing as the OS switches from your program to some
other process. The same problem occurs if trying to read various DHT
sensors -- which return a pulse stream of nominally two lengths and one has
to determine if the pulse is longer or shorter than some median to tell 1
from 0 (the ultrasonic sensor is just a single pulse whose length maps to
the distance, the DHT is sending scaled integer temp/humidity)
A second site did use Python directly on the R-Pi.
https://www.modmypi.com/blog/hc-sr04-ultrasonic-range-sensor-on-the-raspberry-pi
This version should be easy to port to the BBB (replace the RPi.GPIO with
Adafruit_BBIO.GPIO, then change the pin names to be BBB format)
Still may not be the most accurate if the Python program gets
pre-empted by the OS near the start or end of the return pulse (ie: it may
miss the exact time of transition)
--
Wulfraed Dennis Lee Bieber AF6VN
wlf...@ix.netcom.com HTTP://wlfraed.home.netcom.com/