Trying to get rangefinder sensor working - Page 1
Forum section: electronics / beginners

author: Dogma
author_rank: Newbie
timestamp: July 11, 2024, 01:12:16 am
content: Hi everyone,For a university project I've just bought this rangefinder module:https://www.aliexpress.com/item/1005005384252531.html?spm=a2g0o.store_pc_home.0.0.4cdc487fmbcKfl&pdp_npi=4%40dis%21NZD%21NZ%24%2071.14%21NZ%24%2071.14%21%21%21308.10%21308.10%21%402103011717162619069976790e1a6d%2112000032833515483%21sh01%21NZ%210%21I have to get it working using a C/C++ environment and a Raspberry Pi Pico but I am really battling. I've got VS Code set up all good using CMake to build the files and have confirmed that everything works by using it to program the Pico to read from an IMU. My main problem is that I don't really have an idea of how to write code for the rangefinder. In the description of the rangefinder there is a bit of information on commands to use the device but I don't really understand how to use/write code for them.Any help/advice would be greatly appreciated,Cheers

author: darkspr1te
author_rank: Frequent Contributor
timestamp: July 11, 2024, 07:13:06 am
content: from the link you provide it says it's a serial device at 9600 baud. If you send hex commands to it then it will send data back.Code:Baud rate:9600bps;data bit:8 bit;Start bit:1bit;Stop Bit:1bit;Parity:none.Remarks: Because the environment light intensity is too large, the ambient temperature is too high or too low, the reflector is too weak or too strong, or the target of a rough surface, different measurement objectives and measurement environment may cause some error of the measurement range or measurement results.• ADDR Device Address•Postion is 1, count from the top , when item is 0, count from the end (FA 04 08 01 F9),The default setting is from end•CS check byte, it sums all the bytes in front,Returns the reverse, plus 1, in the data returned by single measurements and successive measurements, in which the quotes are part of the data,Format is ASCII sample:123.456 m display 31 32 33 2E 34 35 36 ADDR Default value 80(128)The command to read data when the parameter is factory setting:Single measurement:80 06 02 78 Continuous measurement:80 06 03 77Shutdown device:80 04 02 7ASet address:FA 04 01 80 81Distance modification:FA 04 06 2D 01 CE -1FA 04 06 2B 01 D0 +1time interval (1S) :FA 04 05 01 FCSet start point:FA 04 08 01 F9 TopFA 04 08 00 FA back endsSet range:FA 04 09 05 F4 5mFA 04 09 0A EF 10mFA 04 09 1E DB 30mFA 04 09 32 C7 50mFA 04 09 50 A9 80mSet frequency:FA 04 0A 00 F8FA 04 0A 05 F3 5FA 04 0A 0A EE 10FA 04 0A 14 E4 20Set resolution:FA 04 0C 01 F5 1mmFA 04 0C 02 F4 0.1mmSet start the measurement when power on:FA 04 0D 00 F5 turn offFA 04 0D 01 F4 turn onSingle measurement (broadcast)FA 06 06 FARead cache:80 06 07 73Control laser:80 06 05 01 74 open80 06 05 00 75 Closethere is also a discussion on it here with some code ,https://forum.arduino.cc/t/laser-rangefinder-max485-communication/1154004then theres a write up here with sample code , note the dropbox links dont workhttps://blog.qartis.com/laser-distance-meter-update-serial-commands-timing-measurements/and finally a arduino library that may workhttps://github.com/hackerceo/LaserRangerdarkspr1te