I have done 2 arduino projects before this. My mainstay is C Matlab, Inventor, FEA, very new to this stuff, I am also a SCADA engineer. literally learning this stuff before i interface the sensors in LABview. I have tried the following code. I think i have most of it right I just need to initiate the read which I am struggling to grasp the concept of. If you could help me out i would be most grateful.
Also I am new to the forums. My code compiles I am just missing something to initiate the reads. Code below.
#include <Wire.h>
int dist;//actual distance measurements of LiDAR
int strength;//signal strength of LiDAR
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 lidarData();
void setup() {
Serial.begin(9600);//set bit rate of serial port connecting Arduino with computer
Serial2.begin(115200);//set bit rate of serial port connecting LiDAR with Arduino
}
void loop(){
if (Serial2.available()>0)//check if serial port has data input also greater than 0
{
if(Serial2.read()==HEADER)//assess data package frame header 0x59
{
uart[0]=HEADER;
if(Serial2.read()==HEADER)//assess data package frame header 0x59
{
uart[1]=HEADER;
for(i=2;i<9;i++)//save data in array
{
uart[i]=Serial2.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
if(dist>=30 && dist<1200)
{
Serial.print(dist);//output measure distance value of LiDAR, z-coordinate
Serial.print("\n");
Serial.flush();
}
}
}
}
}
}//https://www.youtube.com/watch?v=ts81ZTdY_DQ