modelHx711Read
Extends from Modelica.Icons.Example (Icon for runnable examples).
Information
The microcontroller reads an HX711 with the MicroPython driver by Robert Hammelrath (robert-hh/hx711, hx711_gpio.py, placed unmodified next to the program hx711_read.py). The driver drives PD_SCK bit by bit and waits for each new data through an interrupt on the falling edge of DOUT: this is possible because each pin access takes 5 µs of simulated time (mcu.gpioOpTime).
The measurement chain is complete: a 1 kg mass (mass), its weight (g, weight), the 5 kg load cell body (loadCell), the gauge bridge (bridge, 1 mV/V at full load) and the converter (hx, without noise).
Expected codes: the bridge output is 1/5 of 1 mV/V, i.e. 0.2 mV/V; at gain 128, code = 0.2e-3 × 128 × 224 ≈ 429,497, and at gain 64, half of it (214,748). The program:
- reads a measurement at gain 128 (after the 400 ms settling time of the HX711);
- switches to gain 64 (
set_gain(64): 27 pulses, the gain applies to the next conversion) and reads again; - shows
128:429497 64:214748; - powers the HX711 down (
power_down():PD_SCKhigh for more than 60 µs), wakes it up 200 ms later, and reads again: the chip has restarted at gain 128, hencewakeup:429497.
To watch: the icon of hx (gain, last code, "data ready" and "power-down" lights), mcu.GP6.v (the trains of 25 or 27 pulses of 5 µs), mcu.GP7.v (the bits of the data), and the log (the print() output of the program).
Components
| Type | Name | Default | Description |
|---|---|---|---|
| MCU | mcu | scriptPath = Resources/Scripts/MCU/hx711_read.py - imports the driver hx711_gpio.py placed next to it (robert-hh, unchanged) | |
| MicroPythonMCU.Peripherals.Display | display | Codes read by the microcontroller | |
| MicroPythonMCU.Peripherals.Weighing.Hx711 | hx | Converter, without noise: the codes read are exactly predictable | |
| MicroPythonMCU.Peripherals.Weighing.WheatstoneBridge | bridge | ||
| MicroPythonMCU.Peripherals.Weighing.LoadCell | loadCell | 5 kg load cell body | |
| Modelica.Mechanics.Translational.Sources.Force | weight | The weight of the mass placed | |
| Modelica.Blocks.Math.Gain | g | Weight = mass × g | |
| Modelica.Blocks.Sources.Constant | mass | Mass placed: 1 kg | |
| Modelica.Electrical.Analog.Basic.Ground | ground |