LIDAR scanner and Arduino board

Hello,

I am working on an RPLIDAR A1M8 and an Arduino Uno and I am trying to get measurements from the RPLIDAR. I have tested the module with its own software and it is working perfectly however, when I connect it to the Arduino Uno, I struggle to get any values and most of the time the Serial Monitor just shows "?P?P" repeatedly.

Has anyone had experience with this module and if so did you have any ideas to solve this?

This is the programming section of the forum, yet we seem to be missing something...

#include <RPLidar.h>

// You need to create an driver instance 
RPLidar lidar;

#define RPLIDAR_MOTOR 3 // The PWM pin for control the speed of RPLIDAR's motor.
                        // This pin should connected with the RPLIDAR's MOTOCTRL signal 
                       
                        
void setup() {
  // bind the RPLIDAR driver to the arduino hardware serial
            
  lidar.begin(Serial);
  Serial.begin(115200);
  
  // 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
    
    //perform data processing here... 
    if(distance>0){
    Serial.print("Angle = ");
    Serial.print(angle);
    Serial.print("  ");
    Serial.print("Distance = ");
    Serial.println(distance);
    }

    else{

   
    
    }
   


  } 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, 255);
       delay(1000);
    }
  }
}

Do these values match?

Does 115200 match the serial monitor speed?
I can't see where you print "?P?P"

Edit: oh. Wait.

Oops

Don't try and control the sensor with the same serial port you're printing the results to.
Isn't that obvious?

Are you sure you posted the correct document?
There's no mention of Arduino that I can see.
Try using a Mega instead.

One UART to handle the LIDAR, one UART to send the results for display.

If I was to buy the MEGA, would I still connect the wires the same way as it shows in the datasheet or would it need to be different? There is only one RX wire and one TX wire so I am unsure as how that would work.

The Mega has four serial interfaces, Serial (which is used to talk to the host, like on a Uno), Serial1, Serial2 and Serial3.
You would use 1, 2 or 3 to talk to the LIDAR.
Check the documentation for "Serial" in the reference, for pin numbers.
You could also use a Micro, which has native USB, plus a UART.

(May I ask which subject you are studying?)

@jp8147 I just googled for general information on using the additional ports.

And googled a bit on the LiDAR.

Do you have anything like this in you setup()?

  Serial2.begin(1152000);
  lidar.begin(Serial2);

Then TX on the LiDAR goes to RX on serial port 2 on the Mega, and so forth.

TX serial2 is 16 on the mega
RX serial2 is 17

But please see those figures for yourself by researching use of additional serial ports on Arduino mega.

HTH

a7

Yay!

Please pots the sketch that works, for the record, and say anything about it you think might help any fellow travellers.

a7

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