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