Manuel Caballero / HX711

Dependents:   EXPO_ANDA EXPO_ANDA_Copilotoco

Embed: (wiki syntax)

« Back to documentation index

HX711 Class Reference

HX711 Class Reference

Example: More...

#include <HX711.h>

Public Types

enum  HX711_channel_gain_t { CHANNEL_A_GAIN_128 = 0, CHANNEL_B_GAIN_32 = 1, CHANNEL_A_GAIN_64 = 2 }
 

CHANNELS & GAIN.

More...
enum  HX711_data_output_status_t { HX711_DATA_BUSY = 0, HX711_DATA_READY = 1 }
 

READY/BUSY DATA.

More...
enum  HX711_scale_t { HX711_SCALE_kg = 0, HX711_SCALE_g = 1, HX711_SCALE_mg = 2, HX711_SCALE_ug = 3 }
 

SCALE.

More...

Public Member Functions

 HX711 (PinName PD_SCK, PinName DOUT)
 Create an HX711 object connected to the specified pins.
 ~HX711 ()
 Delete HX711 object.
HX711_status_t HX711_Reset (void)
 It performs an internal reset.
HX711_status_t HX711_PowerDown (void)
 It puts the device into power-down mode.
HX711_status_t HX711_SetChannelAndGain (HX711_channel_gain_t myChannel_Gain)
 It sets both the channel and the gain for the next measurement.
HX711_channel_gain_t HX711_GetChannelAndGain (void)
 It gets both the channel and the gain for the current measurement.
HX711_status_t HX711_ReadRawData (HX711_channel_gain_t myChannel_Gain, Vector_count_t *myNewRawData, uint32_t myAverage)
 It reads raw data from the device.
HX711_status_t HX711_ReadData_WithCalibratedMass (HX711_channel_gain_t myChannel_Gain, Vector_count_t *myNewRawData, uint32_t myAverage)
 It reads raw data with an user-specified calibrated mass.
HX711_status_t HX711_ReadData_WithoutMass (HX711_channel_gain_t myChannel_Gain, Vector_count_t *myNewRawData, uint32_t myAverage)
 It reads raw data without any mass.
HX711_status_t HX711_SetAutoTare (HX711_channel_gain_t myChannel_Gain, float myCalibratedMass, HX711_scale_t myScaleCalibratedMass, Vector_count_t *myNewRawData, float myTime)
 It reads raw data without any mass after the system is calibrated.
Vector_count_t HX711_SetManualTare (float myTareWeight)
 It sets a tare weight manually.
Vector_mass_t HX711_CalculateMass (Vector_count_t *myNewRawData, float myCalibratedMass, HX711_scale_t myScaleCalibratedMass)
 It calculates scaled data.
Vector_voltage_t HX711_CalculateVoltage (Vector_count_t *myNewRawData, float myVoltageReference)
 It calculates voltage data.

Detailed Description

Example:

include "mbed.h" include "HX711.h"

HX711 myWeightSensor ( p5, p6 ); Serial pc ( USBTX, USBRX );

Ticker newReading; DigitalOut myled1 ( LED1 ); DigitalOut myled2 ( LED2 ); DigitalOut myled3 ( LED3 ); DigitalOut myled4 ( LED4 );

HX711::HX711_status_t aux; HX711::Vector_count_t myData; HX711::Vector_mass_t myCalculatedMass; HX711::Vector_voltage_t myCalculatedVoltage;

void readDATA ( void ) { myled4 = 1;

aux = myWeightSensor.HX711_ReadRawData ( HX711::CHANNEL_A_GAIN_128, &myData, 4 ); myCalculatedMass = myWeightSensor.HX711_CalculateMass ( &myData, 1.0, HX711::HX711_SCALE_kg ); myCalculatedVoltage = myWeightSensor.HX711_CalculateVoltage ( &myData, 5.0 );

pc.printf( "Raw Data: %ld Mass: %0.5f kg Voltage: %0.5f mV\r\n", (uint32_t)myData.myRawValue, myCalculatedMass.myMass, 1000*myCalculatedVoltage.myVoltage );

myled4 = 0; }

