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