RPLIDAR wont print onto Serial Monitor but will spin

Hi, im trying to connect an rplidar a1 to an arduino giga and outputting info through the serial2 monitor. Here is my code

// This sketch code is based on the RPLIDAR driver library provided by RoboPeak
#include <RPLidar.h>


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

#define RPLIDAR_MOTOR 5 // 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);
  
  // set pin modes
  pinMode(RPLIDAR_MOTOR, OUTPUT);
  
  // start serial communication
  Serial2.begin(9600);
}

void loop() {
  if (IS_OK(lidar.waitPoint())) {
    float distance = lidar.getCurrentPoint().distance; // distance value in mm unit
    float angle    = lidar.getCurrentPoint().angle;    // angle 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
    
    // Print distance and angle to the serial monitor
    Serial.print("Distance: ");
    Serial.print(distance);
    Serial.print(" mm, Angle: ");
    Serial.print(angle);
    Serial.println(" degrees");
    
  } 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);
    }
  }
}

I keep getting ?P?P but not info. Ive used the correct wiring from this:

If you guys have any suggestions it would be greatly appreciated

I suggest to start with known working code examples for the Lidar unit and make sure that you understand them thoroughly.

Why is Serial is assigned to communications with the Lidar and used to print on the serial monitor? What is Serial2 supposed to do?

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