int main() { pc.baud ( 115200 );

Reset and wake the device up aux = myWeightSensor.HX711_PowerDown (); aux = myWeightSensor.HX711_Reset (); wait(1);

CALIBRATION time start! 1. REMOVE THE MASS ON THE LOAD CELL ( ALL LEDs OFF ). Read data without any mass on the load cell aux = myWeightSensor.HX711_ReadData_WithoutMass ( HX711::CHANNEL_A_GAIN_128, &myData, 4 );

myled1 = 1; wait(3);

2. PUT A KNOWN MASS ON THE LOAD CELL ( JUST LED1 ON ). Read data with an user-specified calibration mass aux = myWeightSensor.HX711_ReadData_WithCalibratedMass ( HX711::CHANNEL_A_GAIN_128, &myData, 4 ); CALIBRATION time end!

[ OPTIONAL ] REMOVE THE MASS ON THE LOAD CELL ( JUST LED2 ON ). Read the device without any mass to calculate the tare weight for 5 seconds myled1 = 0; myled2 = 1; wait(3); myled2 = 0;

Calculating the tare weight ( JUST LED3 ON ) myled3 = 1; aux = myWeightSensor.HX711_SetAutoTare ( HX711::CHANNEL_A_GAIN_128, 1.0, HX711::HX711_SCALE_kg, &myData, 5 ); myled3 = 0;

newReading.attach( &readDATA, 0.5 ); // the address of the function to be attached ( readDATA ) and the interval ( 0.5s ) ( JUST LED4 BLINKING )

Let the callbacks take care of everything while(1) { sleep(); } }

Library for the HX711 24-Bit Analog-to-Digital Converter (ADC) for Weigh Scales.

Definition at line 108 of file HX711.h.


Member Enumeration Documentation

CHANNELS & GAIN.

Enumerator:
CHANNEL_A_GAIN_128 

Channel A 128 Gain.

CHANNEL_B_GAIN_32 

Channel B 32 Gain.

CHANNEL_A_GAIN_64 

Channel A 64 Gain.

Definition at line 114 of file HX711.h.

READY/BUSY DATA.

Enumerator:
HX711_DATA_BUSY 

HX711 data is NOT ready to be read.

HX711_DATA_READY 

HX711 data is ready to be read.

Definition at line 125 of file HX711.h.

SCALE.

Enumerator:
HX711_SCALE_kg 

HX711 Scale in kg.

HX711_SCALE_g 

HX711 Scale in g.

HX711_SCALE_mg 

HX711 Scale in mg.

HX711_SCALE_ug 

HX711 Scale in ug.

Definition at line 135 of file HX711.h.


Constructor & Destructor Documentation

HX711 ( PinName  PD_SCK,
PinName  DOUT 
)

Create an HX711 object connected to the specified pins.

HX711.h.

Parameters:
pd_sckHX711 Power down control (high active) and serial clock input
doutHX711 Serial data output

24-Bit Analog-to-Digital Converter (ADC) for Weigh Scales. Function file.

