I’ve just started working with LIDAR for the first time, and I’m having difficulty understanding how to connect it to the Arduino Mega2560 and retrieve data from it (distance and angle). I am attempting to use the lidar library provided here: https://github.com/YDLIDAR/ydlidar_arduino
and I have run into issues connecting the lidar to my arduino correctly.
According to the datasheet the black is ground, white is Rx, green is Tx and red is Vcc. This means that I should connect the black to arduino’s ground, green to arduino’s Tx, white to arduino’s Rx and red to arduino’s 5V. Is that correct?
How am I supposed to enable the motor or issue commands using this library without a connection to an Arduino pin? It appears that the library was designed with the G4 in mind (see the ConnectYDLidar.ino example). Am I missing something in the data sheet? Does anyone know of an alternate library for the G4?
Probably the other way around for RX and TX. You will need a 3.3V to 5V logic level converter, as the signals on the Lidar are 3.3V and on the Arduino, 5V. I'm not sure if the Arduino supports the serial Baud rate of 230400.
You will need a separate power supply for the Lidar 5V. The Arduino is not a power supply and cannot provide the required current (1 Ampere startup). Be sure to connect all the grounds.
It is a really, really good idea to read the data sheet carefully! And surely, you can find examples of connecting this device to a 5V Arduino (otherwise, use a 3.3V Arduino).
With serial communications think when you send something (TX) who or what is going to here it (RX). Conversely if you are listening (RX) who is going to tell you (TX). That works in both directions. Note TX cannot hear and RX is mute. So TX goes to RX that way they can communicate. They may still argue about bit rate etc but they do communicate.