Scale
- 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
- __init__(address: str) None[source]
Initializes the Scale.
- Parameters:
address (str) – The I2C address as a hex string (e.g., “0x2A”).
Methods
__init__(address)Initializes the Scale.
calibrate(weight)Calibrates the scale with a known weight.
get_value([samples, interval_s])Reads raw values from the scale.
Gets the current weight in grams.
tare()Tares the scale (sets the current weight as zero).
Attributes
- error: str = 'Error connecting to the scale '
- 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