Hello, we are using a ydlidar x4 for our final year project. At first when we connected with lidar with arduino nano ( providing external supply of 5v to lidar) the lidar starts spinning giving out 0 readings on both parameters (distance and degree)
Here is the Code we are trying to run:
#include <YDLidar.h> #include "QueueList.h" #define SIZE_OF_SCAN_BUFFER 32
// You need to create an driver instance
YDLidar lidar;
#define MOTOR_ENABLE 7 #define MOTOR_SENABLE 3
void setup() {
// bind the RPLIDAR driver to the arduino hardware serial
Serial.begin(115200);
lidar.begin(Serial);
// set pin modes
pinMode(MOTOR_ENABLE, OUTPUT);
pinMode(MOTOR_SENABLE, OUTPUT);
}
void loop() {
lidar.startScan();
float distance = lidar.getCurrentScanPoint().distance; //distance value in mm unit
float angle = lidar.getCurrentScanPoint().angle; //anglue value in degree
Serial.print("Distance: ");
Serial.print(distance);
Serial.print(" Angle: ");
Serial.println(angle);
// try to detect RPLIDAR...
// detected...
// start motor rotating at max allowed speed
Have you tried running Serial at 128000 baud as used in the example? The ydlidar likely expects that specific baud rate, although I am not able to check if the IDE serial monitor supports that at the moment.
I just looked at the IDE on my computer and 128,000 baud is not an option, so another serial monitor program may be necessary. Cannot find any information on changing the baud rate of the Ydlidar X4, it may be fixed at 128,000.