Simple test
Ensure your device works with this simple test.
examples/rplidar_simpletest.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2#
3# SPDX-License-Identifier: MIT
4
5from math import floor
6
7from adafruit_rplidar import RPLidar
8
9# Setup the RPLidar
10PORT_NAME = "/dev/ttyUSB0"
11lidar = RPLidar(None, PORT_NAME, timeout=3)
12
13# used to scale data to fit on the screen
14max_distance = 0
15
16
17def process_data(data):
18 print(data)
19
20
21scan_data = [0] * 360
22
23try:
24 # print(lidar.get_info())
25 for scan in lidar.iter_scans():
26 for _, angle, distance in scan:
27 scan_data[min([359, floor(angle)])] = distance
28 process_data(scan_data)
29
30except KeyboardInterrupt:
31 print("Stopping.")
32lidar.stop()
33lidar.disconnect()