Industrial & Scientific

Tutorial: Raspberry Pi Lidar Visualization notes

I’ve tried matplotlib which has a very convenient polar coordinate mode,

Xiaomi lidar sensor pinout

but the output looked very wrong, so there must be a few mistakes in here:

import matplotlib.pyplot as plt
import matplotlib.animation as animation
import serial
import numpy as np
com_port = "/dev/ttyACM0"
baudrate = 115200
ser = serial.Serial(com_port, baudrate)
fig = plt.figure(figsize=(4,4))
ax = fig.add_subplot(111, projection='polar')
data = np.zeros(360)
theta = np.linspace(0,360, num=360)
l,  = ax.plot([],[])
databuffer = ""
def update(i):
    global data, databuffer
    if (ser.inWaiting()>0):
        data_str ='ascii')
        databuffer +=  data_str
        if ('A' in databuffer and 'B' in databuffer and 'C' in databuffer):
            databuffer = databuffer.split('A')[1]
            databuffer = databuffer.split('C')[0]
                (angle, distance) = databuffer.split('B')
            except Exception as e: print(e)
    l.set_data(theta, data )
    return l, 
ani = animation.FuncAnimation(fig, update, frames=360, interval=200, blit=True)

Related posts

By 2024, 1/3 of Households Will Be Mobile-only Users


Lenovo M7268 All in One Wireless Laser Printer Review


T-Mobile and OPPO Reno 5G Tested New Network In The Netherlands


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.