Example Code for Raspberry Pi-Distance Measurement
This guide offers a comprehensive tutorial on setting up a Raspberry Pi for distance measurement using TF02-i LiDAR, including hardware preparation, software installation, and code execution.
Hardware Preparation
- TF02-i LiDAR x1
- Raspberry Pi x1
- USB to RS485 Module x1
Software Preparation
Install wiringpi library.
Wiring Diagram

Other Preparation Work
Install wiringpi library:
cd /tmp
wget https://project-downloads.drogon.net/wiringpi-latest.deb //download wiringpi library
sudo dpkg -i wiringpi-latest.deb //install wiringpi library
cd Desktop/ //enter desktop folder
git clone https://github.com/DFRobotdl/TF02-i.git //download the sample code and save it on the desktop
cd TF02-i/
Check USB device:
Type in the terminal
sudo ls -l /dev
Find the USB device that has just been connected to the Raspberry Pi (Every time the USB device is connected to the Raspberry Pi, the device port will change, so you need to check the actual port each time you connect the device to the Raspberry Pi).

Sample Code
Compile and run the sample code:
gcc -Wall -lwiringPi -o TF02 TF02.c
sudo ./TF02
Result
Finally, you can see the accurate measured distance value.

Was this article helpful?
