Parallax PING))) ?
I have a small robotics project in mind. In this I need some distance measurements and I thought that the ever used Sharp IR range sensors would do the trick (together with an ADC of course). However I stumbled on the Parallax PING))) ultrasonic range finder which has an impressive 3cm to 3-4meter range for less € than one Sharp IR... tempting of course. The Sharp:s are either like 10-80 cm, 100-200cm etc. etc. The PING))) would do both far and near object ranging at once.
However, there is a catch of course! The PING))) use one pin only for communication (while the Sharp is an anlog piece, so it needs ADC:s etc). The basic logic is as follows (if I have understood it correctly): You drive the pin high for a set period of time (2 - 5us) - this triggers the PING))) to 'schedule' an ultrasonic 'ping' 750us later. The PING))) then drives the signal high when it emits the pulse and drives it low again when it senses an echo. Time lapsed between the high and low events is the time the acoustic signal has travelled (i.e. from the sensor and back again).
My initial thought was "ah well, nice, cheap, but won't work in the regular linux environment" (due to timing inaccuracies in a multitasking environment). Also, my cats would probably appreciate the IR sensors.
But then... according to the Wiki, the RPi GPIO pins are able to work as both inputs and outputs, and are able to trigger interrupts on high/change (amongst others)... my mind started churning on dark thoughts (according to my cats); perhaps it is possible after all!
The logic would then be to do something like this (most likely in a kernel space driver):
- user space program calls for a range probe.
- driver change an GPIO pin to output, drives it high for the required amount of time (2 - 5us).
- driver switch the GPIO pin to input, and sets an interrupt handler on input change.
- when the PING))) drives the input high, the driver notes an appropriate time from the function clock_gettime() using CLOCK_REALTIME or similar (i.e. get a very good start time).
- then the driver sleeps again until the next change (i.e. PING))) drives it low again), it gets the interrupt, notes the time, does the math and returns the range.
What do you guys & gals (I hope) think? This ought to be possible?
More info on the PING))):
Supply voltage +5V
Communication: Positive TTL pulse <- Really I don't know what this means.
Further: "Bidirectional TTL pulse interface on a single I/O pin can communicate with 5 V TTL or 3.3 V CMOS microcontrollers". I think I like the 3.3V parts since the GIPO pins are rated as such.