Advertisement
silver2row

Trying Serial on a BBB w/ pyserial on Py3...

May 18th, 2021
1,134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. from serial import Serial
  2. from time import sleep
  3.  
  4. ser = serial.Serial("/dev/ttyS2", 115200, timeout = 1)
  5.  
  6. def getTFminiData(broken):
  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(0.5)
  18.  
  19. getTFminiData(2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement