I have an MVR2EB lidar module I got from amazon, and it can output in both hex and ASCII. I would really really really like to get it working in ASCII mode. Problem is, the module does not seem to be accepting the command and changing modes. According to the datasheet, I should send a string of "56 71 00 27" to switch to ASCII mode. I'm using Serial.write for this. Does my code at least look correct?
void setup() {
Serial.begin(115200);
Serial1.begin(115200); // replace 17,16 with your RX/TX pins
delay(1000);
byte SendData[] = {0x56,0x71,0x00,0x27};
Serial.print("Sending Message ");
Serial.write(SendData,sizeof(SendData));
}
void loop() {
if (Serial1.available() > 0) { // If anything comes in
Serial.print(Serial1.read(), DEC); // read it and send it out
Serial.print(", ");
int Sync = Serial1.read();
Serial.print(Sync, HEX); // read it and send it out
Serial.print(", ");
int code = Serial1.read();
Serial.print(code, HEX); // read it and send it out
Serial.print(", ");
Serial.print(Serial1.read(), HEX); // read it and send it out
Serial.print(", ");
Serial.print(Serial1.read(), HEX); // read it and send it out
Serial.print(", ");
Serial.print(Serial1.read(), HEX); // read it and send it out
Serial.print(", ");
Serial.print(Serial1.read(), HEX); // read it and send it out
Serial.print(", ");
Serial.print(Serial1.read(), HEX); // read it and send it out
Serial.print(", ");
Serial.print(Serial1.read(), HEX); // read it and send it out
Serial.print(", ");
Serial.print(Serial1.read(), HEX); // read it and send it out
Serial.print(", ");
Serial.println(Serial1.read(), HEX); // read it and send it out
}
}
The other issue is reading the hex it sends back in the serial monitor. I'm not sure I'm doing it right.
After running the code above, this is what the serial monitor gives me:
Sending Message Vq'137, 81, BD, 4, C7, 18, 26, FA, 0, 0, B2
137, 81, BD, 4, CC, 18, 26, FA, 0, 0, B9
137, 81, BD, 4, BC, 18, 26, FA, 0, 0, C9
137, 81, BD, 4, BC, 18, 26, FA, 0, 0, C9
137, 81, BD, 4, B4, 18, 26, FA, 0, 0, C1
137, 81, BD, 4, AC, 18, 26, FA, FFFFFFFF, FFFFFFFF, 89
129, C1, 4, 4E, 18, 26, FA, 0, 0, 47, FFFFFFFF
137, 81, C2, 4, 4F, 18, 26, FA, 0, 0, 45
137, 81, C2, 4, 66, 18, 26, FA, 0, 0, 6C
137, 81, C1, 4, 6E, 18, 26, FA, 0, 0, 67
137, 81, C1, 4, 6A, 18, 26, FA, 0, 0, 63
137, 81, C1, 4, 63, 18, 26, FA, 0, 0, 6A
137, 81, C1, 4, 5A, 18, 26, FA, 0, 0, 53
137, 81, C1, 4, 54, 18, 26, FA, 0, 0, 5D
137, 81, C1, 4, 5D, 18, 26, FA, 0, 0, 54
137, 81, C1, 4, 5C, 18, 26, FA, 0, 0, 55
137, 81, C1, 4, 5B, 18, 26, FA, 0, 0, 52
137, 81, C1, 4, 59, 18, 26, FA, 0, 0, 50
137, 81, C2, 4, 48, 18, 26, FA, 0, 0, 42
137, 81, C2, 4, 52, 18, 26, FA, 0, 0, 58
137, 81, C2, 4, 56, 18, 26, FA, 0, 0, 5C
I don't know what the "Vq" thing is. And if I change the first "Serial1.read" to HEX instead of DEC, I get highly garbled output. This is the only way we could get it to look remotely like it's supposed to.
So our problems are the module not reading my output, and me not reading the hex output properly to begin with.