hx711

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 5, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	None    gainAndChannelCfg = 0 // channel is not used
	A128    gainAndChannelCfg = 1 // channel A, gain factor 128 - 25 pulses
	B32     gainAndChannelCfg = 2 // channel B, gain factor 32 - 26 pulses
	A64     gainAndChannelCfg = 3 // channel A, gain factor 64 - 27 pulses
	A128B32 gainAndChannelCfg = 4 // channel A@128 and channel B@32 - after first read 26 pulses, after second 25 pulses
	A64B32  gainAndChannelCfg = 5 // channel A@64 and channel B@32 - after first read 26 pulses, after second 27 pulses
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Device

type Device struct {
	// contains filtered or unexported fields
}

Device contains attributes for reading the values of HX711, a configurable ADC with a serial output to measure small differential voltages. The device is handy for load cells but can be used to read all kind of Wheatstone bridges. Therefore the usage of the phrases "mass", "weight" or "load" are prevented in this driver - "value" is used instead.

func New

func New(powerDownAndSckPin outputPinner, dataPin inputPinner, gc gainAndChannelCfg, tickSleep time.Duration) *Device

New returns a device for reading differential voltages with 2 inputs (A, B). The gain of input A can be chosen between 128 (default) and 64 - the gain of input B is always 32. The reading can be chosen between: * A@128 only * A@64 only * B@32 only * A@128 followed by B@32 * A@64 followed by B@32 setting "tickSleep" to a value bigger than 0 is needed for fast MCUs, typically 1 us is needed and the HX711 works between 0.2 and 50 us pulse wide according the data sheet - for the nRF52840 setting this to 0 leads to a pulse wide of around 1 us, which is fine, but setting it to 1 us leads to a pulse wide of 20 us, which also will work

func (*Device) Calibrate

func (d *Device) Calibrate(setValue float32, secondReading bool) error

Calibrate calculates, after a measurement of the set value is done, a factor for linear scaling the values of the subsequent measurements. The unit of the given set value define the unit of the measurement result later. Before using this function, the offset value should be obtained by calling Zero() function with no load. If the given flag is true, this is done for the second reading.

func (*Device) Configure

func (d *Device) Configure() error

Configure configures initially the MCU pins and the driver

func (*Device) OffsetAndCalibrationFactor

func (d *Device) OffsetAndCalibrationFactor(secondReading bool) (int32, float32)

OffsetAndCalibrationFactor returns linear correction values, used for reading. If the given flag is true, this values are related to the second reading.

func (*Device) SetGainAndChannel

func (d *Device) SetGainAndChannel(gc gainAndChannelCfg) error

SetGainAndChannel changes the gain and channel configuration for the next reading and reset the device

func (*Device) SetOffsetAndCalibrationFactor

func (d *Device) SetOffsetAndCalibrationFactor(offset int32, calibrationFactor float32, secondReading bool)

SetOffsetAndCalibrationFactor sets linear correction values, used for reading. If the given flag is true, this values are related to the second reading.

func (*Device) Update

func (d *Device) Update(drivers.Measurement) error

Update implements the drivers.Sensor interface

func (*Device) Values

func (d *Device) Values() (float32, float32)

Values returns both scaled values from the last successful update

func (*Device) Zero

func (d *Device) Zero(secondReading bool) error

Zero sets the offset for the reading. If the given flag is true, this is done for the second reading.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL