TF mini sensor slow uart readings
-
HI all,
i am playing with a TF mini distance sensor thru uart.
just grabbed the example code from git for pyboard and just changed to pycom uart.
i have to play with the time.sleep or it just wont read the packets properly.
i played with different time.sleeps and found 20ms seems to work the best but the readings have a delay.
some times 1 or 2 seconds in between sometime 5-10 secs.when i trying with the Benewake windows app plugged into the sensor the readings are fast and update pretty much instantly. I also trying with python on windows and and it also seems to be fairly good.
when i print the uart.recv this is an example data coming in b'\xe8\t\xffYY\xa7\x00\x828'when the reads are good this the data b'YY\xa7\x00\x878\xe8\t\t'
which prints distance in cm and signal strength 167 14471any ideas on how to get more accurate readings in pycom in decent update speeds?
import time, utime from network import WLAN import os import time import sys, machine, gc, utime, struct from machine import Pin, I2C import json #from microWebSrv import MicroWebSrv import pycom #import rf uart = UART(1, 115200, pins=('P10','P20'),timeout_chars=1) while True: try: time.sleep_ms(25) recv = uart.read(9) print(recv) if len(recv) == 9: if recv[0] == 0x59 and recv[1] == 0x59: checksum = 0 for i in range(0, 8): checksum = checksum + recv[i] #print (checksum) checksum = checksum % 256 if checksum == recv[8]: distance = recv[2] + recv[3] * 256 strength = recv[4] + recv[5] * 256 print(distance,strength) except Exception as e: print(e)```
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login