AIN4-20mA Unit
支持以下产品:
MicroPython 应用示例
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 I2C 9from hardware import Pin 10from unit import AIN4_20MAUnit 11 12 13title0 = None 14label0 = None 15label1 = None 16i2c0 = None 17ain4_20ma_0 = None 18 19 20def setup(): 21 global title0, label0, label1, i2c0, ain4_20ma_0 22 23 M5.begin() 24 Widgets.fillScreen(0x222222) 25 title0 = Widgets.Title("AIN 4-20mA Unit Test", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) 26 label0 = Widgets.Label("CH1 Current:", 1, 60, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 27 label1 = Widgets.Label("CH1 ADC:", 1, 96, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 28 29 i2c0 = I2C(0, scl=Pin(33), sda=Pin(32), freq=100000) 30 ain4_20ma_0 = AIN4_20MAUnit(i2c0, 0x55) 31 ain4_20ma_0.set_cal_current(20) 32 33 34def loop(): 35 global title0, label0, label1, i2c0, ain4_20ma_0 36 M5.update() 37 label0.setText(str((str("CH1 Current:") + str((ain4_20ma_0.get_current_value()))))) 38 label1.setText(str((str("CH1 ADC:") + str((ain4_20ma_0.get_adc_raw_value()))))) 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")
UiFlow2 应用示例:








