Ultrasonic Distance Sensors, like the HC-SR04, are an inexpensive way to measure distance from the Jetson TK1. Looky here:
Echo location is used by echolocating animals, such as bats and dolphins, for navigation and object detection. Echolocating animals emit calls out to the environment and listen to the echoes of those calls that return from objects around them. They use the echoes to locate and identify the objects.
A version of this idea has been implemented in the HC-SR04 sensor. When triggered, the HC-SR04 sends out 8 40KHz ultrasonic audio pulses and waits for the echo return. The sensor reads the echo return with the length of the wait determining how far away a detected object is located. This sensor is inexpensive as far as distance sensors go, only costing a few dollars.
There are many versions of the HC-SR02 for sale by a large variety of vendors. In the video, a SunFounder 2 pcs Ultrasonic Module HC-SR04 Distance Sensor was used. There are two sensors in the package, and while only one is needed for demonstration, it is nice to have an extra one lying about.
An Adafruit 4-channel I2C-safe Bi-directional Logic Level Converter:
In the video, a Solderless BreadBoard, 400 tie-points, 4 power rails was used, along with some regular breadboard jumpers, along with Hook up Wire – 22 Gauge.
There are a couple of tools that are useful for this project:
1) A soldering iron, for the video a Hakko FX888D-23BY Digital Soldering Station was used.
2) Wire strippers, for the video a Hakko CHP CSP-30-1 Wire Stripper, 30-20 Gauge Maximum Cutting Capacity was used.
The HC-SR04 operates with 5 volts. This includes the signals as well as the power supply. The Jetson TK1 GPIO signals are 1.8V, which means that a level converter (or voltage divider) must be used to make the signals compatible. For this demonstration, a level converter is used.
5V from Jetson J3A1 pin 1 to 1 (+) 5 volt side power rail
5V to Level Converter HV
5V to HC-SR04 Vcc
1.8V from Jetson J3A1 pin 19 to 1 (+) 1.8 volt side
1.8V to Level Converter LV
On the prototype board, grounds go to the Level Converter HV side GND, Level Converter LV side GND as well as to the GND of the HC-SR04. You can tie the GND rails together on the prototyping board for easier wiring. In the video, the GND rails are tied together at row 30 on the prototype board.
gpio165 from Jetson J3A2 pin 55 (trigger) to Level Shifter A2 (1.8V)
gpio166 from Jetson J3A2 pin 58 (echo) to Level Shifter A1 (1.8V)
Level Shifter B1 (5V) to HC-SR04 ECHO
Level Shifter B2 (5V) to HC-SR04 Trig
A simple library with examples to interface with the HC-SR04 is located on the JetsonHacks Github repository.
To install the library and examples:
$ git clone https://github.com/jetsonhacks/JHHC-SR04.git
To run the simple example:
$ cd JHHC-SR04/example
$ sudo ./simpleHCSR04
Note: The ‘sudo’ command is required to access the GPIO signals from user space under L4T.
The plotExample requires installation and configuration of Qt Creator. For help on installation, looky here. PlotPractice is the name of the project. Build the project, locate the executable, and run it using sudo for permissions, i.e.:
$ sudo ./PlotPractice
Note: The plotExample uses QCustomPlot, a Qt C++ widget for plotting data visualization. Note that QCustomPlot is distributed as GPL licensed.
Note: The demonstration was run on L4T 21.4.
The software that reads the HC-SR04 works, but is probably not as accurate as needed for a serious project. A SoC like the Jetson TK1 running Ubuntu (L4T) is not usually purposed towards real-time control of a bare sensor. Better strategies for dealing with raw sensors like the HC-SR04 usually involve having a micro-controller in the mix to handle the care and feeding of the sensor. Also, the library does not take into account the actual speed of sound dependent on atmospheric temperature and pressure. However, this does not take away any of the fun of connecting the sensor and playing with it on the Jetson!
So there you have it. For a few bucks you can start exploring non-contact distance ranging.