HX711
Driver superclass for the HX711 load cell amplifier/DAC.
Author(s): Erik Hess
Implementation Notes
Driver Subclasses
HX711_GPIO, works with all CircuitPython boards but may be subject to timing issuesHX711_PIO, uses RP2-series (ie, RP2040) PIO to provide consistent pulse timing
Hardware:
Seeed Studio Grove ADC For Load Cell (101020712)
Software and Dependencies:
Adafruit CircuitPython firmware for the supported boards: https://circuitpython.org/downloads
- class hx711.HX711(gain: int = 1, offset: int = 0, scalar: float = 1, tare: bool = False)
Provide basic driver services for the HX711 load cell amplifier/ADC
This subclass includes a GPIO bit-bang implemenation of the HX711 two-wire serial protocol using two GPIO pins, one for data and one for clock.
- Parameters:
Quickstart: Importing and using the HX711
Here is an example of using the
HX711class.First you will need to import the specific library subclass you’d like to use to access the sensor
import board from hx711.hx711_gpio import HX711_GPIO
Once this is done you can define your
DigitalInOutobjects for the pins attached to the HX711 sensor and define the sensor object.from digitalio import DigitalInOut gpio_data = DigitalInOut(board.D5) gpio_clk = DigitalInOut(board.D6) hx711 = HX711_GPIO(gpio_data, gpio_clk)
For defining the PIO subclass, you only need to use the
boardPinrather thanDigitalInOutobjects.pin_data = board.D5 pin_clk = board.D6 hx711 = HX711_PIO(pin_data, pin_clk)
After instantiation, you’ll have access to raw ADC counts.
hx711.read_raw()
These readings are a bit more useful with an offset applied, known as a “tare” operation. With this complete, future
read()operations will return the difference between the offset and the reading.hx711.tare() print(hx711.read())
This
tare()operation can be performed on instantation via kwarg as well.hx711 = HX711_GPIO(gpio_data, gpio_clk, tare=True)
To return a weight in more useful units, you can determine and set a scalar value. The appropriate scalar for your particular load cell and unit of choice can be determined by adding a known weight and running
determine_scalar(weight).hx711.determine_scalar(weight) print(hx711.scalar)
This scalar value can be applied in the future by directly setting it, like this.
hx711.scalar = new_scalar
A scalar value can be assigned at instantiation as well.
hx711 = HX711_GPIO(gpio_data, gpio_clk, scalar=new_scalar, tare=True)
Now you can read in weight values from the scale in the same units used to determine the scalar value.
hx711.read()
- determine_scalar(added_weight: float) float
Helper for determining scalar based on an object of known weight. This scalar is used for future
read()operations to return a weight value scaled to any desired unit rather than raw ADC counts.- Parameters:
added_weight (float) – Known weight of added object, in any desired units of measure.
Caution
An offset is required for a scalar to be effectively determined.
- property gain: int
Int value,
1,2, or3, representing the gain and channel to use for future ADC counts.Channel
Gain
A
128
B
32
A
64
Hint
See the HX711 datasheet for more details.
HX711_GPIO
CircuitPython GPIO driver subclass for the HX711 load cell amplifer and ADC
Author(s): Erik Hess
Implementation Notes
Software and Dependencies:
Adafruit CircuitPython firmware for the supported boards: https://circuitpython.org/downloads
- class hx711.hx711_gpio.HX711_GPIO(pin_data: digitalio.DigitalInOut, pin_clk: digitalio.DigitalInOut, *, gain: int = 1, offset: int = 0, scalar: int = 1, tare: bool = False)
HX711 driver subclass for GPIO
HX711_PIO
CircuitPython PIO driver subclass for the HX711 load cell amplifer and ADC
Author(s): Erik Hess
Implementation Notes
Hardware:
Requires RP2-series or compatible PIO capability
Software and Dependencies:
Adafruit CircuitPython firmware for the supported boards: https://circuitpython.org/downloads
Adafruit’s PIOASM library: https://github.com/adafruit/Adafruit_CircuitPython_PIOASM
- class hx711.hx711_pio.HX711_PIO(pin_data: digitalio.DigitalInOut, pin_clk: digitalio.DigitalInOut, *, gain: int = 1, offset: int = 0, scalar: int = 1, tare: bool = False, pio_freq: int = 4000000)
HX711 driver subclass for RP2-series PIO