How can I get data from RP LIDAR sensor with arduino?

Hello
I'm takamitsu.
I would like to ask about above question.
RP LIDAR sensor equip serial comunication(TX RX), So I thought it is possible to receive data using serial receive block.
I conected cable like attatched pdf, and drived arduino with my simulink model.(attatched model)
But, serial reseve block returned 0 state(that mean
unsuccess comunication), and I failed receive data from RP LIDAR.
So could you give me advice?

Answers (3)

Hello,
I have the same project and I can't receive information. I am not an expert with aruino board but I think the USB communication between computer and arduino use TX and RX pin. If you want create 2 serial communication (1 with RPLIDAR and 1 with the computer) you need create a virtual serial port with 2 digital pin (for the RPILARD) and use RX and TX for the computer.
Me I try to connect directly the computer and the RPLIDAR (without arduino). I create communication, but I can't command the RPLIDAR and I can't receive information.
If you succes to create communication, please help me.

7 Comments

Hello,
Thank you for your comment.
Please don't worry about serial port, because I use arduino MEGA(it's equip 4 serial comunication port).
I would like to share progress.
I succes to comunicate with RP LIDAR with arduino by using RP LIDAR driver distributed by robopeak showed bellow link.(but it's use arduino sketch,,,,,).Therefore, sensor is succesfully worked.
https://github.com/robopeak/rplidar_arduino
I can't make comunication using simulink yet,,,
Hello,
Ok for the MEGA board, on the pdf is an UNO board.
I will try with the arduino sketch but this week I have a lot of work... I will comment if I succes something.
good luck
I just look the arduino sketch. The baud rate on the RPLidar.h is 115200 and I think the default value on matlab is 9600, do you change the value on matlab or on the RPLidar.h?
I revised baud rate, and changed it's value to 115200.
I succesed to comunicate with RP LIDAR using arduino and simulink!!
(sireal read block return 1 state value. I didn't change simulink model I had attatched above except for baud rate.)
But value that block emit is weird,,,,,,
RP LIDAR emit [4X1] information as shown attatched PDF p6.
In my model, these value takes 0~ aprox 258 and vibratory.
I guess the problem is regard data type or sampling time.
(Now I use uint8 and 0.01s [block] 0.01s [arduino] )
My progress is now this point.
I have to work from tommorow and I will busy too this week,,,,,
So, see you again next weekend!
I happy for you succes,
can you share your arduino sketch ?
thanks
you will have more information on this pdf.
It explain the protocol of communication
good luck
Hi,
Thank you for your PDF.
I'll cheak.
and about my sketch, it don't different to https://github.com/robopeak/rplidar_arduino .

Sign in to comment.

I don't understand something, if it's the same the "simple_connect.ino", you have in this sketch the serial connection with the rplidar but you don't have the serial connection with the computer. How you can communicate without this serial connection?
Hi
Acutualy, I just added serial.print command like bellow.
Eventually, I gave up comunication with RP LIDAR using arduino and simulink,,,,,,
I decided that use arduino as driver of RP LIDAR, and send sensored value by IDE(sketch) to raspberry pi using serial.write command.
Regard to raspberry pi, I intend that I use simulink( raspberry pi simulink support package ), and in simulink environment, I wanna built SLAM algorithm.
I posted question about my new plan, So if you have time, please help me.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void setup() {
// bind the RPLIDAR driver to the arduino hardware serial
lidar.begin(Serial1);
Serial.begin( 115200 );←use for serial communication with PC
// set pin modes
pinMode(RPLIDAR_MOTOR, OUTPUT);
}
void loop() {
if (IS_OK(lidar.waitPoint())) {
float distance = lidar.getCurrentPoint().distance; //distance value in mm unit
float angle = lidar.getCurrentPoint().angle; //anglue value in degree
bool startBit = lidar.getCurrentPoint().startBit; //whether this point is belong to a new scan
byte quality = lidar.getCurrentPoint().quality; //quality of the current measurement
Serial.println(distance); ← by this command, you can discribe value of distance on your IDE serial monitor.
}
~~~~~~~~~~~~~~~~~~~~~~~~~~

1 Comment

Hello, I am using arduino due with rplidar a2, I have very tough time get the lidar start and read the data. Please see my code below if you could suggest me where I may did wrong. Much appreciated!
#include <RPLidar.h>
RPLidar lidar;
#define RPLIDAR_MOTOR 3
void setup()
{
// bind the RPLIDAR driver to the arduino hardware serial
lidar.begin(Serial2);
Serial2.begin(115200);
Serial.begin(115200);
//Serial1.begin(115200);
// set pin modes
pinMode(RPLIDAR_MOTOR, OUTPUT);
delay(500);
}
void loop()
{
lidar.stop();
if (IS_OK(lidar.waitPoint()))
{
float distance = lidar.getCurrentPoint().distance; //distance value in mm unit
float angle = lidar.getCurrentPoint().angle; //anglue value in degree
bool startBit = lidar.getCurrentPoint().startBit; //whether this point is belong to a new scan
byte quality = lidar.getCurrentPoint().quality; //quality of the current measurement
Serial.print(", distance: ");
Serial.print(distance);
Serial.print(", angle: ");
Serial.print(angle);
Serial.print(", startBit: ");
Serial.print(startBit);
Serial.print(", quality: ");
Serial.println(quality);
}
else
{
analogWrite(RPLIDAR_MOTOR, 0); //stop the rplidar motor
// try to detect RPLIDAR...
rplidar_response_device_info_t info;
if (IS_OK(lidar.getDeviceInfo(info, 100)))
{
// detected...
lidar.startScan();
// start motor rotating at max allowed speed
analogWrite(RPLIDAR_MOTOR, 155);
delay(100);
}
}
}

Sign in to comment.

Commented:

on 30 Oct 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!