Returns:
NA
Author:
Manuel Caballero
Date:
11/September/2017
Version:
11/September/2017 The ORIGIN
Precondition:
NaN.
Warning:
NaN
Precondition:
This code belongs to Nimbus Centre ( http://www.nimbus.cit.ie ).

Definition at line 20 of file HX711.cpp.

~HX711 (  )

Delete HX711 object.

Definition at line 28 of file HX711.cpp.


Member Function Documentation

HX711::Vector_mass_t HX711_CalculateMass ( Vector_count_t *  myNewRawData,
float  myCalibratedMass,
HX711_scale_t  myScaleCalibratedMass 
)

It calculates scaled data.

HX711_CalculateMass ( Vector_count_t* myNewRawData, uint32_t myCalibratedMass, HX711_scale_t myScaleCalibratedMass )

It calculates the mass.

Parameters:
[in]myNewRawData,:It has myRawValue_WithCalibratedMass ( ADC code taken with calibrated mass ), myRawValue_WithoutCalibratedMass ( ADC code taken without any mass ) and myRawValue ( the current data taken by the system ).
[in]myCalibratedMass,:A known value for the calibrated mass when myRawValue_WithCalibratedMass was calculated.
[in]myScaleCalibratedMass,:The range of the calibrated mass ( kg, g, mg or ug ).
[out]NaN.
Returns:
The calculated mass.
Author:
Manuel Caballero
Date:
12/September/2017
Version:
13/September/2017 Adapt the scale was fixed, myFactor now works as expected. 12/September/2017 The ORIGIN
Precondition:
NaN.
Warning:
NaN.

Definition at line 431 of file HX711.cpp.

HX711::Vector_voltage_t HX711_CalculateVoltage ( Vector_count_t *  myNewRawData,
float  myVoltageReference 
)

It calculates voltage data.

HX711_CalculateVoltage ( Vector_count_t* ,float )

It calculates the mass.

Parameters:
[in]myChannel_Gain,:Gain/Channel of the measurement.
[in]myNewRawData,:myRawValue ( the current data taken by the system ).
[in]myVoltageReference,:The voltage at the converter reference input.
[out]NaN.
Returns:
The calculated voltage.
Author:
Manuel Caballero
Date:
12/September/2017
Version:
12/September/2017 The ORIGIN
Precondition:
NaN.
Warning:
NaN.

Definition at line 609 of file HX711.cpp.

HX711::HX711_channel_gain_t HX711_GetChannelAndGain ( void   )

It gets both the channel and the gain for the current measurement.

HX711_GetChannelAndGain ( void )

It gets both the channel and the gain for the current measurement.

Parameters:
[in]NaN.
[out]NaN.
Returns:
Channel and Gain.
Author:
Manuel Caballero
Date:
12/September/2017
Version:
12/September/2017 The ORIGIN
Precondition:
NaN.
Warning:
NaN.

Definition at line 201 of file HX711.cpp.

HX711::HX711_status_t HX711_PowerDown ( void   )

It puts the device into power-down mode.

HX711_PowerDown ( void )

It puts the device in power-down mode.

Parameters:
[in]NaN.
[out]NaN.
Returns:
Status of HX711_PowerDown.
Author:
Manuel Caballero
Date:
11/September/2017
Version:
11/September/2017 The ORIGIN
Precondition:
When PD_SCK pin changes from low to high and stays at high for longer than 60μs, HX711 enters power down mode.
Warning:
NaN.

Definition at line 93 of file HX711.cpp.

HX711::HX711_status_t HX711_ReadData_WithCalibratedMass ( HX711_channel_gain_t  myChannel_Gain,
Vector_count_t *  myNewRawData,
uint32_t  myAverage 
)

It reads raw data with an user-specified calibrated mass.

HX711_ReadData_WithCalibratedMass ( HX711_channel_gain_t myChannel_Gain, Vector_count_t* myNewRawData, uint32_t myAverage )

It reads data with a calibrated mass on the load cell.

Parameters:
[in]myChannel_Gain,:Gain/Channel to perform the new measurement.
[in]myAverage,:How many data to read.
[out]myNewRawData,:myRawValue_WithCalibratedMass ( ADC code taken with calibrated mass ).
Returns:
Status of HX711_ReadData_WithCalibratedMass.
Author:
Manuel Caballero
Date:
12/September/2017
Version:
12/September/2017 The ORIGIN
Precondition:
NaN.
Warning:
NaN.

Definition at line 344 of file HX711.cpp.

HX711::HX711_status_t HX711_ReadData_WithoutMass ( HX711_channel_gain_t  myChannel_Gain,
Vector_count_t *  myNewRawData,
uint32_t  myAverage 
)

It reads raw data without any mass.

HX711_ReadData_WithoutMass ( HX711_channel_gain_t myChannel_Gain, Vector_count_t* myNewRawData, uint32_t myAverage )

It reads data without any mass on the load cell.

Parameters:
[in]myChannel_Gain,:Gain/Channel to perform the new measurement.
[in]myAverage,:How many data to read.
[out]myNewRawData,:myRawValue_WithoutCalibratedMass ( ADC code taken without any mass ).
Returns:
Status of HX711_ReadData_WithoutMass.
Author:
Manuel Caballero
Date:
12/September/2017
Version:
12/September/2017 The ORIGIN
Precondition:
NaN.
Warning:
NaN.

Definition at line 385 of file HX711.cpp.

HX711::HX711_status_t HX711_ReadRawData ( HX711_channel_gain_t  myChannel_Gain,
Vector_count_t *  myNewRawData,
uint32_t  myAverage 
)

It reads raw data from the device.

HX711_ReadRawData ( HX711_channel_gain_t myChannel_Gain, Vector_count_t*, uint32_t )

It reads the raw data from the device according to the channel and its gain.

Parameters:
[in]myChannel_Gain,:Channel and Gain to perform the new read.
[in]myAverage,:How many measurement we have to get and deliver the average.
[out]myNewRawData,:The new value from the device.
Returns:
Status of HX711_ReadRawData.
Author:
Manuel Caballero
Date:
11/September/2017
Version:
12/September/2017 Gain mode was fixed, now it gets the value a given gain/channel. A timeout was added to avoid the microcontroller gets stuck. 11/September/2017 The ORIGIN
Precondition:
NaN.
Warning:
NaN.

Definition at line 232 of file HX711.cpp.

HX711::HX711_status_t HX711_Reset ( void   )

It performs an internal reset.

HX711_Reset ( void )

It performs an internal reset.

Parameters:
[in]NaN.
[out]NaN.
Returns:
Status of HX711_Reset.
Author:
Manuel Caballero
Date:
11/September/2017
Version:
11/September/2017 The ORIGIN
Precondition:
When PD_SCK pin changes from low to high and stays at high for longer than 60μs, HX711 enters power down mode.

When PD_SCK returns to low, chip will reset and enter normal operation mode.

Warning:
NaN.

Definition at line 57 of file HX711.cpp.

HX711::HX711_status_t HX711_SetAutoTare ( HX711_channel_gain_t  myChannel_Gain,
float  myCalibratedMass,
HX711_scale_t  myScaleCalibratedMass,
Vector_count_t *  myNewRawData,
float  myTime 
)

It reads raw data without any mass after the system is calibrated.

HX711_SetAutoTare ( HX711_channel_gain_t ,float ,HX711_scale_t ,Vector_count_t* ,float )

It reads data without any mass on the load cell after the system is calibrated to calculate the tare weight.

Parameters:
[in]myChannel_Gain,:Gain/Channel to perform the new measurement.
[in]myCalibratedMass,:A known value for the calibrated mass when myRawValue_WithCalibratedMass was calculated.
[in]myScaleCalibratedMass,:The range of the calibrated mass ( kg, g, mg or ug ).
[in]myTime,:How long the auto-set lasts.
[out]myNewRawData,:myRawValue_TareWeight ( ADC code taken without any mass ).
Returns:
Status of HX711_SetAutoTare.
Author:
Manuel Caballero
Date:
12/September/2017
Version:
12/September/2017 The ORIGIN
Precondition:
NaN.
Warning:
NaN.

Definition at line 517 of file HX711.cpp.

HX711::HX711_status_t HX711_SetChannelAndGain ( HX711_channel_gain_t  myChannel_Gain )

It sets both the channel and the gain for the next measurement.

HX711_SetChannelAndGain ( HX711_channel_gain_t myChannel_Gain )

It sets both the channel and the gain for the next measurement.

Parameters:
[in]myChannel_Gain,:Channel and Gain to perform the new measurement.
[out]NaN.
Returns:
Status of HX711_SetChannelAndGain.
Author:
Manuel Caballero
Date:
11/September/2017
Version:
11/September/2017 The ORIGIN
Precondition:
NaN.
Warning:
NaN.

Definition at line 127 of file HX711.cpp.

HX711::Vector_count_t HX711_SetManualTare ( float  myTareWeight )

It sets a tare weight manually.

HX711_SetManualTare ( float myTareWeight )

It sets a tare weight manually.

Parameters:
[in]myTareWeight,:Tare weight.
[out]NaN.
Returns:
myRawValue_TareWeight.
Author:
Manuel Caballero
Date:
12/September/2017
Version:
12/September/2017 The ORIGIN
Precondition:
NaN.
Warning:
NaN.

Definition at line 574 of file HX711.cpp.