Issue with sending request to the ethernet client ...

Hi all,

EWven If I'm not completely a beginer with Arduino and coding (much better in Matlab than C/C++), I encountered a stupid issiue I tried to solve for days.\

I got an Arduino Uno, an ethernet shield and a lidar sick (tim family). This lidar is owrkinf perfectly with my Matlab code, but I cannot translate it properly into Arduino >:( .

As the first thing to do with this lidar is to login, lets try to solve my problem with this first request.

The way to send it (according the manual):
https://forum.arduino.cc/index.php?action=dlattach;topic=724112.0;attach=400142
What I'm supposed to get back:
https://forum.arduino.cc/index.php?action=dlattach;topic=724112.0;attach=400144
I tried with both following codes:

  • writting the request as byte,

#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};

void setup()
{
// put your setup code here, to run once:
Ethernet.begin(mac, ip);
Serial.begin(9600);
delay(1000);
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())
{
setthelidar(lidar2d, login);
}
}

void loop()
{
}

void setthelidar(EthernetClient client, byte login)
{
Serial.println("Setting to the lidar ...");
int sizelogin = sizeof(login);
client.write(login,sizelogin);
Serial.println("Login write done");
char anslogin = "";
while (client.available())
{
Serial.println(client.read());
anslogin = sprintf(anslogin,client.read());
}
Serial.println(anslogin);
if (anslogin == 'sAN SetAccessMode 1')
{
Serial.println("login OK");
}
}

  • writting the request as char

#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 };
char* loginchar = 'sMN SetAccessMode 03 F4724744';

void setup()
{
// put your setup code here, to run once:
Ethernet.begin(mac, ip);
Serial.begin(9600);
delay(1000);
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())
{
lidar2d.write(loginchar);
Serial.println("Login write done");
char anslogin = "";
while (lidar2d.available())
{
Serial.println(lidar2d.read());
anslogin = sprintf(anslogin,lidar2d.read());
}
Serial.println(anslogin);
if (anslogin == 'sAN SetAccessMode 1')
{
Serial.println("login OK");
}
}
}

void loop()
{

}

As you can see in ecnlsoed picture, I just got a "?" as an answer:

Since the ethernet client is connected, I guess either the writing of the reading is wrong.

Is there anyone to share tips and advices ?

Kind regards

Requete.png

Reponse.png

Requete.png

Requete.png

Reponse.png

Requete.png

Please edit your post and change the "quote" tags to "code" tags to make the code readable!

This line:

 anslogin = sprintf(anslogin,client.read());

probably doesn't do what you expected although I don't know what you actually expected. I got the impression that you think sprintf adds a character to a C string but it is designed to format a string according to a template string. The way you used it, it reacts unpredictably, at least for some read characters.

As Pylon has indicated, but also this:

char anslogin = "";

Surely that allocates a single character and not a charcter array. I think you need to define a character array as a buffer into which you copy the characters you read using something like:

char anslogin [32];
int position = 0;
while (lidar2d.available())
    {
    anslogin[position] = lidar2d.read());
    position = postion + 1;
    anslogin[position] = '\0';
    Serial.println (anslogin);
}

Above not tested, and of course you don't want two variables anslogin !

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

Some update ... and some progress but ...

The code we are laking about:

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())
      { 
        Serial.print("measure index: ");
        Serial.println(istrspod);
        ansonescan[istrspod] = lidar2d.read();
        istrspod = istrspod + 1;
        ansonescan[istrspod] = '\0';
        lidar2d.flush();
        Serial.print(". Available: ");
        Serial.println(lidar2d.available());
        Serial.println(ansonescan);
        Serial.flush();
      }
    }
  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);

And two screenshots from tne Serial monitor:
At index measure 105, something starts to go wrong ... the data are prtinted instead of "index Measure"
A bit later, even of the data are recorded fist properly, they start to be strange after a while: line ending with 13C and next run, 13C 9?.

Could it be due to: either an issue with serial buffer, amount of data in the variable, or something else ?

I'm glad we re4ch this point, but I do not understand why the data start to behave strangely after a while.
The data acquisition stops before there is no data anymore in the client.

I'm a bit lsot, not sure if it is the issue of hardware, seria monitor nor the code.

Kind regards

  char ansonescan[1000];

The line above requires that you allocate 1000 bytes of ram as a buffer, your Ethernet will require over 512bytes and I would assume the Lidar will require a buffer along with all the rest of your code. Because the allocation above is not global it will not be reflected in the memory figures produced when compiling the sketch. What does the compilation produce for memory figures. The Uno has only 2K of usable ram for variables/buffers etc. I am guessing you are attempting to exceed that and have resulting memory corruption.

Hi all,

Back to this topic> I do encounter a new issue, depiste the fact everything is working ...

With this code (which was working before):

#include <SdFat.h>
#include <sdios.h>
#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 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};

