Advertisement
silver2row

Trying some no-laser LiDAR

Jul 6th, 2021
942
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. import serial
  2. from time import sleep
  3.  
  4. ser = serial.Serial("/dev/ttyS2", 115200, timeout = 1)
  5.  
  6. def getTFminiData():
  7.     while True:
  8.         count = ser.in_waiting
  9.         if count >= 9:
  10.             recv = ser.read(9)
  11.             ser.reset_input_buffer()
  12.             if recv[0] == 'Y' and recv[1] == 'Y': # 0x59 is 'Y'
  13.                 low = int(recv[2].encode('hex'), 16)
  14.                 high = int(recv[3].encode('hex'), 16)
  15.                 distance = low + high * 256
  16.                 print("This is your distance away from the Lidar: ", distance)
  17.             sleep(1)
  18.  
  19. getTFminiData()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement