Reading Neato LIDAR Ranging Data with a BeagleBone Black

I’ve been experimenting with the idea of using a Neato LIDAR module paired with a BeagleBone Black to form the core of an autonomous wheeled robot. This would be done using a SLAM algorithm running on the the BeagleBone Black, with the LIDAR providing the robot’s vision. So far, I’ve been able to hook up the LIDAR to one of the serial ports of the BeagleBone and read the ranging data that it outputs.

Enabling a Serial Port on the BeagleBone Black

On the BeagleBone Black, each I/O pin can be used for multiple purposes (but not at the same time). This means that before using a pin, we need to be sure it is in the correct mode. The mode can be set using device tree overlays. In this case I just wanted to enable the RX and TX pins for the 2nd serial port, which was easy to do by running the following commands from a terminal connection to the BeagleBone. Note that I’m using a Revision C BeagleBone Black with the Debian OS that came pre-installed.

cd /sys/devices/bone_capemgr.*
echo BB-UART2 > slots

After doing this, I ran cat slots to verify that it had been setup correctly. I also used dmesg to check the logs and make sure there wasn’t anything unusual.

I originally tried this using the 1st serial port (BB-UART1), and while everything looked fine initially, things didn’t seem quite right when I ran the following commands to check the pin modes.

cd /sys/kernel/debug/pinctrl/44e10800.pinmux
cat pingroups
cat pins

Running cat pingroups told me which pin numbers were being used for the serial port, and cat pins provided a list of the pins along with the mode that each one was in. For BB-UART1, it turned out that both the RX and TX pins were set to 0x20, which is pin mode 0, in input mode (note: reference the BeagleBone Black documentation for an explanation of the different pin modes). This didn’t seem right, as the TX pin should be in output mode. When I switched to BB-UART2, the pin modes for the RX and TX pins were 0x21 (input, mode 1), and 0x01 (output, mode 1), which is what I expected.

The Neato LIDAR uses a baud rate of 115200, so it is important to set that correctly like so:

stty -F /dev/ttyO2 115200

Wiring the Neato LIDAR

I connected the 4-wire strip from the Neato LIDAR to the BeagleBone Black as follows (red wire last):

Neato LIDAR BeagleBone Black
Black Wire (GND) P9_1 or P9_2 (both ground)
Orange Wire (LDS_TX) P9_22 (uart2_rxd)
Brown Wire (LDS_RX) P9_21 (uart2_txd)
Red Wire (+5V) P9_5 or P9_6 (both VDD_5V)

Neato LIDAR and BeagleBone Black Wiring More Neato LIDAR and BeagleBone Black Wiring

Connecting the motor directly to a 3V power supply will cause it to spin at a speed within the acceptable range. Later on, I plan to drive the motor with a PWM signal and use the rpm data provided by the serial connection to keep the speed consistent, but this is good enough for now.

Testing the Serial Connection

At this point, I ran cat /dev/ttyO2 and spun the LIDAR by hand to verify that the connection was working. Of course, this only produced random characters since the data was encoded. Next, I used screen /dev/ttyO2 115200 to open a serial connection that would allow me to send commands to the LIDAR. For example, typing getversion returns some basic information about the unit. There are a number of other useful commands for testing and calibration, which can be found by typing help. Be warned that some of these might brick the device if used improperly. There is also some documentation for this on the xv11hacking website.

Reading Ranging Data

To view the data as hex values, I ran the following Python script while spinning the LIDAR motor manually.


with open("/dev/ttyO2", "rb") as f:
    byte =
    count = 1
    while byte != "" and count <= 22*100:
        print(byte.encode('hex') + ":")
        byte =
        count += 1


This produced the expected output of 22 bytes per packet, as detailed here. There were a few bad packets, but not enough to have much of an effect. However, the 4 data reading sections of each packet were invalid. Most of the data reading hex values were 50 80 00 00, but there were also a few that were 52 80 00 00. The second byte’s value of 80 is what indicates that the data is invalid in both of these cases. The first byte is apparently an error code, but I haven’t been able to find out what the error codes 50 and 52 mean.

After a bit of head scratching, I finally figured out that the data was invalid because the LIDAR was not spinning at the proper rate. Powering the LIDAR’s motor with 3V and updating my Python script to capture 1000 packets instead of 100 produced good data. Capturing only 100 packets simply didn’t give the LIDAR time to get up to speed.

Valid Sample Data:


Visualizing the Data

The only thing left at this point was to graph some of the sample data so that I could determine how accurate the Neato LIDAR’s readings were. For this part I used a Python script on my laptop.

import numpy as np
import matplotlib.pyplot as plt

def getDist(lsb, msb):
    if (msb == "80" or msb == "70"):
        return False
    return int(msb + lsb, 16)/1000.

def addPoint(dist, theta, x, y):
    if (dist != False and dist < 6):
        x.append(dist*np.cos((theta+90) * np.pi/180))
        y.append(dist*np.sin((theta+90) * np.pi/180))

with open("C:\Users\Alex\Desktop\lidardata.txt") as f:
    line = f.readline()
    while line != "":
        bytes = line.strip(':n').split(':')
        if (len(bytes) == 22):
            theta = (int(bytes[1], 16) - 160) * 4
            # print(line)
            addPoint(getDist(bytes[4], bytes[5]), theta, x, y)
            addPoint(getDist(bytes[8], bytes[9]), theta + 1, x, y)
            addPoint(getDist(bytes[12], bytes[13]), theta + 2, x, y)
            addPoint(getDist(bytes[16], bytes[17]), theta + 3, x, y)
        line = f.readline()

fig = plt.figure()
ax = fig.gca()

Running this script against a small sample of the data collected earlier yielded the graph below. Some sections were missed, but the measurements that were captured are surprisingly accurate (plus or minus a few centimeters in most cases). Note that the measurements shown on the graph are in meters.

Graph of Neato LIDAR Data

Further Reading

For more information about the Neato LIDAR sensor, I recommend that you read the following posts:

For more information about the BeagleBone Black serial ports, see the following links. Some the information in these posts may only be applicable to certain versions of the BeagleBone Black.


  1. I tried to replicate your experiment as I’m interested in building a similar robot. I was able to communicate with the Lidar and receive the correct header (info about the Lidar), but I have problems getting valid data packets: most of the packets have 22 bytes, I get the ‘fa’ correctly, indexes are ok, but the speed and the 4 groups of data as invalid, the speed is either too low or too high. I assume that the speed may not be correct, but I tried multiple Lidar’s and various sources of 3.3V for the motor.
    Do you have any idea what I may do wrong or what else to try?
    I’m very beginner in Linux, so I may need beginner type instructions for Linux.


    1. I’m not sure how many data packets you are capturing total, but one thing that you could try is capturing more packets to see if it just needs time to get up to speed and stabilize. I initially was capturing only 100 packets, but that’s only a little over one revolution so it didn’t work well. When I captured 1000 packets and checked the data towards the end it was fine. Depending on your situation it’s possible that you might need more than that.

      If that still doesn’t work, you might need to PWM the LIDAR motor to get it to run at the correct speed. Going even further, you could write some code to adjust the PWM signal based on the speed data that the LIDAR sends over the serial connection in order to hold the RPMs steady. Just keep in mind that the PWM signal from the BeagleBone Black probably can’t drive the motor directly. I am planning to write a blog post on this topic at some point in the future.

      Note: I also get an occasional packet that doesn’t have 22 bytes. It doesn’t cause much of an issue as I just skip over those.


  2. Your first script with some modifications of my own:

    import serial

    COM_PORT = “/dev/cu.usbserial-A102GPP8” # I’m on Mac OS X
    BAUD_RATE = 115200
    HEADER_BYTE = ‘fa:’

    def main(num_data = 1000, file_name = “lidar_data.dat”):

    print(“Establishing connection to XV-11 LiDAR via ” + COM_PORT)

    lidar_serial = serial.Serial(port = COM_PORT, baudrate = BAUD_RATE, timeout = 1)

    lidar_data = list()

    count = 1
    hex_reading = ”

    while iter_counter <= num_data:

    raw_data = str()

    while hex_reading != HEADER_BYTE: # Wait for a header byte

    byte =
    hex_reading = get_hex(byte)

    raw_data += hex_reading

    byte_counter = 1 # Initialize counter

    while byte_counter < PACKET_BYTE_COUNT:

    byte =
    hex_reading = get_hex(byte)

    # Abandon this packet if you encounter another header byte too soon
    if hex_reading == HEADER_BYTE:

    raw_data += hex_reading
    byte_counter += 1

    if len(raw_data) == 3*PACKET_BYTE_COUNT:
    # This is a proper packet, use it
    print raw_data
    iter_counter += 1

    return lidar_data


Leave a Reply

Your email address will not be published. Required fields are marked *