AIN4-20mA Unit
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 unit import AIN4_20MAUnit 10 11 12title0 = None 13label0 = None 14label1 = None 15i2c0 = None 16ain4_20ma_0 = None 17 18 19def setup(): 20 global title0, label0, label1, i2c0, ain4_20ma_0 21 22 M5.begin() 23 Widgets.fillScreen(0x222222) 24 title0 = Widgets.Title("AIN 4-20mA Unit Test", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) 25 label0 = Widgets.Label("CH1 Current:", 1, 60, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 26 label1 = Widgets.Label("CH1 ADC:", 1, 96, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 27 28 i2c0 = I2C(0, scl=Pin(33), sda=Pin(32), freq=100000) 29 ain4_20ma_0 = AIN4_20MAUnit(i2c0, 0x55) 30 ain4_20ma_0.set_cal_current(20) 31 32 33def loop(): 34 global title0, label0, label1, i2c0, ain4_20ma_0 35 M5.update() 36 label0.setText(str((str("CH1 Current:") + str((ain4_20ma_0.get_4_20ma_current_value()))))) 37 label1.setText(str((str("CH1 ADC:") + str((ain4_20ma_0.get_adc_raw16_value()))))) 38 39 40if __name__ == "__main__": 41 try: 42 setup() 43 while True: 44 loop() 45 except (Exception, KeyboardInterrupt) as e: 46 try: 47 from utility import print_error_msg 48 49 print_error_msg(e) 50 except ImportError: 51 print("please update to latest firmware")
UIFLOW2 Example:
class AIN4_20MAUnit
Constructors
Methods
- AIN4_20MAUnit.get_adc_raw_value() int
Retrieves the raw ADC value from the channel.
- 返回:
Raw ADC value as a 12-bit integer.
UIFLOW2:
- AIN4_20MAUnit.get_current_value() float
Retrieves the current value (in mA) from the channel.
- 返回:
Current value in milliamperes (mA).
UIFLOW2:
- AIN4_20MAUnit.set_cal_current(val)
Sets the calibration current for the specified channel.
- 参数:
val (int) – The calibration current value, ranging from 4 to 20 mA.
UIFLOW2:
- AIN4_20MAUnit.get_firmware_version() int
Retrieves the firmware version of the AIN 4-20mA unit.
- 返回:
Firmware version.
UIFLOW2: