Hello, I'm working on creating a system that utilizes two U81 Laser Rangefinder (LRF) sensors from Chengdu JRT, transmits the data via RS485 to two Max485 modules, and then to my Arduino Mega 2560 r3. I've been using the datasheet from the manufacturer but am only able to get the LRF's to return zeros. I have verified voltages at all critical locations, and tested the circuit at each stage of increasing complexity.
My test program is as follows:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(18, 19); // RX, TX - Pins for the laser range finder
// COMMANDS FROM DATASHEETs
byte one_shot_auto[9] = {0xAA, 0x00, 0x00, 0x20, 0x00, 0x01, 0x00, 0x00, 0x21};
byte read_measurement_result[9] = {0xAA, 0x00, 0x00, 0x22, 0x00, 0x03, 0x00, 0x00, 0x00};
byte laser_on[9] = {0xAA, 0x00, 0x01, 0xBE, 0x00, 0x01, 0x00, 0x01, 0xC1};
byte laser_off[9] = {0xAA, 0x00, 0x01, 0xBE, 0x00, 0x01, 0x00, 0x00, 0xC0};
// VARs FOR WORKING WITH DATA
unsigned long Data = 0;
byte Read[13]; // Increased to 14 to accommodate the reply from the sensor
const int PWRENPin = 23; // PWREN pin connected to Pin 23
void setup() {
Serial.begin(19200); // Set baud rate for Serial Monitor
pinMode(PWRENPin, OUTPUT); // Set PWRENPin as an output pin
digitalWrite(PWRENPin, HIGH); // Power on the laser range finder
delay(1000); // Wait for the sensor to initialize
mySerial.begin(19200); // Set baud rate for communication with the laser range finder
mySerial.setTimeout(0.001);
//test ON and OFF pointer
Serial.println("LASER POINT ON...");
mySerial.write(laser_on, 9);
delay(1000);
Serial.println("LASER POINT OFF...");
mySerial.write(laser_off, 9);
delay(200);
}
void loop() {
Serial.println("read one shot mode: ");
Data = 0;
mySerial.write(one_shot_auto, 9);
//Received command in HEX format
while (mySerial.available()>0){
mySerial.readBytes(Read,13);
}
//Print Data for test
Serial.println(" ");
Serial.print("Value in HEX:");
for (int i = 0; i <= 12; i++){
Serial.print(Read[i],HEX);
}
//Print only measure data
Serial.println(" ");
Serial.print("Measured Data in HEX:");
for (int i = 6; i <= 9; i++){
Serial.print(Read[i], HEX);
}
// If you want convert to Decimal
for (int i = 6; i <= 9; i++){
Data = (Data |= Read[i]) << 8 ;
}
Data = Data >> 8;
//Print in mm
Serial.println(" ");
Serial.print("Measurement in mm: ");
Serial.println(Data, DEC);
delay(1000);
}
I was going to upload datasheets with this post but was blocked d/t being a new user, will try again in a couple days.
I've looked at countless forum articles, and feel like the answer is staring me in the face.
Thanks in advance for any and all help!