I'm looking for some help integrating with this laser distance measuring kit. I can turn the laser on and off but when I try and send a request for measurement I get garbage back. I set up a button to turn on the laser and when the button is on trying to request a single measurement. I am doing this on an UNO. Here is the code I have tried:
Here is a link to the datasheet that shows their communication protocols.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(6, 7);
// constants won't change. They're used here to set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
mySerial.begin(9600);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
pinMode(9, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH)
{
// turn LRF on:
digitalWrite(9, HIGH);
//Not sure which order these need to be sent in
byte message[8]={0xA8,0x45,0x44,0x01,0x00,0x00,0x00,0xAA}; // reversed order, for sendig single measurement request
//byte message[8]={0xAA,0x00,0x00,0x00,0x01,0x44,0x45,0xA8}; // order as shown in doc, for sendig single measurement request
//Serial.write(message,sizeof(message));
mySerial.write(message,sizeof(message));
//delay(5000);
Serial.println("Sent Data");
}
else {
// turn LRF off:
digitalWrite(9, LOW);
}
if(mySerial.available()) Serial.write(mySerial.read());
//if(mySerial.available()) Serial.println(mySerial.read());
}
I wasn't sure if I'm sending the right packet information and if I need to reorder the bytes. I tried both ways. I have pin 6 (Rx) connected to their Tx wire. I have pin 7 (Tx) connected to their Rx wire.
Thanks for your help.