/* Noms des fichiers*/
char FileDataname[10] = "Lidar2.csv";
/*Carte SD*/
const byte SDCARD_CS_PIN = 4;
SdFat sd;
SdFile file;
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 (!sd.begin(SDCARD_CS_PIN, SPI_HALF_SPEED))
      {
        Serial.println("No SD");
      }
  if (!file.open(FileDataname,FILE_WRITE))
      {
        return;
      }
    file.close();
    Serial.println(sd.exists(FileDataname));
    if (sd.exists(FileDataname))
      {
        file.open(FileDataname,FILE_WRITE);   
        file.println("1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20;21;22;23;24;25;26;27;28;29;30;31;32;33;34;35;36;37;38;39;40;41;42;43;44;45;46;47;48;49;50;51;52;53;54;55;56;57;58;59;60;61;62;63;64;65;66;67;68;69;70;71;72;73;74;75;76;77;78;79;80;81;82;83;84;85;86;87;88;89;90;91;92;93;94;95;96;97;98;99;100;101;102;103;104;105;106;107;108;109;110;111;112;113;114;115;116;117;118;199;120;121;122;123;124;125;126;127;128;129;130;131;132;133;134;135;136;137;138;139;140;141;142;143;144;145;146;147;148;149;150;151;152;153;154;155;156;157;158;159;160;161;162;163;164;165;166;167;168;169;170;171;172;173;174;175;176;177;178;179;180;181;182;183;184;185;186;187;188;189;190;191;192;193;194;195;196;197;198;199;200;201;202;203;204;205;206;207;208;209;210;211;212;213;214;215;216;217;218;219;220;221;222;223;224;225;226;227;228;229;230;231;232;233;234;235;236;237;238;239;240;241");
        file.close();
        Serial.println("Colonne OK");
      }    
  

void getLidardata(SdFile file, EthernetClient lidar2d)
{
  
}

void loop()
{
  if (!file.open(FileDataname,  FILE_WRITE  ))
    {
      Serial.println("no file");
      return;
    }
  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();
        Serial.println(ansonescan[istrspod]);
        istrspod = istrspod + 1;
        ansonescan[istrspod] = '\0';
        lidar2d.flush();
      }
    }
  else
    {
      Serial.println("No data");  
    }
  //Serial.println("Printed: ");
  //Serial.println(istrspod);
  Serial.println(ansonescan);
  String Telegramme = String(ansonescan);
  Telegramme.remove(0,(Telegramme.indexOf("DIST1 3F800000 00000000 FFEDB080 2710")+38));
  Serial.println(Telegramme);
  /*Serial.println(strstr(ansonescan,"sSN LMDscandata 1 1 20430033 0 0"));
  if (strstr(ansonescan,"sSN LMDscandata 1 1 20430033 0 0") != NULL)
    {
      Serial.println("Data  OK");
      String Telegramme = String(ansonescan);
      Telegramme.remove(0,Telegramme.indexOf("DIST 1 3F800000 00000000 FFEDB080 2710")+38+1);processdata(ansonescan);
      Serial.println(Telegramme);
    }*/
  for (int index = 1; index < 242; index++)
  {
    //Serial.println(index);
    //Serial.println(Telegramme.indexOf(" "));
    //Serial.println(Telegramme.substring(0,Telegramme.indexOf(" ")));
    String Value = Telegramme.substring(0,Telegramme.indexOf(" "));
    char value[4];
    Value.toCharArray(value,4);
    int number = (int)strtol(value,NULL,16);
    Telegramme.remove(0,Telegramme.indexOf(" ")+1);
    if (index < 241)
    {
      file.print(number);
      file.print(";");
    }
    else
    {
      if (index == 241);
      {
        file.print(number);
        file.println(";");
      }
    }
  }
  lidar2d.flush();
  delay(100);
  file.close();
}

Everything is going smoothly, gettign data fromt he first scan but not the entiore scan (see AnsH and Ans V ppcitures).
I got plenty of question marks.

This is not comming from the sensor: it is working on other cxomputer and via matlab.
I do not guess it is coming from the code: even easier codes are not working.
Could it come from:

  • an issue with ethernet shield?
  • an issue in the settigns ?

Kind regards

In this section of code:

  Serial.println(ansonescan);[color=#222222][/color]
  String Telegramme = String(ansonescan);[color=#222222][/color]
  Telegramme.remove(0,(Telegramme.indexOf("DIST1 3F800000 00000000 FFEDB080 2710")+38));[color=#222222][/color]

If you have no data from the section above, ansonescan has the default data that was already in memory present (which will generally be random characters) so you could be printing out rubbish and also using it for processing.

It seems you repeatedly check that things are valid in an if block but then continue processing in the next section as though everything was correct. Not sure that is causing your problems, but "good news code" if often bad news.

Hi,

Unfortunatley, I don't think it coming from this issue. I add a deeper look into the data, and, for tthe correct beginning parts (I mean distance measurement), they slighlty differ.
So I guess there are data, different from each measurement.

Few strange things:

  • this phenomenon occurs arround 110th value (more or less 10) i.e. the lcoation is not that random,
  • the "bad" part could be either 0 or anotehr value repeated until the end (e.g. 131 or 143).

Could it come from a saturated buffer, some speed differences ?

Kind regards

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.