Miniscale Unit
The Miniscale
class is designed for interfacing with a mini scale weight sensor, which includes a HX711 22-bit ADC. This sensor is capable of measuring weight and also includes additional functionalities like LED control and various filters.
Support the following products:
Micropython Example:
import os, sys, io
import M5
from M5 import *
import time
from unit import MiniScaleUnit
i2c = I2C(0, scl=Pin(1), sda=Pin(2), freq=400000)
scale = MiniScaleUnit(i2c)
scale.setLed(255, 0, 0)
print(miniscale.weight)
UIFLOW2 Example:
class MiniScaleUnit
Constructors
- class MiniScaleUnit(i2c0)
Create an MiniScaleUnit object.
I2C0
is I2C Port.
UIFLOW2:
Methods
- MiniScaleUnit.adc()
Gets the raw adc readout.
UIFLOW2:
- MiniScaleUnit.weight()
Gets the weight readout in grams.
UIFLOW2:
- MiniScaleUnit.button()
Gets the button state.
UIFLOW2:
- MiniScaleUnit.setLed(r, g, b)
Sets the RGB LED color.
r
: Red value (0 - 255).g
: Green value (0 - 255).b
: Blue value (0 - 255).
UIFLOW2:
- MiniScaleUnit.reset()
Resets sensor.
UIFLOW2:
- MiniScaleUnit.calibration(weight1_g, weight1_adc, weight2_g, weight2_adc)
Calibrates the MiniScale sensor.
weight1_g
: Weight1 in grams.weight1_adc
: Weight1 in ADC value.weight2_g
: Weight2 in grams.weight2_adc
: Weight2 in ADC value.
calibration steps:
Reset sensor;
Get adc, this is weight1_adc (should be zero). And weight1_g is also 0.
Put some weight on it, then get adc, this is weight2_adc. And weight2_g is weight in gram you put on it.
UIFLOW2:
- MiniScaleUnit.setLowPassFilter(enable)
Enables or disables the low pass filter.
UIFLOW2:
- MiniScaleUnit.getLowPassFilter()
Returns the status of the low pass filter (enabled or not).
UIFLOW2:
- MiniScaleUnit.setAverageFilterLevel(level)
Sets the level of the average filter.
level
: Level of the average filter (0 - 50). Larger value for smoother result but more latency
UIFLOW2:
- MiniScaleUnit.getAverageFilterLevel()
Returns the level of the average filter.
UIFLOW2:
- MiniScaleUnit.setEMAFilterAlpha(alpha)
Sets the alpha value for the EMA filter.
The EMA (Exponential Moving Average) filter is more sensitive to changes in data compared to the average filter.
alpha
: Alpha value for the EMA filter (0 - 99). Smaller value for smoother result but more latency
UIFLOW2:
- MiniScaleUnit.getEMAFilterAlpha()
Returns the alpha value for the EMA filter.
UIFLOW2: