Setting up Lidar Lite 3 on Raspberry Pi 3

I got a Garmin Lidar Lite 3 for Christmas this year.  This is a simple post documenting what I had to do to get it up and running.

Lidar Lite 3 is an optical distance measuring unit that uses lasers to calculate distance.  The unit is commonly used to things like range-finding, and object sensing/avoidance in robots and drones.  It is generally more accurate than using other techniques like Sonar to ‘see’ objects, but there are any number of applications for it.

Garmin’s documentation for the Lidar Lite 3 can be found here. (Manuals & Software:  C Library for Arduino (No RPi Specific Library from Garmin…)

Since there’s no official Garmin Raspberry Pi libraries, this one worked well for me to get the basic functionality up and running.  (Lidar Lite C & Python Libraries)

Hardware Setup

Setting up the Raspberry Pi to talk to the Lidar unit was pretty straight forward.  This assumes that you already have a Pi up and running.  I used a Raspberry Pi 3 running Pixel installed via Noobs.  In addition I used the following setup:

  • Raspberry Pi 3 running Pixel
  • Breadboard
  • 40-pin GPIO extender
  • 40-pin patch cable
  • Lidar Lite 3 with included cable
  • 680µF Electrolytic Capacitor
  • Connection Wires

According to the Garmin documentation the Lidar Lite 3 can be connected using I2C or or PWM; I used I2C to make the connection following the below diagram from the Garmin manual.

lidarlite3i2cdiagram

The setup is pretty simple just remember that you need the Capacitor between the 5v/Ground from the Raspberry Pi and the Power/Ground cables of the Lidar unit otherwise you may fry one or both of them.

Using the diagram above I made the connections to the breadboard using the GPIO extension like so (The Raspberry Pi is not connected yet, wire it up and then connect it so you don’t accidentally fry something):

img_0228

On the Raspberry Pi 3 and my GPIO extension the I2C SDA and SCA connections are pins 3 & 5 in the top right just under the 3v power connection.  The Lidar Lite 3 requires the 5v power out to run so I’ve made the power and ground connections along the bottom rail.

Next you need to make sure that the capacitor is in-between the RPi power/ground and the Lidar Lite 3 connection.

img_0232

For the capacitor the long connectors is on the power rail and the short connector is on ground.  Then you simply run the red power line and black ground line from the Lidar unit and connect them to their respective power/ground rails.

The only other connections from the Lidar unit that you need to worry about are the SDA (Blue) and SCA (Green) connections.  This is done by connecting them to the I2C SDA/SCA pins on the RPi.

img_0231

And that’s it, the board is all wired and you can connect the board to the RPi without hurting anything.

Setting up the Raspberry Pi

Since we are using I2C to talk to the Lidar unit there are a few thing that need to be setup on the RPi to make this happen.  As mentioned earlier, this was done with a basic Raspberry Pi 3 running Pixel installed via Noobs from Raspberrypi.org.

Setting up I2C

First you need to make sure that I2C is enabled on the Raspberry Pi.  There’s a pretty good write-up on I2C and Raspberry Pi here, but I’ve condensed it down to the steps below.  If you want to read more on it follow the link. Of note, that tutorial is a bit dated as far as the raspi-config menu goes, but the rest works.

  1. Open up a terminal window and type:  sudo raspi-config
  2. Choose option: 5 Interfacing Options
  3. Choose option: P5 I2C and hit enter
  4. Choose:  <Yes> to turn on the I2C interface
  5. Choose: Ok
  6. Choose:  Finish

This should turn on the I2C pins on the RPi to test whether or not it worked in your terminal window type this command:  ls /dev/*i2c*

This should return something like this:  ‘/dev/i2c-1’ if you see that then you are good.

Next you need to install the i2c tools to get the command line tools needed to interact with i2c.  In the terminal type:  sudo apt-get install -y i2c-tools

Once that is installed you can test it using the i2detect utility.  The resulting map where the peripheral is addressed.  in my case it’s mapped to 0x62.

If you wired it up correctly, and the grid came back with an address then you are all set, the Raspberry Pi is now talking to the Lidar Lite.

Basic Operations

The Garmin library is written for Arduino and in C, neither of which I needed.  I did find a pretty good basic library on GitHub that worked pretty well for me here.  I cloned the Git onto my Raspberry Pi and then tested it by running the test.py file in the Python folder.

Just to play around with it a bit more I wrote a very simple loop to take some measurements and warn me if something is too close:

from lidar_lite import Lidar_Lite
lidar = Lidar_Lite()

connected = lidar.connect(1)

if connected < -1:
    print “Not Connected”
else:
    print “Connected”

for i in range(100):
    distance = lidar.getDistance()
    print(“Distance to target = %s” % (distance))
    if int(distance) < 50:
        print(“Too Close!!! Back Off!!!”)

This is pretty simple, it just takes 100 measurements and if anything (like your hand) moves within 50 of the Lidar unit then it starts to print a warning.

That was it, the unit is now up and running at a basic level.

 

 

4 Comments

  1. I am having difficulty recognizing the Lidar Lite Sensor using your suggested configuration (via i2cdetefct). The tech from Robot Shop said that I may not have sufficient power to initialize. Presume you are using the default power supply for the Pi? In any event it appears mine is insufficient. Not sure there is any easy way to get additional power. By the way thanks for the tutorial for the capacitor as not that familiar with electronics.

    Like

  2. thank you very much for sharing your experience, I did the same but after running your last loop app, I only getting below message regardless of distance.
    Distance to target = 0
    Too Close!!! Back Off!!!

    I did some research and look like after last kernel update everything stop working :
    http://www.robotshop.com/forum/post-p130228#p130228

    and

    https://www.raspberrypi.org/forums/viewtopic.php?f=91&t=179248#

    wondering if you have any solution for it.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s