Mini ToF-90° Unit
这是 Mini ToF-90° Unit 的驱动库,用于从距离传感器获取数据。
支持以下产品:
UiFlow2 应用示例
获取距离值
在 UiFlow2 中打开 tof90_core2_example.m5f2 项目。
该示例获取 Mini ToF-90° Unit 的距离值,并将其显示在屏幕上。
UiFlow2 代码块:
示例输出:
None
MicroPython 应用示例
获取距离值
该示例获取 Mini ToF-90° Unit 的距离值,并将其显示在屏幕上。
MicroPython 代码块:
1# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 2# 3# SPDX-License-Identifier: MIT 4 5import os, sys, io 6import M5 7from M5 import * 8from hardware import I2C 9from hardware import Pin 10from unit import ToF90Unit 11 12 13title0 = None 14label0 = None 15label1 = None 16i2c0 = None 17minitof90_0 = None 18 19 20def setup(): 21 global title0, label0, label1, i2c0, minitof90_0 22 23 M5.begin() 24 Widgets.fillScreen(0x222222) 25 title0 = Widgets.Title( 26 "Core2 Mini ToF-90 Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18 27 ) 28 label0 = Widgets.Label("label0", 2, 110, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 29 label1 = Widgets.Label("label1", -85, 149, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 30 31 i2c0 = I2C(0, scl=Pin(33), sda=Pin(32), freq=100000) 32 minitof90_0 = ToF90Unit(i2c0, 0x29) 33 minitof90_0.start_continuous() 34 35 36def loop(): 37 global title0, label0, label1, i2c0, minitof90_0 38 M5.update() 39 if minitof90_0.get_data_ready(): 40 label0.setText(str((str("Distance:") + str((str((minitof90_0.get_range())) + str("mm")))))) 41 42 43if __name__ == "__main__": 44 try: 45 setup() 46 while True: 47 loop() 48 except (Exception, KeyboardInterrupt) as e: 49 try: 50 from utility import print_error_msg 51 52 print_error_msg(e) 53 except ImportError: 54 print("please update to latest firmware")
示例输出:
None
API参考
ToF90Unit
VL53L0X
- class driver.vl53l0x.VL53L0X(i2c, address=41, io_timeout_ms=0)
基类:
object创建一个 VL53L0X 对象。
- 参数:
MicroPython 代码块:
from driver import VL53L0X i2c0 = I2C(0, scl=Pin(1), sda=Pin(2), freq=100000) vl53l0x_0 = VL53L0X(i2c0)
- get_measurement_timing_budget()
获取以微秒为单位的测量时序预算。
- 返回:
测量时序预算(以微秒为单位)。
- 返回类型:
UiFlow2 代码块:

MicroPython 代码块:
budget_ms = vl53l0x_0.get_measurement_timing_budget()
- set_measurement_timing_budget(budget_us)
设置测量时序预算,单位为微秒。
- 参数:
budget_us (int) – 测量时序预算(单位:微秒,范围 20000 - 200000)。
- 返回类型:
None
UiFlow2 代码块:

MicroPython 代码块:
budget_ms = vl53l0x_0.get_measurement_timing_budget()
- get_distance()
对传感器前方的物体执行一次测距,并以厘米为单位返回距离。
- 返回:
以厘米为单位的距离。
- 返回类型:
MicroPython 代码块:
distance = vl53l0x_0.get_distance()
- get_range()
对传感器前方的物体执行一次测距,并返回以毫米为单位的距离。
- 返回:
以毫米为单位的距离。
- 返回类型:
UiFlow2 代码块:

MicroPython 代码块:
distance = vl53l0x_0.get_range()
- get_data_ready()
获取传感器的数据就绪状态。
- 返回:
传感器的数据就绪状态。
- 返回类型:
UiFlow2 代码块:

MicroPython 代码块:
data_ready = vl53l0x_0.get_data_ready()
- is_continuous_mode()
获取传感器的连续模式状态。
- 返回:
传感器的连续模式状态。
- 返回类型:
UiFlow2 代码块:

MicroPython 代码块:
continuous_mode = vl53l0x_0.is_continuous_mode()
- start_continuous()
将传感器设置为连续模式。
UiFlow2 代码块:

MicroPython 代码块:
vl53l0x_0.start_continuous()
- 返回类型:
None
- stop_continuous()
将传感器设置为单次测距模式。
UiFlow2 代码块:

MicroPython 代码块:
vl53l0x_0.stop_continuous()
- 返回类型:
None



