upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
Public Member Functions
HX711 Class Reference

API for the HX711 Analog-to-Digital Converter. More...

Detailed Description

HX711 is a precision 24-bit analog-to-digital converter (ADC) designed for weight scales and industrial control applications to interface directly with a bridge sensor. This module was tested on the Intel(R) Galileo Gen 2 board.

hx711.jpeg
#include "hx711.h"
int
main(int argc, char **argv)
{
upm::HX711 *scale = new upm::HX711(3, 2);
// 2837: value obtained via calibration
scale->setScale(2837);
scale->tare();
std::cout << scale->getUnits() << std::endl;
return 0;
}

Public Member Functions

 HX711 (uint8_t data, uint8_t sck, uint8_t gain=128)
 
 ~HX711 ()
 
unsigned long read ()
 
void setGain (uint8_t gain=128)
 
unsigned long readAverage (uint8_t times=10)
 
double getValue (uint8_t times=10)
 
float getUnits (uint8_t times=1)
 
void tare (uint8_t times=10)
 
void setScale (float scale=1.f)
 

Constructor & Destructor Documentation

HX711 ( uint8_t  data,
uint8_t  sck,
uint8_t  gain = 128 
)

HX711 constructor

Parameters
dataDefines the data pin
sckDefines the clock pin
gainDefines the gain factor Valid values are 128 or 64 for channel A; channel B works with a 32-gain factor only
~HX711 ( )

HX711 destructor

Member Function Documentation

unsigned long read ( )

Waits for the chip to be ready and returns a reading

Returns
Raw ADC reading
void setGain ( uint8_t  gain = 128)

Sets 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 factor depending on the parameter; the channel is also set to either A or B

Parameters
gainDefines the gain factor
unsigned long readAverage ( uint8_t  times = 10)

Returns an average reading

Parameters
timesDefines how many reading to do
Returns
Average reading
double getValue ( uint8_t  times = 10)

Returns (readAverage() - OFFSET)

Parameters
timesDefines how many readings to do
Returns
Current value without the tare weight
float getUnits ( uint8_t  times = 1)

Returns getValue() divided by SCALE

Parameters
timesDefines how many readings to do
Returns
Raw value divided by a value obtained via calibration
void tare ( uint8_t  times = 10)

Sets the OFFSET value for the tare weight

Parameters
timesDefines how many times to read the tare value
void setScale ( float  scale = 1.f)

Sets the SCALE value This value is used to convert the raw data to human-readable data (measurement units)

Parameters
scaleValue obtained via calibration

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