Hi everyone,
I am having trouble getting consistent performance from my RPLIDAR A1M8 sensor with my Arduino Uno R4 WiFi. The sensor only works intermittently, typically providing a reading once every 20 seconds, and often these readings are incorrect. Occasionally, it performs perfectly, but this is rare and unpredictable.
Here are the details of my setup:
- Microcontroller: Arduino Uno R4 WiFi
- Sensor: RPLIDAR A1M8
Symptoms:
- The LIDAR gives a valid reading approximately once every 20 seconds.
- The readings are often false or equal to distances I gave to my variables.
- Occasionally, the sensor works perfectly for a short period before reverting to the issues above.
Things I've tried:
- Ensuring all connections are secure.
- Using different power supplies.
- Checking and re-uploading the code.
- Testing the LIDAR sensor with an adapter and robotstudio (slantec) and it works perfectly
#include <RPLidar.h>
#define RPLIDAR_MOTOR 3 // The PWM pin for control the speed of RPLIDAR's motor (MOTOCTRL).
RPLidar lidar;
void setup() {
Serial.begin(115200);
Serial1.begin(115200); // For RPLidar
lidar.begin(Serial1);
pinMode(RPLIDAR_MOTOR, OUTPUT); // set pin modes
}
float minDistance = 100000;
float angleAtMinDist = 0;
void loop() {
if (IS_OK(lidar.waitPoint())) {
//perform data processing here...
float distance = lidar.getCurrentPoint().distance;
float angle = lidar.getCurrentPoint().angle; // 0-360 deg
if (lidar.getCurrentPoint().startBit) {
// a new scan, display the previous data...
printData(angleAtMinDist, minDistance);
minDistance = 100000;
angleAtMinDist = 0;
} else {
if ( distance > 0 && distance < minDistance) {
minDistance = distance;
angleAtMinDist = angle;
}
}
}
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();
analogWrite(RPLIDAR_MOTOR, 255);
delay(1000);
}
}
}
void printData(float angle, float distance)
{
Serial.print("dist: ");
Serial.print(distance);
Serial.print(" angle: ");
Serial.println(angle);
}