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 14471

    any 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:
            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
        except Exception as e:

Log in to reply

Pycom on Twitter