Example Code for Raspberry Pi-Distance Reading

This guide details the process of using Raspberry Pi and TFmini-i LiDAR for distance reading, including hardware and software setup, wiring diagrams, and running sample code for accurate measurement results.

Hardware Preparation

Software Preparation

  • wiringPi library (installation instructions provided in the steps)

Wiring Diagram

Other Preparation Work

Step 1. 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     //ownload the sample code and save it on the desktop
cd TF02-i/

Step 2. 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?

TOP