Hello, I am using a 3 TF mini Plus to count people traffic, actually I am using many Arduino Uno and Nano to make the tests, the problem is that I got error measurements between 1,24m and 1,8m, it goes to 0 and start reading again and when pass 180, continues measuring normal, here is the code used, also I am attaching an image from the serial plotter, I contact the manufacturer and told me that as arduino are cheap uC it can get this error, when using the arduino as USB-TTL reader with the reading software from the manufacturer it doesn't happen this error, this happen with all 3 sensors, so it must be and arduino issue.
Has anyone had this error? any ideas why this could be happening?
#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
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() {
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
dist1= uart[2];
dist2= uart[3];
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.println(dist); //output measure distance value of LiDAR
// Serial.print(" strength = ");
//
// Serial.print(strength); //output signal strength value
//
}
}
}
}
}
Thank for your help
