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.
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)
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
- 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.
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):
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.
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.
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.
- Open up a terminal window and type: sudo raspi-config
- Choose option: 5 Interfacing Options
- Choose option: P5 I2C and hit enter
- Choose: <Yes> to turn on the I2C interface
- Choose: Ok
- 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.
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.