modelKitchenScale
Extends from Modelica.Icons.Example (Icon for runnable examples).
Information
A complete kitchen scale, from the mass placed on the pan to the display:
load + pan (masses) → g, weight (weight: a force) → loadCell (load cell body, which deforms) → bridge (gauges: the strain unbalances the bridge, 1 mV/V at full load) → hx (HX711: amplification × 128 and 24-bit conversion) → mcu (program kitchen_scale.py) → lcd (Grove LCD RGB screen, I2C bus).
The program uses two off-the-shelf MicroPython drivers, unmodified: hx711_gpio.py (robert-hh/hx711) and driver_grove_lcd_rgb.py. It tares at start-up (the 200 g pan becomes the zero), converts the HX711 points into grams with a calibration constant (429.497 points per gram) and shows the result to the nearest gram. Only the characters that change are sent to the screen: each one costs an I2C transaction. Pressing the TARE button (GP0, interrupt on falling edge) resets the display to zero, bowl included.
Scenario:
- t = 0 to 1.1 s: start-up, tare of the empty pan ("Tare...");
- t = 2 s: a 350 g bowl is placed → "350 g";
- t = 3.5 s: TARE pressed → "Tare...", then "0 g" around 4.2 s;
- t = 4.5 to 5.5 s: 250 g of flour are poured → the display rises up to "250 g".
To watch: the icon of lcd during the animated replay; hx.code (the raw points, noise included); mcu.GP6.v and mcu.GP7.v (the HX711 frames); mcu.GP4.v/mcu.GP5.v (the I2C bus, active only when the display changes).
Lab ideas: calibrate the scale (find 429.497 points per gram again from a known mass); tune the filter of the driver (set_time_constant) and observe the trade-off between stability and speed; increase hx.noiseLsb; set hx.rate to 80 samples per second.
Components
| Type | Name | Default | Description |
|---|---|---|---|
| MCU | mcu | scriptPath = Resources/Scripts/MCU/kitchen_scale.py - imports the drivers hx711_gpio.py and driver_grove_lcd_rgb.py placed next to it | |
| MicroPythonMCU.Peripherals.I2cGroveLcdRgb | lcd | 16x2 screen with RGB backlight, carrying the pull-ups of the I2C bus | |
| MicroPythonMCU.Peripherals.Weighing.Hx711 | hx | Converter, with realistic noise (25 LSB, i.e. 0.06 g) | |
| MicroPythonMCU.Peripherals.Weighing.WheatstoneBridge | bridge | Four gauges bonded to the load cell body | |
| MicroPythonMCU.Peripherals.Weighing.LoadCell | loadCell | 5 kg load cell body | |
| Modelica.Mechanics.Translational.Sources.Force | weight | The weight of what is on the pan (pan included) | |
| Modelica.Blocks.Math.Gain | g | Weight = mass × g | |
| Modelica.Blocks.Math.Add | totalMass | Total mass on the load cell body | |
| Modelica.Blocks.Sources.Constant | pan | Pan: 200 g, always present - the tare at start-up makes them disappear | |
| Modelica.Blocks.Sources.TimeTable | load | What is placed (kg): a 350 g bowl at t = 2 s, then 250 g of flour poured between 4.5 and 5.5 s | |
| Modelica.Electrical.Analog.Sources.ConstantVoltage | vcc | 3.3 V supply of the button pull-up | |
| Modelica.Electrical.Analog.Basic.Resistor | rPull | Pull-up resistor: button released, GP0 reads 1 | |
| Modelica.Electrical.Analog.Basic.VariableConductor | button | TARE button: contact to ground (controlled conductance, no ideal switching) | |
| Modelica.Blocks.Math.BooleanToReal | contact | Pressed: 0.1 Ω; released: 1 GΩ | |
| Modelica.Blocks.Sources.BooleanTable | press | TARE pressed from t = 3.5 s to 3.7 s, bowl in place | |
| Modelica.Electrical.Analog.Basic.Ground | ground | ||
| Modelica.Electrical.Analog.Basic.Ground | groundBtn | ||
| Modelica.Electrical.Analog.Basic.Ground | groundLcd |