BA6A Laser Distance Sensor UART Communication Help?

I'm trying to communicate with this BA6A laser distance sensor (https://www.jrt-measure.com/2004-2021-new-laser-distance-sensor/58854931.html) using an Arduino Uno with a UART protocol; the datasheet for the device is attached below.

The device is supposed to take VCC between 2.5V and 3.3V so I used this level shifter (Bi-Directional Logic Level Converter Hookup Guide - SparkFun Learn) between the sensor and Arduino. I have tested the circuit in three configurations, one with this level shifter and an independent power supply for the sensor (figure 1), one with the Arduino's Vin pin powering the sensor (figure 2), and one with the Arduino's 5V pin powering the sensor (figure 3).

I have written some code attached below that I am testing with just to try to get some functionality out of the sensor. I’m using SoftwareSerial to establish one serial line for the sensor to communicate with the Arduino and another for the Arduino to communicate with my PC for debugging messages.

As specified in the sensor's datasheet, the sensor works by sending an 'O' command in serial to open the laser (or 'C' to close it), and the sensor will return "Ok!". From there, sending 'D' in serial requests a measurement and then the sensor should reply with a distance in meters followed by a unitless quality metric (ex. "1.982m, 0283").

I don't have much experience with UART communication so I've hit quite a few problems. I have confirmed that the sensor has power (the laser is on and sensor VCC is at the intended voltage). When connected to the Arduino via the level shifter as in figure 1, my debugging serial monitor just spits out a bunch of empty messages and a few unrecognized characters and ‘?’ in the mix. It won’t even display the “inByte: ” and “message: ” strings that I print directly from the Arduino to serial.

When I connect the sensor to higher voltage (Arduino Vin or 5V pins as in figures 2 and 3, respectively), the debugging serial monitor is entirely empty, not displaying any messages at all. I have confirmed that the sensor is still powered on in these configurations.

At this point I’m pretty stuck and I would greatly appreciate any guidance this community can offer!

Configuration 1:

Configuration 2:

Configuration 3:

Sensor Datasheet:
20201015205513100M-new(1).pdf (606.2 KB)

Software:
sensor_test_Av2.2.2.ino (1.5 KB)

Note: I used a lot of code from this website to help me get started with UART: Serial.read and Arduino: Here's the advanced stuff you should know

1 Like
mySerial.println('D');  //send byte to sensor to request measurement
mySerial.flush();       //wait for transmission to end

 //Check to see if anything is available in the serial receive buffer
 while (mySerial.available() > 0)

It's quite improbably that your sensor device answered fast enough for the response to arrive before the while loop starts.

And as you write much more to the Serial interface than you receive on the mySerial interface you should increase the baudrate there or decrease the baudrate of mySerial (if possible).

Where you able to communicate with it ?
Can you share latest code and connection schem ?
I am trying to connect PTFS-1200m also from JRT without success

https://www.jrt-measure.com/2004-2021-new-laser-distance-sensor/58612798.html

Looks like the commands it not what is given! :scream:

Hi there! Can anyone share the datasheet and/or test software for the BA6A module? Thank you!

After performing sniffing on the serial port, I found our that there are additional commends to open and start communication with the sensor, I used the suppliers software to send commends

Hi, remember BA6A tx and rx pin are open drain; add load resistors (15k) to set up voltage level . To perform Auto distance Measure send Hex String "AA 00 00 20 00 01 00 00 21"

small example: BA6A performs 1 shot Auto distance Measure and replies with 13 bytes . Arduino Due used (no need to translate signal voltage). Pin TX of BA6A connected to a 15k resistor to 3,3 Vcc. and to Arduino RX1. Pin RX of BA6A connected to Arduino TX1.

byte lmsr[] = {0xAA, 0x00, 0x00, 0x20, 0x00, 0x01, 0x00, 0x00, 0x21};  //Laser measure 1 shot auto
char c=0;
void setup() {
  Serial.begin(19200);
  Serial1.begin(19200);  //start com 1 to activate pin TX1 and RX1
  delay(10);
  Serial1.write(0X55); // 0X55 for autobaud rate
  delay(100);          // at least 100ms to complete autobaud
 }
void loop() {
 String s;
 long distance; 
 int quality;   
 Serial1.write(lmsr, sizeof(lmsr));  //perform single auto measure
 delay(10); 
 s = "";
  while (Serial1.available() > 0) {
    c = Serial1.read();
    s += c;
    }
   distance=((s[6]<<24)|(s[7]<<16)|(s[8]<<8)|(s[9])); // bytes 6 to 9 distance in mm
   quality =((s[10]<<8)|(s[11]));
   Serial.print(distance);Serial.print(" mm. ------");Serial.print(quality);Serial.print(" signal quality --");Serial.println();  
   Serial1.flush();   
   delay(1000);    
}



This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.