Simple test¶
Ensure your device works with this simple test.
examples/tfmini_simpletest.py¶
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4import time
5import board # comment this out if using pyserial
6import busio # comment this out if using pyserial
7import adafruit_tfmini
8
9# Use hardware uart
10uart = busio.UART(board.TX, board.RX)
11
12# Or, you can use pyserial on any computer
13# import serial
14# uart = serial.Serial("/dev/ttyS2", timeout=1)
15
16# Simplest use, connect with the uart bus object
17tfmini = adafruit_tfmini.TFmini(uart)
18
19# You can put in 'short' or 'long' distance mode
20tfmini.mode = adafruit_tfmini.MODE_SHORT
21print("Now in mode", tfmini.mode)
22
23while True:
24 print(
25 "Distance: %d cm (strength %d, mode %x)"
26 % (tfmini.distance, tfmini.strength, tfmini.mode)
27 )
28 time.sleep(0.1)