Hello,
I'm new to using LiDAR - for this project, I'm working with a RPLiDAR. I'm using the attached code and the LiDAR spins, however, returns 0 for all values:
Edit: I'm using an Arduino Uno
#include <RPLidar.h>
// Create an instance of the RPLidar class
RPLidar lidar;
// Define the pin for controlling the LIDAR motor
#define RPLIDAR_MOTOR 7
void setup() {
// Initialize Serial communication
Serial.begin(115200);
// Initialize the LIDAR
lidar.begin(Serial);
// Set the LIDAR motor pin as output
pinMode(RPLIDAR_MOTOR, OUTPUT);
// Start the LIDAR motor
analogWrite(RPLIDAR_MOTOR, 255);
delay(1000); // Wait for the motor to reach full speed
// Start the LIDAR scanning
lidar.startScan();
}
void loop() {
if (lidar.waitPoint()) {
// Get the current LIDAR data point
float distance = lidar.getCurrentPoint().distance; // Distance value in mm
float angle = lidar.getCurrentPoint().angle; // Angle value in degrees
bool startBit = lidar.getCurrentPoint().startBit; // Whether this point is the start of a new scan
byte quality = lidar.getCurrentPoint().quality; // Quality of the current measurement
// Print the LIDAR data
Serial.print("Distance: ");
Serial.print(distance);
Serial.print("mm");
Serial.print(" | Angle: ");
Serial.print(angle);
Serial.print("°");
Serial.print(" | Start Bit: ");
Serial.print(startBit);
Serial.print(" | Quality: ");
Serial.println(quality);
}
}
I get the following output:
Distance: 0.00mm | Angle: 0.00° | Start Bit: 0 | Quality: 0
Distance: 0.00mm | Angle: 0.00° | Start Bit: 0 | Quality: 0
Distance: 0.00mm | Angle: 0.00° | Start Bit: 0 | Quality: 0
Thank you!