How to use the FHL-LD20 LiDAR correctly

Hi! I bought a FHL-LD20 lidar a few months ago. I “get” the raw data with an ESP32 (as shown in the code below) and send it through the serial port to process it in Python. At first, I used Matlab to read the sent data, however I had a problem with the timeout, so I decided to use Python. The error persists, I don’t know if the transmission between LiDAR - ESP is correct or if ESP - PC is failing. I have doubts about how to send the data packet because I don’t know if I’m jamming the serial port with so much data. If someone knows how I should handle the data, I would really appreciate it. Or, how to avoid “empty” readings without changing the timeout (it should be fast enough to capture changes in the environment).

Matlab error:

Are you sending data to your PC via EPS32?

Try this step:
First, process the data received by the ESP32 according to the lidar data frame format into a frame form to confirm that the data you received is normal.

Then, Try sending raw data to a PC frame-by-frame without processing it again?
That way you’ll know which of your positions is timed out or empty.

lidar data frame format

Thank you for your reply :).

The procedure I follow is as follows: Using the ESP32, I first read the raw data from the “Header” and “VarLen” fields to validate the start of a packet according to the datasheet. If the headers indicate that a packet is available, I extract the data and calculate the CRC to ensure the packet has not been corrupted during transmission. If the CRC is correct, I then extract key information from the packet: the start angle (2 bytes), 12 distance measurements (24 bytes), and the end angle (2 bytes), totaling 28 bytes of relevant data. This data is formatted as a hexadecimal string and sent via serial. The string length sent via serial is 28 bytes × 2 hexadecimal characters per byte = 56 characters, plus 1 newline character, making a total of 57 characters sent for each processed packet.

In MATLAB, I used the readline function to read the data, which corresponds to the 57 characters received from the serial port at that moment, and performed the necessary processing. However, I encountered a timeout issue, so I decided to switch to Python. Despite this, the problem still occurs intermittently. Yes, I am able to get measurements. However, I still encounter a timeout issue “n” times.

I don’t know anything about MATLAB’s data handling, so if the timeout is occurring in the readline function, then you might want to look into that function more closely or switch to something else.

Thank you for your reply :).

I’ve solved the timeout issue. However, I have a new question. Each measurement data point consists of a 2-byte distance value and a 1-byte confidence value (intensity strength). What is the minimum acceptable intensity range for a valid measurement? Is it correct to consider that a commonly accepted minimum intensity threshold might be around 10% to 20% of the total range, which would correspond to approximately 25-50 on a scale from 0 to 255?

Not quite sure what you’re getting at.

Is it data noise? It’s up to you to determine how to deal with it.
The easiest way to deal with it is to use the weighted average method.