REF. need help for setting it up. i have the same LRF but this is not working
What have you tried so far?
You should post the code you are using along with a drawing of how you've connected it all together.
Appears the other person you referenced never got it to work either.
// Laser Range Finder Communication Example
// Define constants for LRF communication
const int LRF_RX_PIN = 10; // RX pin for communication (connect to LRF TX)
const int LRF_TX_PIN = 11; // TX pin for communication (connect to LRF RX)
// Include libraries
#include <SoftwareSerial.h>
// Initialize SoftwareSerial for LRF
SoftwareSerial lrfSerial(LRF_RX_PIN, LRF_TX_PIN);
// Function to calculate checksum
byte calculateChecksum(byte command[]) {
byte sum = 0;
for (int i = 2; i < 7; i++) { // Sum Byte 3 to Byte 7
sum += command[i];
}
return sum;
}
// Function to send a command and wait for a response
void sendCommand(byte command[], byte response[], int responseSize) {
// Send the command
for (int i = 0; i < 8; i++) {
//Serial.println(command[i],HEX);
lrfSerial.write(command[i]);
}
// Wait and read the response
delay(100);
for (int i = 0; i < responseSize; i++) {
if (lrfSerial.available()) {
response[i] = lrfSerial.read();
}
}
}
void setup() {
// Initialize serial for debugging
Serial.begin(9600);
// Initialize LRF communication
lrfSerial.begin(9600); // Start communication at 9600 to set baud rate
delay(100);
// Set LRF baud rate to 115200
byte setBaudCommand[8] = {0x55, 0xAA, 0x88, 0xFF, 0xFF, 0xFF, 0xFF, 0x00};
setBaudCommand[7] = calculateChecksum(setBaudCommand);
byte baudResponse[8];
sendCommand(setBaudCommand, baudResponse, 8);
if (baudResponse[3] == 0x01) {
Serial.println("Baud rate set to 115200 successfully.");
} else {
for (int i = 0; i < 8; i++) {
Serial.print("0x");
if (baudResponse[i] < 16){ Serial.print("0");}
Serial.print(baudResponse[i], HEX);
Serial.print(" ");
}
Serial.println();
Serial.println("Failed to set baud rate.");
}
// Update LRF baud rate in SoftwareSerial
lrfSerial.begin(14400);
delay(100);
}
void loop() {
// Perform a single distance measurement
byte distanceCommand[8] = {0x55, 0xAA, 0x88, 0xFF, 0xFF, 0xFF, 0xFF, 0x00};
distanceCommand[7] = calculateChecksum(distanceCommand);
byte distanceResponse[8];
//sendCommand(distanceCommand, distanceResponse, 8);
// float distance=0;
// distance=distanceResponse[6]*256+distanceResponse[7]*0.001 ; // byte 6 and 7 are specified as data_h and data_l in the document
// Serial.print("Distance = ");
// Serial.print(distance);
// Serial.println(" M");
// delay(20);
// Parse the response
if (distanceResponse[3] == 0x01) { // Status = Success
int highByte = distanceResponse[5];
int lowByte = distanceResponse[6];
int distance = (highByte << 8) | lowByte; // Combine high and low bytes
float realDistance = distance / 10.0; // Convert to meters
Serial.print("Distance: ");
Serial.print(realDistance);
Serial.println(" m");
} else {
// Serial.println("-----------------------");
// Serial.println(distanceResponse[0]);
// Serial.println(distanceResponse[1]);
// Serial.println(distanceResponse[2]);
// Serial.println(distanceResponse[3]);
// Serial.println(distanceResponse[4]);
// Serial.println(distanceResponse[5]);
// Serial.println(distanceResponse[6]);
// Serial.println(distanceResponse[7]);
// Serial.println(distanceResponse[8]);
//Serial.println("Distance measurement failed.");
}
delay(1000); // Delay before the next measurement
}
Connections are 10,11 on Uno and 5v and Ground
https://drive.google.com/drive/folders/1NjK5_ys1XIXW43HF_keSPVtgrzg7pM9F?usp=drive_link
attaching the docs given to me by Manufacturer
What baud rate are you using for the LRF? It starts at 9600, then a comment says 115200 but your code the sets 14400.
i was trying with different baud rates but nothing worked.
Why you want to set high baud rate, if you are using software serial that can't reliably work with high rates.
Also note that if you change the baud rate, you need to change it in your code as well.
Also note what the mf suggests:
" * Do Not use Baud rate changes to check if the module works. * Please use one more time measurement to check if the module works."*
i changed in the code as well still nothing, no value from LRF. as it was sending the same value back.
What does this mean exactly?
You get some response?