Hello, I've been working on a project with an Arduino Mega and a U81 laser range finder from JRT (user manual attached below). I'm utilizing the UART ports on the Arduino to just use TTL Serial since that seems to be the most simplistic way to accomplish my goal. The user manual is riddled with typos, poorly translated sections, etc and it has been causing a lot of issues by not having a good reference document.
Currently I'm not even trying to user the laser range finder to measure distance, I'm simply trying to establish communications between my microcontroller and the U81. At the moment, I'm trying to give it this command:
and then the user manual shows the following as the method to read the result of the previous command:
Yet my Serial Monitor Output only gives me the following:
I've also attempting to send just the "read input voltage" command, and then to store and display the resulting data into a temp array but have been unsuccessful so far.
Here is my code as it sits currently:
// No need to include SoftwareSerial library, as we will use hardware UART (Serial1)
//Serial1____ -> Referring to exterior devices
//Serial____ -> Communicating to PC Serial Monitor to print data.
// COMMANDS FROM DATASHEET
byte rd_status[5] = {0xAA, 0x80, 0x00, 0x00, 0x80};
byte reply_status[9] = {0xAA, 0x80, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00};
byte rd_hv[5] = {0xAA, 0x80, 0x00, 0x0A, 0x8A};
byte reply_hv[9] = {0xAA, 0x80, 0x00, 0x0A, 0x00, 0x01, 0x00, 0x00, 0x00};
byte rd_sw[5] = {0xAA, 0x80, 0x00, 0x0C, 0x8C};
byte rd_sn[5] = {0xAA, 0x80, 0x00, 0x0E, 0x8E};
byte rd_vo[5] = {0xAA, 0x80, 0x00, 0x06, 0x86};
byte reply_vo[9] = {0xAA, 0x80, 0x00, 0x06, 0x00, 0x01, 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};
byte one_shot_auto[9] = {0xAA, 0x00, 0x00, 0x20, 0x00, 0x01, 0x00, 0x00, 0x21};
byte reply_measurement_results[5] ={0xAA, 0x80, 0x00, 0x22, 0xA2};
//==========
void setup() {
// Establish baud rate
Serial.begin(115200);
delay(1000);
Serial1.begin(115200);
delay(2500);
Serial.println("==========");
Serial.println("Setup: Baud Rate has been established.");
// Cycle Power To LRF
Serial.println("Setup: Cycling Power to LRF...");
Serial1.write(laser_off, 9);
delay(100);
Serial1.write(laser_on, 9);
delay(2000);
Serial.println("Setup: LRF Powered On.");
//Read Input Voltage
Serial.println("Setup: Checking Input Voltage...");
Serial1.write(rd_vo, 5);
delay(10);
if (Serial1.available() >= 9) {
Serial1.readBytes(reply_vo, 9);
//Print Response
byte payload1 = reply_vo[6];
byte payload2 = reply_vo[7];
int combinedpayload = (payload1 << 8) | payload2;
if(combinedpayload < 0x1000){
Serial.println("0"); //Print leading zero if necessary
}
Serial.println(combinedpayload, HEX);
}
else {
Serial.print("Raw VCC Reply Packet: ");
for (int i = 0; i < 9; i++) {
Serial.print(reply_vo[i], HEX);
Serial.print(" ");
}
Serial.println(); // Print a newline at the end
}
}
//==========
void loop() {
}
Any and all suggestions are greatly appreciated, have been struggling with this for a couple weeks now
U81 Laser Distance Sensor USER MANUAL.pdf (3.1 MB)