重量 I2C Unit
Weight I2C Unit 是一款称重采集变送器单元,采用 “STM32+HX711 chip” 方案,通过 I2C 通信实现 24-bit 精度的重量测量,且不包含称重传感器(load cell sensor)。该单元能够测量重量,并且还包含多种滤波器。
支持以下产品:
MicroPython 应用示例
import os, sys, io
import M5
from M5 import *
from hardware import *
from unit import WeightI2CUnit
import time
i2c0 = I2C(0, scl=Pin(1), sda=Pin(2), freq=100000)
weight_i2c_0 = WeightI2CUnit(i2c0)
print(weight_i2c_0.get_adc_raw)
print(weight_i2c_0.get_weight_float)
time.sleep_ms(100)
UiFlow2 应用示例
class WeightI2CUnit
Constructors
Import with from unit import WeightI2CUnit.
- class WeightI2CUnit(i2c, address=0x26)
Create an WeightI2CUnit object.
i2cis an initialized I2C bus or PAHUB port.0x26是默认 I2C 地址
UiFlow2

Methods
- WeightI2CUnit.get_adc_raw
获取原始 ADC 值。
UiFlow2

- WeightI2CUnit.get_weight_float
获取以克为单位的重量浮点值。
UiFlow2

- WeightI2CUnit.get_weight_int
获取以克为单位的重量整数值。
UiFlow2

- WeightI2CUnit.get_weight_str
获取以克为单位的重量字符串值。
UiFlow2

- WeightI2CUnit.set_reset_offset()
重置偏移值(去皮)。
UiFlow2

- WeightI2CUnit.set_calibration(weight1_g, weight1_adc, weight2_g, weight2_adc)
校准 Load 传感器。
weight1_g:以克为单位的 Weight1。weight1_adc:Weight1 的 ADC 值。weight2_g:Weight2 的单位为克。weight2_adc:以 ADC 值表示的 Weight2。
校准步骤:
1.Reset offset(Tare). 2.Get the raw ADC value at no-load weight, this is the Raw ADC of zero weight in 0g. 3.Put some weight on it, then get adc, this is the load weight adc value and the gram weight you put on it.
UiFlow2

- WeightI2CUnit.set_lowpass_filter(Enable)
启用或禁用低通滤波器。
UiFlow2

- WeightI2CUnit.get_lowpass_filter
返回低通滤波器的状态(启用或禁用)。
UiFlow2

- WeightI2CUnit.set_average_filter_level(level)
设置平均滤波器的级别。
level:平均滤波器的级别(0 - 50)。数值越大结果越平滑,但延迟也越高。
UiFlow2

- WeightI2CUnit.get_average_filter_level
返回平均滤波器的等级。
UiFlow2

- WeightI2CUnit.set_ema_filter_alpha(alpha)
设置 EMA 滤波器的 alpha 值。
EMA(指数移动平均)滤波器相比平均滤波器对数据变化更敏感。
alpha:EMA 滤波器的 Alpha 值(0 - 99)。值越小结果越平滑,但延迟越大
UiFlow2

- WeightI2CUnit.get_ema_filter_alpha
返回 EMA 滤波器的 alpha 值。
UiFlow2

- WeightI2CUnit.set_i2c_address(address)
i2c 地址可由用户更改,该地址应在 0x01 到 0x7F 之间。
address:地址范围(0x01 - 0x7F)。
UiFlow2

- WeightI2CUnit.get_device_spec(info)
获取该设备的固件版本详细信息以及 I2C 地址。
info:(0xFE, 0xFF)
UiFlow2


