Get Started with Lidar Hat for Raspberry Pi

Scroll down

This get started with Lidar hat guide will take you through setting up your Lidar hat and configuring it for use with a Raspberry Pi 4B.
The hat uses a low powered infrared laser beam which is safe and compliant with Class 1 laser certification. It has a serial interface and the lidar scanner can be controlled using a PWM signal.
We will show how to install the Robot Operating System (ROS) which the module relies on, using a shell script to simplify the process. This includes setting up the serial interface on the Raspberry Pi, installing the driver and running a 2D visualization of the Lidar scan. 
All the scripts used, including a stable version of the driver, are hosted on the OKdo GitHub for your convenience.

Although the Lidar Module is version LD06 some of the documentation and datasheets refer to the LD19 module.

What you'll need

Lidar module with bracket

Raspberry Pi Kit

Host computer Windows/Mac/Linux

HDMI monitor

USB keyboard

USB mouse

Ethernet cable

Internet connection and router

Raspberry Pi set up

Before adding the Lidar Module, start by setting up your Raspberry Pi Kit in the usual way. You will need to enable internet connectivity using either ethernet or Wifi. We recommend using the full desktop version of Raspberry Pi OS. If you need help with this you can follow the guide on here.

During the Raspberry Pi configuration steps you can skip the OS updates.

Robot Operating System

The Lidar Module relies on the Robot Operating System (ROS) which must be specially installed and configured to run on the Raspberry Pi.

As this process is complex and involves running multiple bash commands, we have produced two shell scripts to ease the installation. They can be found on the OKdo GitHub repository: https://github.com/LetsOKdo/ld19

The ROS installation and build script lidar_ros_setup.sh takes about 2:15 hrs to complete.

  • Open a Terminal and change to the Pi users home dir:
cd
  • Download the script and execute it.
curl https://raw.githubusercontent.com/LetsOKdo/ld19/master/lidar_ros_setup.sh | bash
  • When the script has finished, reboot the pi and test with the following command in Terminal.
roscore

The output should look something like this screenshot and shows that the ROS install was successful:

Terminal window
  • Use Ctrl + C to exit.

Monitor the build progress by checking the Terminal title eg [179 of 187]

Enable serial

Enable the Raspberry Pi’s serial port and disable serial console:

  • From the main menu click Preferences > Raspberry Pi Configuration.
  • Select Interfaces tab.
  • Click Serial Port Enabled button.
  • Click Serial Console Disabled button.
  • Select OK and reboot when prompted.
  • Select Shutdown > Shutdown to safely shutdown the Raspberry Pi.
  • Disconnect the power supply.
Raspberry Pi configuration

Attach Lidar module

Now attach the Lidar Module to the Raspberry Pi.

  • Place the Lidar module onto the support bracket with the connector facing the cutout.
  • Using two of the screws secure the module to the bracket.
  • Orient the cable connector (it only mates one way round) and connect to the module.
Lidar hat

  • Make sure the Raspberry Pi is powered off.
  • Orient the Lidar unit so that the cutout is above the GPIO header pins.
  • Attach the unit using the four remaining screws.
  • Connect the cable socket to the GPIO pins as below. It does not follow conventional colour coding:
Lidar PinRaspberry Pi PinColourMinTypicalMax
Pin 1 (TX)Pin 10 (RXD)White 0V3.3V3.5V
Pin 2 (PWM)Pin 12 (PWMO)Yellow3.3V
Pin 3 (GND)Pin 6 (GND)Red0V0V
Pin 4 (P5V)Pin 4 (5V)Blue5V5V5.5V

Check the connector is aligned correctly before powering the Raspberry Pi

Lidar connection to Raspberry PI

Lidar driver

A tested version of the Lidar driver is hosted on the OKdo GitHub along with a script lidar_driver_setup.sh to install and build it correctly.

https://github.com/LetsOKdo/ld19

  • Connect the power supply and boot the Raspberry Pi.
  • The Lidar head should spin up in the housing and a rotating blue led should be visible.
  • Open a terminal and change to the pi users home dir.
cd
  • Download the driver installation script and execute it.
curl https://raw.githubusercontent.com/LetsOKdo/ld19/master/lidar_driver_setup.sh | bash
  • When the script has finished, reboot the Pi.

Open a Terminal and test with the following commands:

  • Change into the driver installation dir.
cd ~/ld06
  • Source the driver environment.
source devel/setup.bash
  • Launch the driver.
roslaunch ldlidar ld19.launch

The output should look something like this screenshot and shows that the driver was started:

  • Leave the Terminal open and running for the next step.
Lidar driver

If you get an error when starting the driver check that the Serial Console is disabled in Raspberry Pi Configuration

RViz

This final step uses RViz visualisation software to show the results of the Lidar scan. It displays the room and obstacles around the Lidar in real-time.

  • Open another Terminal.
  • Start RViz with the following command:

rosrun rviz rviz
  • The RViz application will open.
  • From the File menu choose Open Config.
  • Navigate to /pi/ld06/rviz and select ldlidar.rviz.

The room and the surroundings should now be visualized on the 2D Grid in real-time.

rviz visualisation

After you have finished experimenting:

  • Close RViz from the menu.
  • Use Ctrl + C to shutdown the driver session.
  • Perform a safe shutdown of the Raspberry Pi.
  • Disconnect the power supply to stop the Lidar.

Summary

We have shown how to set up and install the Lidar Module on a Raspberry Pi 4B, including building the Robot Operating System, configuring the serial interface and installing the Lidar driver with the help of custom shell scripts hosted on the OKdo GitHub.

Finally, the whole installation was tested by visualising the Lidar scan in RViz.

Refer to the latest datasheet and technical information on the OKdo GitHub: https://github.com/LetsOKdo/ld19

Location

Please select an option to see content specific to your location and shop online.

Browse the US site

Privacy

Our website uses cookies and similar technologies to provide you with a better service while searching or placing an order, for analytical purposes and to personalise our advertising. You can change your cookie settings by reading our cookie policy. Otherwise, we’ll assume you’re OK with our use of cookies.