Im trying to connect a JRT M88 laser distance sensor to a Mega.
I have it wired to the serial1 (19RX, and 18TX) pins.
Both the RX and TX lines go through a Sparkfun bidirectional Logic level shifter from 5vt to 3.3 vt.
The laser is powered via the Mega 3 vt pin
To operate the sensor it needs to be turned on....{0x55};
and a measurement type sent....i.e shotslow {0xAA, 0x00, 0x00, 0x20, 0x00, 0x01, 0x00, 0x01, 0x22}
Note there is also a code called...... rdmres[] = {0xAA, 0x80, 0x00, 0x22, 0xA2}; // Read Measure Result (usermanual S13 result)..... im not sure its required.
I suspect the {0x55} message is being sent as the laser turns on.
JRT have sent two very different codes...which they indicate are supplied by customers not their company.
The code for the first approach is below
byte startmsg[] = {0x55};
byte shotmsg[] = {0xAA, 0x00, 0x00, 0x20, 0x00, 0x01, 0x00, 0x01, 0x22};// changed to cont slow
byte incomingByte;
void setup() {
// pinMode(6, OUTPUT);
// digitalWrite(6, HIGH);
Serial.begin(19200);
Serial1.begin(19200);
delay(100);
// digitalWrite(6, LOW);
delay(100);
Serial1.write(startmsg, sizeof(startmsg));
delay(100);
}
void loop() {
Serial1.write(shotmsg, sizeof(shotmsg));
//delay(1000);
for (int i = 0; i <18; i++) {
// while (!Serial1.available()); // wait for a character
if (Serial1.available() > 0){
int incomingByte = Serial1.read();
Serial.print(incomingByte, HEX);
Serial.print(' ');
}
Serial.println();
delay(500);
}}
//Hexadezimale-Codes from Usermanual
byte autobdr[] = {0x55};//Auto Baud Rate
byte rdstatus[] = {0xAA, 0x80, 0x00, 0x00, 0x80};//Read Module Latest Status
byte rdhwn[] = {0xAA, 0x80, 0x00, 0x0A, 0x8A};//Read Hardware Version Number
byte rdswn[] = {0xAA, 0x80, 0x00, 0x0C, 0x8C};//Read Software Version Number
byte rdsn [] = {0xAA, 0x80, 0x00, 0x0E, 0x8E};//Read Module Serial Number
byte rdiv[] = {0xAA, 0x80, 0x00, 0x06, 0x86};//Read Input Voltage
byte rdmres[] = {0xAA, 0x80, 0x00, 0x22, 0xA2}; // Read Measure Result (usermanual S13 result)
byte lon[] = {0xAA, 0x00, 0x01, 0xBE, 0x00, 0x01, 0x00, 0x01, 0xC1};// Laser on
byte loff[] = {0xAA, 0x00, 0x01, 0xBE, 0x00, 0x01, 0x00, 0x00, 0xC0};//Laser off
byte shotauto[] = {0xAA, 0x00, 0x00, 0x20, 0x00, 0x01, 0x00, 0x00, 0x21};//Start 1-shot Auto Distance Measure
byte shotslow[] = {0xAA, 0x00, 0x00, 0x20, 0x00, 0x01, 0x00, 0x01, 0x22};// Start 1-shot Slow Distance Measure
byte shotfast[] = {0xAA, 0x00, 0x00, 0x20, 0x00, 0x01, 0x00, 0x02, 0x23};//Start 1-shot Fast Distance Measure
byte cntinusauto[] = {0xAA, 0x00, 0x00, 0x20, 0x00, 0x01, 0x00, 0x04, 0x25}; //Start Continuous Auto Distance Measure auto
byte cntinusslow[] = {0xAA, 0x00, 0x00, 0x20, 0x00, 0x01, 0x00, 0x05, 0x26};// Start Continuous Slow Distance Measure slow
byte cntinusfast[] = {0xAA, 0x00, 0x00, 0x20, 0x00, 0x01, 0x00, 0x06, 0x27};// Start Continuous Fast Distance Measure fast
byte stopmes[] = {0x58};//Stop continuous Mesure
byte incomingByte [13] = {};
int x = 0;
int count = 0;
int val = 0;
void setup() {
Serial1.begin(19200, SERIAL_8N1);
Serial.begin(19200);
delay(200);
Serial1.write(autobdr, sizeof(autobdr));
delay(100);
Serial1.write(rdstatus, sizeof(rdstatus));
delay(100);
Serial1.write(rdiv, sizeof(rdiv));
delay(100);
}
void loop() {
Serial1.write(shotslow, sizeof(shotslow));
delay(30);
if (Serial1.available() > 0){
Serial1.readBytes(incomingByte, 13);
val = incomingByte[8];
val = val << 8;
val = val + incomingByte[9];
Serial.println(val, DEC);
delay(100);
}}
I really appreciate your help
Marcus
M8xx-JRT-User Manual.1.-40m.pdf (1.18 MB)