Reading HEX data from LIDAR with Arduino UNO

Hi,
I am trying to integrate Delta 2A LIDAR with an Arduino UNO. I know that for a lot of reasons this is not the best idea as Arduino is not powerful enough to handle so much data from a LIDAR but I want to see how far I can go with building such a project and eventually moving to some more powerful board (MKR or Portenta).

Documentation is in Chinese but the translator helped a lot and I figured out how the frame ox HEX data starts (with AA, then there are 4 bits of frame length and some other constant values after that). After connecting the LIDAR to the computer with the UART converter and seeing the data through Serial Port Utility everything is fine, I can see what’s expected based on documentation. So I started connecting that to Arduino. There is only TX, GND, and 5V to connect to Arduino and motor pins that I am powering with the lab bench power supply. I tried simply reading values from software serial and sending them to the normal serial port to see them in the serial monitor without success. Data looks different, I can’t find the beginning of the frame, even sometimes there is AA and after that some kind of repeating pattern of values but not what I am looking for. Here is a code:

#include <SoftwareSerial.h>
SoftwareSerial ss(3,4);    

void setup() {
  ss.begin(230400);
  Serial.begin(250000);
}

void loop() {
      while(!ss.available()){}
        Serial.print(ss.read(), HEX);
        Serial.print(' ');
}

I thought that probably Arduino is not fast enough to handle reading and writing so fast so I tried reading 1000 values, storing those in an array, and after that printing to serial monitor without any success. Here is my code:

uint8_t table[1000];
void setup() {
  Serial.begin(230400);
}

void loop() {
     for(int a = 0; a < 1000; a++){
      while(!Serial.available()){}
      table[a] = Serial.read();
     }
     
      for(int a = 0; a < 1000; a++){
        Serial.print(table[a], HEX);
        Serial.print(' ');
        delay(5);
     }
}

Baud rate of LIDAR: 230400
It transmits data on it’s own, you don’t have to communicate with it (simplex). I spend really a lot of time trying to figure it out and experimenting with different settings. I wanted to give up but I feel like I am so close, probably there is just one stupid thing that I am doing work, and maybe it’s not that hard to get it working.
Any help highly appriciated!
Have a nice day!

What part of your posted code is detecting the beginning of the frame?

Here is how a TFMini parser data receiver detects the beginning of the frame, finds the data, and extracts the data.

void getTFminiData(int* distance, int* strength) {
  static char i = 0;
  char j = 0;
  int checksum = 0; 
  static int rx[9];
  if(SerialTFMini.available())
  {  
    // Serial.println( "tfmini serial available" );
    rx[i] = SerialTFMini.read();
    if(rx[0] != 0x59) {
      i = 0;
    } else if(i == 1 && rx[1] != 0x59) {
      i = 0;
    } else if(i == 8) {
      for(j = 0; j < 8; j++) {
        checksum += rx[j];
      }
      if(rx[8] == (checksum % 256)) {
        *distance = rx[2] + rx[3] * 256;
        *strength = rx[4] + rx[5] * 256;
      }
      i = 0;
    } else 
    {
      i++;
    } 
  }  
}

See how the code is looking through the serial data for a rx[0] != 0x59 and then looks for another rx[1] != 0x59 before it starts storing the data for parsing.

Where in your code are you detecting the starting frame?

Thanks a lot for your reply. I am not even trying to detect the beginning of the frame yet. Just wanted to see the output from the LIDAR going through the Arduino to the serial monitor. Since the data is incorrect there is no point in detecting the beginning of the frame (but I tried doing that just to see what happens with if(Serial.read() == 170) 170 for AA in hex I was printing the next few values from serial but it wasn't looking as it should)

What I find is I don't get the complete story from a book when I just start to read from a random location, you?

Does it make sense to start getting and trying to interpret the data in the order the data is received?

Do you have the spec sheet that 'say' how the data is supposed to look?

You can, also, port one of the python libraries over to c++.

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