Title: Trouble Getting Data from USB-Connected Lidar on Raspberry Pi
Hi everyone,
I’m currently trying to retrieve data from a Lidar device connected to my Raspberry Pi via USB. My goal is to detect obstacles, but I’ve encountered difficulties as the Lidar doesn’t seem to send any data. I’ve tried various programs and GitHub examples without success.
Here’s my latest attempt using Python and serial to read data from the Lidar:
python
Copy code
import time
import serial
print(‘Starting Lidar data retrieval’)
Open serial port for communication with the Lidar
ser = serial.Serial(port=’/dev/ttyUSB0′, baudrate=115200, parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, timeout=1)
while True:
# Read a line of data from the serial port and decode it as UTF-8
raw_data = ser.readline().decode(“utf_8″).rstrip(‘nr’)
print(f”Raw data: {raw_data}”)
# Add further processing logic here based on the received data
# For example, convert the data to float and perform obstacle detection
# Uncomment below lines to implement further logic
# try:
# y = float(raw_data)
# print(y)
# if y > 3:
# print("Obstacle detected! Too far!")
# except ValueError:
# print("Error: Received data is not a valid float")
# Add a small delay to control the rate of data retrieval
# time.sleep(0.1)
However, when running this program, I only see “Raw data:” printed in the terminal, and no actual data from the Lidar. I’m seeking guidance on how to properly configure the serial communication or troubleshoot this issue.
Any help or suggestions would be greatly appreciated! Thank you.
Thomas D is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.