0% found this document useful (0 votes)
293 views6 pages

Develop Routine of TF-Luna in Arduino: Step 1: Hardware Connection

This document provides instructions for setting up a routine to interface TF-Luna LiDAR with an Arduino board. It involves: 1. Connecting the TF-Luna to an Arduino Uno or Due board via serial ports. 2. Uploading code to the Arduino that reads data from the LiDAR's serial port and outputs distance, strength, and temperature readings to the serial monitor or plotting software. 3. Viewing the real-time LiDAR measurements in the serial monitor or as data curves in plotting software.

Uploaded by

Sumitra T
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
293 views6 pages

Develop Routine of TF-Luna in Arduino: Step 1: Hardware Connection

This document provides instructions for setting up a routine to interface TF-Luna LiDAR with an Arduino board. It involves: 1. Connecting the TF-Luna to an Arduino Uno or Due board via serial ports. 2. Uploading code to the Arduino that reads data from the LiDAR's serial port and outputs distance, strength, and temperature readings to the serial monitor or plotting software. 3. Viewing the real-time LiDAR measurements in the serial monitor or as data curves in plotting software.

Uploaded by

Sumitra T
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Develop Routine of TF-Luna in Arduino

In this routine, Arduino Uno and DUE board is taken as example, which is mainly for the user to quickly
familiarize himself with our LiDAR and thus save the time of product development.

For detailed introduction and tutorial of Aruidno, please refer to following website:
Arduino Official website: www.arduino.cc

Step 1: Hardware Connection

Figure 1 Schematic Diagram of Connection between TF-Luna and UNO Board

Figure 2 Schematic Diagram of Connection between TF-Luna and DUE Board

Page 1
Step 2: Program Compilation

At least two serial ports of Arduino are required for the achievement of this routine function with one for

receiving data of LiDAR and another for outputting data to PC for display. The user may either copy

following code and paste it in Arduino IDE program editing window or directly open relevant enclosed file.

/*

This program is the interpretation routine of standard output protocol of TFmini-Plus product on Arduino.

For details, refer to Product Specifications.

For Arduino boards with only one serial port like UNO board, the function of software visual serial port is

to be used.

*/

#include <SoftwareSerial.h> //header file of software serial port

SoftwareSerial Serial1(2,3); //define software serial port name as Serial1 and define pin2 as RX and pin3

as TX

/* For Arduinoboards with multiple serial ports like DUEboard, interpret above two pieces of code and

directly use Serial1 serial port*/

int dist; //actual distance measurements of LiDAR

int strength; //signal strength of LiDAR

float temprature;

int check; //save check value

int i;

int uart[9]; //save data measured by LiDAR

const int HEADER=0x59; //frame header of data package

void setup() {

Page 2
Serial.begin(9600); //set bit rate of serial port connecting Arduino with computer

Serial1.begin(115200); //set bit rate of serial port connecting LiDAR with Arduino

void loop() {

if (Serial1.available()) { //check if serial port has data input

if(Serial1.read() == HEADER) { //assess data package frame header 0x59

uart[0]=HEADER;

if (Serial1.read() == HEADER) { //assess data package frame header 0x59

uart[1] = HEADER;

for (i = 2; i < 9; i++) { //save data in array

uart[i] = Serial1.read();

check = uart[0] + uart[1] + uart[2] + uart[3] + uart[4] + uart[5] + uart[6] + uart[7];

if (uart[8] == (check & 0xff)){ //verify the received data as per protocol

dist = uart[2] + uart[3] * 256; //calculate distance value

strength = uart[4] + uart[5] * 256; //calculate signal strength value

temprature = uart[6] + uart[7] *256;//calculate chip temprature

temprature = temprature/8 - 256;

Serial.print("dist = ");

Serial.print(dist); //output measure distance value of LiDAR

Serial.print('\t');

Page 3
Serial.print("strength = ");

Serial.print(strength); //output signal strength value

Serial.print("\t Chip Temprature = ");

Serial.print(temprature);

Serial.println(" celcius degree"); //output chip temperature of Lidar

Step 3: Viewing of Data

Download the code into Arduino board and open the serial monitor for the serial port. Then real-time

distance values as well as the corresponding strength and chip temperature can be viewed, as shown in

figure 3.

Page 4
Figure 3 Lidar data displayed on the monitor software by serial port

In addition, data curve can be viewed in the curve plotter for serial port, however, the above coding regarding
the print of serial port should be modified:

//Serial.print("dist = ");
Serial.print(dist); //output measure distance value of LiDAR
Serial.print(" ");
//Serial.print("strength = ");
Serial.print(strength); //output signal strength value
//Serial.print("\t Chip Temprature = ");
Serial.print(" ");
Serial.print(temprature);
Serial.println();
//Serial.println(" celcius degree");

Re-compile and download to Arduino board and open the curve plotter. Then two curves including the dist and
strength can be viewed, as shown in Figure 4.

Page 5
Figure 4 Plots of TF-Luna data on Curve plotter for Serial Port

Page 6

You might also like