scale
Functions
|
Factory function to initialize the Scale. |
|
Determines if a sequence of weight measurements represents a stable weight. |
Classes
|
Interface for an I2C scale sensor. |
- class Scale(address: str)[source]
Bases:
ScaleBaseInterface for an I2C scale sensor.
- I2C_ADDR
The I2C address of the scale.
- Type:
int
- REG_DATA_GET_RAM_DATA
Register address for getting raw data.
- Type:
int
- bus
The I2C bus number.
- Type:
int
- calibration
Calibration factor.
- Type:
float
- offset
Tare offset.
- Type:
float
- i2cbus
The I2C bus connection.
- Type:
smbus2.SMBus
- error
Error message if any.
- Type:
str
- error_message_timer
Timer to limit error logging frequency.
- Type:
time_utils.Timer
- alarm_timer
Timer for non-responsive alarms.
- Type:
time_utils.Timer
- tare() None[source]
Tares the scale (sets the current weight as zero).
- calibrate(weight: float) None[source]
Calibrates the scale with a known weight.
- Parameters:
weight (float) – The known weight in grams used for calibration.
- get_value(samples: int = 1, interval_s: float = 0.005) int[source]
Reads raw values from the scale.
- Parameters:
samples (int) – Number of samples to read.
interval_s (float) – Delay between samples in seconds.
- Returns:
The median of the raw values.
- Return type:
int
- get_weight() float[source]
Gets the current weight in grams.
- Returns:
The weight in grams.
- Return type:
float
- get_scale(address: str) ScaleBase[source]
Factory function to initialize the Scale.
- Parameters:
address (str) – The I2C address of the scale.
- Returns:
An initialized Scale instance or a base class on failure.
- Return type:
- real_weight_inference(weight_array, threshold) tuple[bool, float][source]
Determines if a sequence of weight measurements represents a stable weight.
- Conditions to call it a real weight:
- standard deviation of the last 5 measurements is
smaller than 10% of the threshold
- Parameters:
weight_array (list | np.ndarray) – Array of weight measurements.
threshold (float) – Threshold for stability check.
- Returns:
(True, median_weight) if stable, else (False, 0.0).
- Return type:
tuple[bool, float]