Skyward boardcore
Loading...
Searching...
No Matches
Boardcore::HX711 Class Reference

Load cell transducer. More...

#include <HX711.h>

Inheritance diagram for Boardcore::HX711:
Collaboration diagram for Boardcore::HX711:

Public Member Functions

 HX711 (SPIBusInterface &bus, miosix::GpioPin sckPin, SPIBusConfig config=getDefaultSPIConfig(), unsigned char sckAlternateFunction=5)
 
bool init () override
 Initialize the sensor.
 
bool selfTest () override
 Check if the sensor is working.
 
void computeScale (float value, float sample)
 Calculates the scale value such that the load cell's output matches the given value.
 
void computeScale (float value)
 Same as computeScale but uses the last sample.
 
void setScale (float scale)
 Simply changes the scale.
 
float getScale ()
 Returns the current scale.
 
void setOffset (float offset)
 Sets the offset to the given value.
 
void updateOffset (float offset)
 Updates the offset by adding it to the current offset.
 
float getOffset ()
 Return the current offset.
 
- Public Member Functions inherited from Boardcore::Sensor< HX711Data >
 Sensor ()
 
 Sensor (Sensor &&other)
 
virtual ~Sensor ()
 
void sample () override
 Sample the sensor.
 
virtual HX711Data getLastSample ()
 
- Public Member Functions inherited from Boardcore::AbstractSensor
virtual ~AbstractSensor ()
 
SensorErrors getLastError ()
 Get last error for debugging purposes. Avoid silent fails.
 

Static Public Member Functions

static SPIBusConfig getDefaultSPIConfig ()
 

Protected Member Functions

HX711Data sampleImpl () override
 Read a data sample from the sensor. In case of errors, the method should return the last available correct sample.
 

Additional Inherited Members

- Public Types inherited from Boardcore::Sensor< HX711Data >
using DataType
 
- Protected Attributes inherited from Boardcore::Sensor< HX711Data >
DataType lastSample
 
miosix::FastMutex mutex
 
- Protected Attributes inherited from Boardcore::AbstractSensor
SensorErrors lastError = SensorErrors::NO_ERRORS
 

Detailed Description

Load cell transducer.

HX711 is a precision 24-bit analog-to-digital converter (ADC) designed for weigh scales and industrial control applications to interface directly with a bridge sensor.

The input multiplexer selects either Channel A or B differential input to the low-noise programmable gain amplifier (PGA). Channel A can be programmed with a gain of 128 or 64, corresponding to a full-scale differential input voltage of ±20mV or ±40mV respectively, when a 5V supply is connected to AVDD analog power supply pin. Channel B has a fixed gain of 32. On-chip power supply regulator eliminates the need for an external supply regulator to provide analog power for the ADC and the sensor. Clock input is flexible. It can be from an external clock source, a crystal, or the on-chip oscillator that does not require any external component. On-chip power-on-reset circuitry simplifies digital interface initialization. There is no programming needed for the internal registers. All controls to the HX711 are through the pins.

Reference: https://github.com/bogde/HX711

Definition at line 54 of file HX711.h.

Constructor & Destructor Documentation

◆ HX711()

Boardcore::HX711::HX711 ( SPIBusInterface & bus,
miosix::GpioPin sckPin,
SPIBusConfig config = getDefaultSPIConfig(),
unsigned char sckAlternateFunction = 5 )

Definition at line 32 of file HX711.cpp.

Member Function Documentation

◆ computeScale() [1/2]

void Boardcore::HX711::computeScale ( float value)

Same as computeScale but uses the last sample.

Definition at line 84 of file HX711.cpp.

◆ computeScale() [2/2]

void Boardcore::HX711::computeScale ( float value,
float sample )

Calculates the scale value such that the load cell's output matches the given value.

The value is used to compute the scale coefficient in this way: scale = value / (sample - offset)

Parameters
valueValue that the load cell should read now.
sampleSensor sample used to compute the scale.

Definition at line 75 of file HX711.cpp.

◆ getDefaultSPIConfig()

SPIBusConfig Boardcore::HX711::getDefaultSPIConfig ( )
static

Definition at line 39 of file HX711.cpp.

◆ getOffset()

float Boardcore::HX711::getOffset ( )

Return the current offset.

Definition at line 94 of file HX711.cpp.

◆ getScale()

float Boardcore::HX711::getScale ( )

Returns the current scale.

Definition at line 88 of file HX711.cpp.

◆ init()

bool Boardcore::HX711::init ( )
overridevirtual

Initialize the sensor.

Returns
boolean value indicating whether the operation succeded or not

Implements Boardcore::AbstractSensor.

Definition at line 47 of file HX711.cpp.

◆ sampleImpl()

HX711Data Boardcore::HX711::sampleImpl ( )
overrideprotectedvirtual

Read a data sample from the sensor. In case of errors, the method should return the last available correct sample.

Returns
sensor data sample

Implements Boardcore::Sensor< HX711Data >.

Definition at line 51 of file HX711.cpp.

◆ selfTest()

bool Boardcore::HX711::selfTest ( )
overridevirtual

Check if the sensor is working.

Returns
boolean indicating whether the sensor is correctly working or not

Implements Boardcore::AbstractSensor.

Definition at line 49 of file HX711.cpp.

◆ setOffset()

void Boardcore::HX711::setOffset ( float offset)

Sets the offset to the given value.

Parameters
offsetOffset that will be removed from the measurement.

Definition at line 90 of file HX711.cpp.

◆ setScale()

void Boardcore::HX711::setScale ( float scale)

Simply changes the scale.

Parameters
scaleNew scale value.

Definition at line 86 of file HX711.cpp.

◆ updateOffset()

void Boardcore::HX711::updateOffset ( float offset)

Updates the offset by adding it to the current offset.

Parameters
offsetOffset that will be removed from the measurement.

Definition at line 92 of file HX711.cpp.


The documentation for this class was generated from the following files: