管压单位
这是 Tube Pressure Unit 的驱动库,用于控制压力传感器。
支持以下产品:
UiFlow2 应用示例
获取压力值
在 UiFlow2 中打开 tube_pressure_core2_example.m5f2 项目。
该示例展示管道压力单元的压力值。
UiFlow2 代码块:
示例输出:
None
MicroPython 应用示例
获取压力值
该示例展示管道压力单元的压力值。
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 unit import TubePressureUnit 9 10 11title0 = None 12label2 = None 13label0 = None 14label1 = None 15tubepressure_0 = None 16 17 18def setup(): 19 global title0, label2, label0, label1, tubepressure_0 20 21 M5.begin() 22 Widgets.fillScreen(0x222222) 23 title0 = Widgets.Title( 24 "TubePressureUnit Core2 Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18 25 ) 26 label2 = Widgets.Label("label2", 1, 159, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 27 label0 = Widgets.Label("label0", 1, 73, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 28 label1 = Widgets.Label("label1", 1, 116, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 29 30 tubepressure_0 = TubePressureUnit((36, 26)) 31 32 33def loop(): 34 global title0, label2, label0, label1, tubepressure_0 35 M5.update() 36 label0.setText(str((str("Pressure:") + str((tubepressure_0.get_pressure()))))) 37 label1.setText(str((str("ADC 12Bits Value:") + str((tubepressure_0.get_analog_value(12)))))) 38 label2.setText(str((str("Voltage:") + str((tubepressure_0.get_voltage()))))) 39 40 41if __name__ == "__main__": 42 try: 43 setup() 44 while True: 45 loop() 46 except (Exception, KeyboardInterrupt) as e: 47 try: 48 from utility import print_error_msg 49 50 print_error_msg(e) 51 except ImportError: 52 print("please update to latest firmware")
示例输出:
None
API参考
TubePressureUnit
- class unit.tube_pressure.TubePressureUnit(port)
基类:
object创建一个 TubePressureUnit 对象。
- 参数:
port (tuple) – 管道压力端口。
UiFlow2 代码块:

MicroPython 代码块:
from unit import TubePressureUnit tube_pressure_0 = TubePressureUnit((32, 26))
- get_pressure()
获取管道压力的压力值。
- 返回:
压力值。
- 返回类型:
UiFlow2 代码块:

MicroPython 代码块:
tube_pressure_0.get_pressure()
- get_voltage()
获取管压的电压值。
- 返回:
电压值。
- 返回类型:
UiFlow2 代码块:

MicroPython 代码块:
tube_pressure_0.get_voltage()


