Library to read out HX711 24-Bit Analog-to-Digital Converter (ADC) for Weigh Scales by AVIA Semiconductor. Tested with K22F with SCK pint at D13 and DT pin at D12

Dependents:   SmartCrutches

Embed: (wiki syntax)

« Back to documentation index

Hx711 Class Reference

Hx711 Class Reference

Class for communication with the HX711 24-Bit Analog-to-Digital Converter (ADC) for Weigh Scales by AVIA Semiconductor. More...

#include <Hx711.h>

Public Member Functions

 Hx711 (PinName pin_sck, PinName pin_dt, int offset, float scale, uint8_t gain=128)
 Create an Hx711 ADC object.
 Hx711 (PinName pin_sck, PinName pin_dt, uint8_t gain=128)
 Create an Hx711 ADC object with zero offset and unit scaling.
bool is_ready ()
 Check if the sensor is ready from the datasheet: When output data is not ready for retrieval, digital output pin DOUT is high.
uint32_t readRaw ()
 Waits for the chip to be ready and returns a raw int reading.
float read ()
 Obtain offset and scaled sensor output; i.e.
float convert_to_real (int val)
 Convert integer value from chip to offset and scaled real value.
void power_down ()
 Puts the chip into power down mode.
void power_up ()
 Wakes up the chip after power down mode.
void set_gain (uint8_t gain=128)
 Set the gain factor; takes effect only after a call to read() channel A can be set for a 128 or 64 gain; channel B has a fixed 32 gain depending on the parameter, the channel is also set to either A or B Ensures that gain_ = 128, 64 or 32.
uint8_t get_gain ()
 Obtain current gain.
void set_scale (float scale=1.0f)
 Set the scale factor.
float get_scale ()
 Get sensor scale factor.
void set_offset (int offset=0)
 Set the sensor offset.
int get_offset ()
 Get current sensor offset.

Detailed Description

Class for communication with the HX711 24-Bit Analog-to-Digital Converter (ADC) for Weigh Scales by AVIA Semiconductor.

This library is a port of the Arduino library at https://github.com/bogde/HX711 It works with the FRDM K22F.

Definition at line 11 of file Hx711.h.


Constructor & Destructor Documentation

Hx711 ( PinName  pin_sck,
PinName  pin_dt,
int  offset,
float  scale,
uint8_t  gain = 128 
)

Create an Hx711 ADC object.

Parameters:
pin_sckPinName of the clock pin (digital output)
pin_dtPinName of the data pin (digital input)
offsetoffset for sensor values
scalescale factor to obtain real values
gainchannel selection is made by passing the appropriate gain: 128 or 64 for channel A, 32 for channel B

Definition at line 24 of file Hx711.h.

Hx711 ( PinName  pin_sck,
PinName  pin_dt,
uint8_t  gain = 128 
)

Create an Hx711 ADC object with zero offset and unit scaling.

Parameters:
pin_sckPinName of the clock pin (digital output)
pin_dtPinName of the data pin (digital input)
gainchannel selection is made by passing the appropriate gain: 128 or 64 for channel A, 32 for channel B TODO: constructor overloading is not allowed?

Definition at line 40 of file Hx711.h.


Member Function Documentation

float convert_to_real ( int  val )

Convert integer value from chip to offset and scaled real value.

Parameters:
valinteger value
Returns:
(val - get_offset()) * get_scale()

Definition at line 80 of file Hx711.h.

uint8_t get_gain (  )

Obtain current gain.

Returns:
gain_

Definition at line 112 of file Hx711.h.

int get_offset (  )

Get current sensor offset.

Returns:
offset_

Definition at line 144 of file Hx711.h.

float get_scale (  )

Get sensor scale factor.

Returns:
scale_

Definition at line 128 of file Hx711.h.

bool is_ready (  )

Check if the sensor is ready from the datasheet: When output data is not ready for retrieval, digital output pin DOUT is high.

Serial clock input PD_SCK should be low. When DOUT goes to low, it indicates data is ready for retrieval.

Returns:
true if dt_.read() == LOW TODO: this is not ideal; the programm will hang if the chip never becomes ready...

Definition at line 57 of file Hx711.h.

void power_down (  )

Puts the chip into power down mode.

Definition at line 87 of file Hx711.h.

void power_up (  )

Wakes up the chip after power down mode.

Definition at line 95 of file Hx711.h.

float read (  )

Obtain offset and scaled sensor output; i.e.

a real value

Returns:
float

Definition at line 71 of file Hx711.h.

uint32_t readRaw (  )

Waits for the chip to be ready and returns a raw int reading.

Returns:
int sensor output value

Definition at line 21 of file Hx711.cpp.

void set_gain ( uint8_t  gain = 128 )

Set the gain factor; takes effect only after a call to read() channel A can be set for a 128 or 64 gain; channel B has a fixed 32 gain depending on the parameter, the channel is also set to either A or B Ensures that gain_ = 128, 64 or 32.

Parameters:
gain128, 64 or 32

Definition at line 4 of file Hx711.cpp.

void set_offset ( int  offset = 0 )

Set the sensor offset.

Parameters:
offsetthe desired offset

Definition at line 136 of file Hx711.h.

void set_scale ( float  scale = 1.0f )

Set the scale factor.

Parameters:
scaledesired scale

Definition at line 120 of file Hx711.h.