Hi everyone, I've been struggling for some days in a project I'm doing. Bascially I'm trying to do a MicroMouse robot with a Teensy 3.6 and a RPLidar a1m8 from Slamtec.
I can move the Lidar motor but I'm not able to recieve the data of the angle and the distance.
I've connected Rx Lidar to Tx Teensy 3.6, and Tx Lidar to Rx Teensy 3.6 with a downgrade of voltage to 3.3V (I've been wondering if this might be the problem). I've checked the connections thousands of times and I believe everything's OK. They share common GND, I supply the Teensy with 3.3V and the Lidar with 5V.
I can move the Lidar motor but I'm not able to recieve the data of the angle and the distance.
I've connected Rx Lidar to Tx Teensy 3.6, and Tx Lidar to Rx Teensy 3.6 with a downgrade of voltage to 3.3V (I've been wondering if this might be the problem). I've checked the connections thousands of times and I believe everything's OK. They share common GND, I supply the Teensy with 3.3V and the Lidar with 5V.
Code:
//------------------------------------------------------------------------------------------
// Teensy 3.2
// Read data from Robo Peak 360 Degree Scanning Lidar
// Outputs A###R#####\n A = angle 0-359 R = range in mm
// Serial1 incoming data from RP Lidar
//------------------------------------------------------------------------------------------
#include <RPLidar.h>
RPLidar lidar;
#define RPLIDAR_MOTOR_PIN 5
//------------------------------------------------------------------------------------------
// Setup
//------------------------------------------------------------------------------------------
void setup()
{
Serial.begin (115200);
//while(!Serial);
delay(3000);
Serial1.begin(115200);
lidar.begin(Serial1);
delay(2000);
pinMode(RPLIDAR_MOTOR_PIN, OUTPUT);
}
float distance; //distance value in mm unit
float angle; //angle value in degree
bool startBit; //whether this point is belong to a new scan
byte quality; //quality of the current measurement
//------------------------------------------------------------------------------------------
// Main Loop
//------------------------------------------------------------------------------------------
void loop()
{
if ( IS_OK(lidar.waitPoint()) )
{
distance = lidar.getCurrentPoint().distance; //distance value in mm unit
angle = lidar.getCurrentPoint().angle; //angle value in degree
startBit = lidar.getCurrentPoint().startBit; //whether this point is belong to a new scan
quality = lidar.getCurrentPoint().quality; //quality of the current measurement
if (lidar.getCurrentPoint().startBit)
{
Serial.print ("A");Serial.print (distance);
Serial.print ("R"); Serial.print (angle);
Serial.print ('\n');
}
}
else
{
analogWrite(RPLIDAR_MOTOR_PIN, 0); // Stop motor
rplidar_response_device_info_t info; // Check Status
if (IS_OK(lidar.getDeviceInfo(info, 100)))
{
lidar.startScan(); // Start Scanning
analogWrite(RPLIDAR_MOTOR_PIN, 255); // Start Motor
delay(1000);
}
}
}