ToF Hat
The following products are supported:
Micropython Example:
1# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD 2# 3# SPDX-License-Identifier: MIT 4 5import os, sys, io 6import M5 7from M5 import * 8from hardware import * 9from hat import ToFHat 10 11 12label0 = None 13i2c0 = None 14hat_tof_0 = None 15 16 17def setup(): 18 global label0, i2c0, hat_tof_0 19 20 M5.begin() 21 label0 = Widgets.Label("label0", 39, 109, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 22 23 i2c0 = I2C(0, scl=Pin(26), sda=Pin(0), freq=100000) 24 hat_tof_0 = ToFHat(i2c0) 25 26 27def loop(): 28 global label0, i2c0, hat_tof_0 29 M5.update() 30 label0.setText(str((str((hat_tof_0.get_range())) + str("mm")))) 31 32 33if __name__ == "__main__": 34 try: 35 setup() 36 while True: 37 loop() 38 except (Exception, KeyboardInterrupt) as e: 39 try: 40 from utility import print_error_msg 41 42 print_error_msg(e) 43 except ImportError: 44 print("please update to latest firmware")
UIFLOW2 Example:
class ToFHat
Constructors
- class ToFHat(i2c: I2C, address: int = 0x29, io_timeout_ms: int = 0)
Creates an instance of the ToFHat class.
- 参数:
i2c – the I2C object.
address – the I2C address of the device. Default is 0x23.
io_timeout_ms – the timeout of I2C communication. Default is 0ms.
UIFLOW2:

ToFHat class inherits ToFUnit class, See unit.ToFUnit.Methods for more details.

