|Since||Origin / Contributor||Maintainer||Source|
|2015-10-09||Chris Takahashi||Chris Takahashi||hx711.c|
|2019-04-20||Philip Gladstone||Philip Gladstone|
This module provides access to an HX711 load cell amplifier/ADC. The HX711 is an inexpensive 24bit ADC with programmable 128x, 64x, and 32x gain. The standard Chinese sources have cheap HX711 boards for around $1.
This can be used for single shot reads, or repetitive reads.
Note: To save ROM image space, this module is not compiled into the firmware by default.
Initialize io pins for hx711 clock and data.
clkpin the hx711 clock signal is connected to
datapin the hx711 data signal is connected to
-- Initialize the hx711 with clk on pin 5 and data on pin 6 hx711.init(5,6)
Read digital loadcell ADC value.
modeADC mode. This parameter specifies which input and the gain to apply to that input. Reading in mode 1 or 2 takes longer than reading in mode 0.
a number (24 bit signed ADC value extended to the machine int size)
-- Read ch A with 128 gain. raw_data = hx711.read(0)
Starts to read multiple samples from the ADC.
hx711.start(mode, samples, callback)
modeADC mode. This parameter is currently ignored and reserved to ensure backward compatibility if support for additional modes is added.
samplesThe number of samples before the callback is invoked. The length of time depends on the chip's sampling rate.
callbackThe callback is invoked with three arguments (see below).
This is invoked every time
samples samples are read from the HX711. The arguments are:
- A string which contains
samplespacked 24 bit values. This can be unpacked with the
structmodule (using the "i3" format).
- The time in microseconds of the reception of the last sample in the buffer.
- The number of samples dropped before the start of this buffer (after the end of the previous buffer).
This api only is built if GPIO_INTERRUPT_ENABLE and GPIO_INTERRUPT_HOOK_ENABLE are defined in the
user_config.h. This is the default.
Also, do not try and mix calls to
start and calls to
read. Any calls to
read will implicitly call
-- Read ch A with 128 gain. hx711.start(0, 2, function(s, t, d) local r1, r2, _ = struct.unpack("i3 i3", s) print(r1, r2) end)
Stops a previously started set of reads. Any data in buffers is lost. No more callbacks will be invoked.