HX711 Class

Here we can find the documentation for the HX711 library

HX711 public functions

HX711()

Construct a new HX711 object.

Note

The constructer can be used without any parameter. If no parameter is given it will use the standart pins set by menuconfig.

HX711(hx711_conf_t *conf_hx711)

Construct a new HX711 object with config.

If you want to setup the hx711 from programm you can use this function.

Parameters:

conf_hx711 – Config struct for hx711 modul. See hx711_conf_t.

inline ~HX711()
float getOffset()

Get the the offset of the hx711 modul.

Returns:

Return the offset value.

float getScale()

Get the scale factor value.

Returns:

Return the scale factor

void poweron()

Function to power on the hx711 controller.

void setGain(hx711_gain gain)

Set the gain for hx711.

Here you can set the gain. There are 3 option aviable. See hx711_gain for more information.

Parameters:

gain – Set the gain

void setOffset(float newoffset)

Set the offset for hx711 modul.

Parameters:

newoffset – Offset value

void setScale(float scaleFactor)

Function to set the scale factor.

This factor will be used to get right value based on which load cell is connected to the hx711

Parameters:

scaleFactor – Set the scale factor

void standby()

Function to bring the hx711 to standby mode.

void startTask()

Start background task.

void stopTask()

Stop background task.

void tare()

Function to tare the cell load.

In this function we will read the sensor for the number TARESAMPLES to get the offset. In the start of the function we will also read the load until 2 seconds to get a more accurate result.

void update()

Function to manuel trigger value read.

This function can be used to trigger the read. It will be used when no background task running. This function will trigger ::wait_ready.

bool wait_ready(unsigned long delay_ms = 1)

Function to wait until hx711 is ready for shift out data.

It will wait until PDOUT went LOW or it will be more the 10 trys. In this case ::_error will get true and it will stop to read value. In the case ::_error will get true maybe there is a problem with your wiring.

Note

Note we read the value for 10 times to get an average to have a more accurate result. When the hx711 modul is set to 10Mhz we get all second one result 10MHz/10. After some testing it resuslts that it looks like the modul i testet has about 5Mhz. So we get a result every 2 seconds.

Parameters:

delay_ms – Time wait between next call

Returns:

true

Returns:

false

float cellload

HX711 private functions

Note

Only show for complete the documentation

void init()
void _readData()

Function to shift out the value from hx711 modul.

Note

In this function we disable all interrupts to for shifting

float read_average(uint8_t times)

Helper function to get the average of load.

This function will always be called when we read the value. It will take samples of n times to get a more accurate result. It will also remove the highest and lowest value.

Parameters:

times – number of reading value

Returns:

float return the average sum of readings

uint8_t trys
gpio_num_t _pdsck
gpio_num_t _dout
int _gain
float _oload
float _scale
uint8_t raw_data[3]
gpio_config_t pdsck_conf
gpio_config_t dout_conf
float offset
int read_times
bool _error
float _loadsamples[TARESAMPLES]
bool taskrun
static void hx711Task(void *pvParameter)

Background Task for reading out hx711 value.

HX711 gain enum

Definition of the gain for hx711

enum hx711_gain

Enum for set gain to hx711 modul.

Values:

enumerator GAIN_128

gain factor 128 for channel A

enumerator GAIN_32

gain factor 32 for channel B

enumerator GAIN_64

gain factor 64 for channel A

HX711 config struct

Struct used to set the config for hx711 library

struct hx711_conf_t

Struct for configuration.

Public Members

int pin_pdsck

assign clockpin

int pin_dout

assign data out pin

uint8_t samples

set read times for average read

hx711_gain gain

set the gain

float scale

set the scale factor

HX711 defines

Here you can see the defaults defines

SCALE 491.f
OFFSET 46709.0
TARESAMPLES 20
WAIT_TIME 20