I've purchased 2 laser modules (TW10S-UART) from aliexpress. They have no info about programming at all, only the following info and I can't figure out what commands I should send to tell the laser to take and reading and how to get the correct data back.
The information on the aliexpress site had the text formatted just as you see it below.
Would someone be willing to help?
Protocol instruction description:
1: The sensor is ready to continue
Before each ranging, set the EN pin to high level (3.3V ~ 5V), the sensor will be woken up and initialize the hardware, the sensor will continue to issue the following
Response:
01 03 02 00 00 B8 44
Set EN low after the measurement is completed, and the sensor enters low power mode.
2: Read the input register (function code 0x03) (Before issuing this command, wait for the sensor to continue)
Example:
Read measurement distance
Description Address code Function code Start address Number of registers CRC
Send: 0x01 0x03 0x00 0x0F 0x00 0x02 0xF4 0x08
Normal response (measurement distance 57.505m):
Description Address code Function code Number of bytes Register 1 value Register 2 value CRC
Normal response: 0x01 0x03 0x04 0x00 0x00 0xE0 0xA1 0x72 0x4B
Note (the distance in this instruction is 4 bytes, 0x00 0x00 0xE0 0xA1, and the distance is 0x0000E0A1, converted to 57505mm in decimal)
That was:
0x01 (Address)
0x03 (Function: Read Register)
0x000F (Register start address)
0x0002 (Number of 2-byte registers to read)
0xF408 (CRC)
What you receive back is:
0x01 (Address)
0x03 (Function: Register Contents)
0x04 (Data length in bytes)
0xHHHHHHHH (four bytes of distance in mm, MSB first)
0xHHHH (CRC)
I made a valiant attempt on my own and could get the laser to turn on, but the data returned was always 'FF' (255 DEC). It would turn on but wouldn't actually take a reading and return anything that looked like distance data.
I wasn't sure who the manufacturer was and didn't find anything specific when searching. However, I never used the 'code' word as a search word. Your link looks like it might show some sites with info, so I'll continue looking.
Thank you John for parsing the register items. I didn't know how to break it up. I've performed a serial.read before, but how exactly would I break up 4 bytes and convert that to decimal?
Also, I'm not exactly sure what command actually tells the laser to fire to obtain a reading.
Did you check that data was available before reading? Serial.read() returns -1 if you try to read from an empty buffer. If you store -1 in a byte it becomes 255. Perhaps you should show the sketch you are using.
What baud rate are you using for the sensor? One place says the default is 38400 but it could be anything.
Hi, I have found code for that Lasermodule that works so far (not written by me)
Setup:
ESP32 D1 MINI with TW10S UART Laser
Serial2 Pin16/17
Laser EN-Power connected permanently to VCC
my problem now is that i can't bring the Laser to "continuous" mode
it always stopps for a moment so i have no continuous reading of distance.