Hi all,
thank you for your answer. Very helpfull : I can now communicate with the lidar.
I'm now stuck to get the data.
Here is my code:
#include <SPI.h>
#include <Ethernet.h>
EthernetClient lidar2d;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = {192,168,0,5};
byte maclidar[] = { 0x00, 0x06, 0x77, 0x87, 0x48, 0xBC };
byte iplidar[] = { 192, 168, 0, 1 };
byte login[] = {0x02, 0x73, 0x4D, 0x4E, 0x20, 0x53, 0x65, 0x74, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x4D, 0x6F, 0x64, 0x65, 0x20, 0x30, 0x33, 0x20, 0x46, 0x34, 0x37, 0x32, 0x34, 0x37, 0x34, 0x34, 0x03};
char loginchar = "sMN SetAccessMode 03 F4724744";
byte senddatapermanentlystop[] = {0x02, 0x73, 0x45, 0x4E, 0x20, 0x4C, 0x4D, 0x44, 0x73, 0x63, 0x61, 0x6E, 0x64, 0x61, 0x74, 0x61, 0x20, 0x30, 0x03};
byte modelandfirmware[] = {0x02, 0x73, 0x52, 0x49, 0x20, 0x30, 0x03};
byte angularresolutionandvelocity[] = {0x02, 0x73, 0x52, 0x4E, 0x20, 0x4C, 0x4D, 0x50, 0x73, 0x63, 0x61, 0x6E, 0x63, 0x66, 0x67, 0x03};
byte sendconfigurationdata[] = {0x02, 0x73, 0x57, 0x4E, 0x20, 0x4C, 0x4D, 0x44, 0x73, 0x63, 0x61, 0x6E, 0x64, 0x61, 0x74, 0x61, 0x63, 0x66, 0x67, 0x20, 0x30, 0x31, 0x20, 0x31, 0x20, 0x30, 0x20, 0x31, 0x20, 0x30, 0x20, 0x30, 0x31, 0x20, 0x31, 0x20, 0x31, 0x20, 0x31, 0x20, 0x30, 0x20, 0x30, 0x20, 0x2B, 0x31, 0x03};
byte sendconfigurationdataoutput[] = {0x02, 0x73, 0x57, 0x4E, 0x20,
0x4C, 0x4D, 0x50, 0x6F, 0x75, 0x74, 0x70, 0x75, 0x74, 0x52, 0x61, 0x6E, 0x67, 0x65, 0x20,
0x31, 0x20,
0x32, 0x37, 0x31, 0x30, 0x20,
0x2D, 0x31, 0x32, 0x30, 0x30, 0x30, 0x30, 0x30, 0x20,
0x2B, 0x31, 0x32, 0x30, 0x30, 0x30, 0x30, 0x30, 0x03};
byte saveparameter[] = {0x02, 0x73, 0x4D, 0x4E, 0x20, 0x6D, 0x45, 0x45, 0x77, 0x72, 0x69, 0x74, 0x65, 0x61, 0x6C, 0x6C, 0x03};
//byte startmeasurement[] = {0x02, 0x73, 0x4D, 0x4E, 0x20, 0x4C, 0x4D, 0x43, 0x73, 0x74, 0x61, 0x72, 0x74, 0x6D, 0x65, 0x61, 0x73, 0x03};
byte settorun[] = {0x02, 0x73, 0x4D, 0x4E, 0x20, 0x52, 0x75, 0x6E, 0x03};
byte sendpoolonedata[] = {0x02, 0x73, 0x45, 0x4E, 0x20,
0x4C, 0x4D, 0x44, 0x73, 0x63, 0x61, 0x6E, 0x64, 0x61, 0x74, 0x61, 0x20, 0x31, 0x03};
byte onescan[] = {0x02, 0x73, 0x52, 0x4E, 0x20,
0x4C, 0x4D, 0x44, 0x73, 0x63, 0x61, 0x6E, 0x64, 0x61, 0x74, 0x61, 0x03};
void setup()
{
// put your setup code here, to run once:
Ethernet.begin(mac, ip);
Serial.begin(115200);
delay(1000);
Serial.println("Connection ....");
while (!lidar2d.connected())
{
Serial.println("Connecting to the lidar ...");
if (lidar2d.connect(iplidar, 2111))
{
Serial.println("Connected");
}
else
{
Serial.println("Connection failed");
}
delay(1000);
}
if (lidar2d.connected())
{
//LOGIN
lidar2d.write(login, sizeof(login));
Serial.println("Login write done");
delay(100);
char anslogin[21];
int ilogin = 0;
while (lidar2d.available())
{
anslogin[ilogin] = lidar2d.read();
ilogin = ilogin + 1;
anslogin[ilogin] = '\0';
}
Serial.println(anslogin);
if (strstr(anslogin,"sAN SetAccessMode 1") != NULL)
{
Serial.println("login OK");
}
lidar2d.flush();
delay(100);
//STOP
lidar2d.write(senddatapermanentlystop, sizeof(senddatapermanentlystop));
Serial.println("Senddatapermanentlystop write done");
delay(100);
char anssenddatapermanentlystop[30];
int istop = 0;
while (lidar2d.available())
{
anssenddatapermanentlystop[istop] = lidar2d.read();
istop = istop + 1;
anssenddatapermanentlystop[istop] = '\0';
}
Serial.println(anssenddatapermanentlystop);
if (strstr(anssenddatapermanentlystop,"sEA LMDscandata 0") != NULL)
{
Serial.println("stop OK");
}
lidar2d.flush();
delay(100);
// MODEL and FIRMWARE
lidar2d.write(modelandfirmware, sizeof(modelandfirmware));
Serial.println("modelandfirmwarep write done");
delay(100);
char ansmodelandfirmware[30];
int imf = 0;
while (lidar2d.available())
{
ansmodelandfirmware[imf] = lidar2d.read();
imf = imf + 1;
ansmodelandfirmware[imf] = '\0';
}
Serial.println(ansmodelandfirmware);
if (strstr(ansmodelandfirmware,"sRA 0 6 TiM240 8 1.0.3.0R") != NULL)
{
Serial.println("M & F OK");
}
lidar2d.flush();
delay(100);
// ANGULAR RESOLUTION AND VELOCITY
lidar2d.write(angularresolutionandvelocity, sizeof(angularresolutionandvelocity));
Serial.println("angularresolutionandvelocity write done");
delay(100);
char ansangularresolutionandvelocity[30];
int iarv = 0;
while (lidar2d.available())
{
ansangularresolutionandvelocity[iarv] = lidar2d.read();
iarv = iarv + 1;
ansangularresolutionandvelocity[iarv] = '\0';
}
Serial.println(ansangularresolutionandvelocity);
if (strstr(ansangularresolutionandvelocity,"sRA LMPscancfg 5AA 1 2710 FFEDB080 124F80") != NULL)
{
Serial.println("AR & V OK");
}
lidar2d.flush();
delay(100);
// SEND CONFIGURATION DATA
lidar2d.write(sendconfigurationdata, sizeof(sendconfigurationdata));
Serial.println("sendconfigurationdata write done");
delay(100);
char anssendconfigurationdata[30];
int iscd = 0;
while (lidar2d.available())
{
anssendconfigurationdata[iscd] = lidar2d.read();
iscd = iscd + 1;
anssendconfigurationdata[iscd] = '\0';
}
Serial.println(anssendconfigurationdata);
if (strstr(anssendconfigurationdata,"sWA LMDscandatacfg") != NULL)
{
Serial.println("SCD OK");
}
lidar2d.flush();
delay(100);
// SEND CONFIGURATION DATA OUTPUT
lidar2d.write(sendconfigurationdataoutput, sizeof(sendconfigurationdataoutput));
Serial.println("sendconfigurationdataoutput write done");
delay(100);
char anssendconfigurationdataoutput[100];
int iscdo = 0;
while (lidar2d.available())
{
anssendconfigurationdataoutput[iscdo] = lidar2d.read();
iscdo = iscdo + 1;
anssendconfigurationdataoutput[iscdo] = '\0';
//delay(10);
}
Serial.println(anssendconfigurationdataoutput);
if (strstr(anssendconfigurationdataoutput,"sWA LMPoutputRange") != NULL)
{
Serial.println("SCDO OK");
}
lidar2d.flush();
delay(1000);
// SAVE PARAMETER
lidar2d.write(saveparameter, sizeof(saveparameter));
Serial.println("saveparameter write done");
delay(100);
char anssaveparameter[30];
int isp = 0;
while (lidar2d.available())
{
anssaveparameter[isp] = lidar2d.read();
isp = isp + 1;
anssaveparameter[isp] = '\0';
}
Serial.println(anssaveparameter);
if (strstr(anssaveparameter,"sAN mEEwriteall 1") != NULL)
{
Serial.println("Save OK");
}
lidar2d.flush();
delay(100);
//SETTORUN
lidar2d.write(settorun, sizeof(settorun));
Serial.println("settorun write done");
delay(100);
char anssettorun[30];
int istr = 0;
while (lidar2d.available())
{
anssettorun[istr] = lidar2d.read();
istr = istr + 1;
anssettorun[istr] = '\0';
}
Serial.println(anssettorun);
if (strstr(anssettorun,"sAN Run 1") != NULL)
{
Serial.println("Set to run OK");
}
lidar2d.flush();
delay(100);
}
lidar2d.write(onescan,sizeof(onescan));
Serial.println("Send data write done");
delay(100);
int istrspod = 0;
char ansonescan[1000];
if (lidar2d.available())
{
Serial.println("Data available");
while (lidar2d.available())
{
ansonescan[istrspod] = lidar2d.read();
istrspod = istrspod + 1;
ansonescan[istrspod] = '\0';
}
}
else
{
Serial.println("No data");
}
Serial.println("Printed: ");
Serial.println(istrspod);
Serial.println(ansonescan);
if (strstr(ansonescan,"sSN LMDscandata 1 1") != NULL)
{
Serial.println("Data OK");
}
lidar2d.flush();
delay(100);
}
void loop()
{
}
And here the serial monitor:
It is like there are some data available, but the arduino cannot read them: issue of data flow ? sync between the arduino and the lidar ?
Kind regards
Mathieu