Skip to main content

TFmini

GitHub PyPI - Python Version PyPI PyPI - Downloads

Install

Install using pip:

pip install -U tfmini

Usage

Reading the sensor returns the range in meters.

import time
from tfmini import TFmini

# create the sensor and give it a port and (optional) operating mode
tf = TFmini('/dev/tty.usbserial-A506BOT5', mode=TFmini.STD_MODE)

try:
    print('='*25)
    while True:
        d = tf.read()
        if d:
            print(f'Distance: {d:5}')
        else:
            print('No valid response')
        time.sleep(0.1)

except KeyboardInterrupt:
    tf.close()
    print('bye!!')
  • TFmini(port, mode=5, retry=2): the constructor takes several inputs
    • port: serial port the sensor is connected too
    • mode: either pixhawk (default) or standard mode
    • retry: how many times the driver should search the serial port for the packet header. This only applies in standard mode.
  • read(): in any mode, returns the distance in meters
  • TFmini.strength: in standard mode, each packet contains the returned IR strength level. In decimal mode, this doesn't exist and is always set to -1.

Standard (Packet) Mode

In this mode, a data packet is sent from the sensor:

packet = [0x59, 0x59, distL, distH, strL, strH, reserved, integration time, checksum]

Where the first two bytes 0x59, 0x59 are the header and each packet has a checksum to ensure the packet is valid data.

PixHawk (String) Mode

In this mode, the sensor can sometimes returns an incorrect value because the ASCII string was read wrong across the serial port. There is no error checking in this mode.

Distance:  2.96
Distance:  2.96
Distance:  96.0 <<< Error
Distance:  2.95
Distance:  2.95
Distance:  2.96

References

MIT License

Copyright (c) 2018 Kevin Walchko

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Release files for tfmini 0.3.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tfmini 0.3.2
File Size Uploaded
tfmini-0.3.2.tar.gz 5.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tfmini 0.3.2
File Interpreter ABI Platform
tfmini-0.3.2-py3-none-any.whl Python 3 none any Details

Total release size: 12.1 kB

Release files / tfmini-0.3.2.tar.gz

Download URL tfmini-0.3.2.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
a2c36e4644129ff95f935deea3a1580f998a721a3fe3f5ed71b6ef252c014ad8
BLAKE2b-256 checksum
How to use checksums
a8ebbb4d1514ed1cdcd33d25e4976992c036a6ec03e6742c3457dfecce0620cb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.6 CPython/3.9.5 Darwin/20.5.0

Release files / tfmini-0.3.2-py3-none-any.whl

Download URL tfmini-0.3.2-py3-none-any.whl
Size 6.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
981ce1bb9fd2bccb44d8dfce92f904fbccffbc4ff113df914391eb979b3d63f8
BLAKE2b-256 checksum
How to use checksums
d333de1c302c9abf051d7e25597dbb44ff6b0bf4c02305cd4c7b8e28b41bc30c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.6 CPython/3.9.5 Darwin/20.5.0

Release history Release notifications | RSS feed

This release

0.3.2 This release

2 release files

0.2.0

2 release files

0.1.3

3 release files

0.1.2

3 release files

0.1.1

3 release files

0.1.0

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page