A
Arduino2mo ago
abim

RPLIDAR C1 Not Detected on Arduino Mega

I am trying to use RPLIDAR C1 directly to Arduino Mega via UART communication (Serial2).
#include <RPLidar.h>
RPLidar lidar;

void setup() {
Serial.begin(115200);
Serial2.begin(460800); // RX2 = 17, TX2 = 16
delay(1000);

Serial.println("Mencoba deteksi RPLIDAR...");
if (lidar.begin(Serial2)) {
Serial.println("RPLIDAR Terdeteksi ✅");
lidar.startScan();
} else {
Serial.println("❌ Gagal mendeteksi RPLIDAR");
}
}

void loop() {
if (IS_OK(lidar.waitPoint())) {
float d = lidar.getCurrentPoint().distance;
float a = lidar.getCurrentPoint().angle;
Serial.printf("Jarak: %.2f mm, Sudut: %.2f°\n", d, a);
}
}
#include <RPLidar.h>
RPLidar lidar;

void setup() {
Serial.begin(115200);
Serial2.begin(460800); // RX2 = 17, TX2 = 16
delay(1000);

Serial.println("Mencoba deteksi RPLIDAR...");
if (lidar.begin(Serial2)) {
Serial.println("RPLIDAR Terdeteksi ✅");
lidar.startScan();
} else {
Serial.println("❌ Gagal mendeteksi RPLIDAR");
}
}

void loop() {
if (IS_OK(lidar.waitPoint())) {
float d = lidar.getCurrentPoint().distance;
float a = lidar.getCurrentPoint().angle;
Serial.printf("Jarak: %.2f mm, Sudut: %.2f°\n", d, a);
}
}
However, every time I upload the program, the following output always appears:
❌ Gagal mendeteksi RPLIDAR
❌ Gagal mendeteksi RPLIDAR
No description
4 Replies
pseud0
pseud02mo ago
And you already tried swapping the TX and RX wires in hardware?
abim
abimOP2mo ago
I have already swapped it
pseud0
pseud02mo ago
I actually don't understand your code. What library version are you using exactly? The lidar.begin() function does not return bool. Looking at https://github.com/DanCrank/rplidar_arduino/blob/master/RPLidarDriver/RPLidar.h.

Did you find this page helpful?