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
Diff: Hx711.h
- Revision:
- 1:197ef68ad6de
- Parent:
- 0:5fa72cacd94b
- Child:
- 2:f118f8c456a4
--- a/Hx711.h Wed Jun 15 15:23:54 2016 +0000 +++ b/Hx711.h Thu Jun 16 07:31:43 2016 +0000 @@ -1,11 +1,6 @@ #ifndef _HX711_H_ #define _HX711_H_ -#define LSBFIRST 0 -#define MSBFIRST 1 -#define LOW 0 -#define HIGH 1 - /** * Class for communication with the HX711 24-Bit Analog-to-Digital * Converter (ADC) for Weigh Scales by AVIA Semiconductor. @@ -14,7 +9,9 @@ * It works with the FRDM K22F. */ class Hx711 { + public: + /** * Create an Hx711 ADC object * @param pin_sck PinName of the clock pin (digital output) @@ -33,11 +30,12 @@ } /** - * Create an Hx711 ADC object with zero offset and scaling + * Create an Hx711 ADC object with zero offset and unit scaling * @param pin_sck PinName of the clock pin (digital output) * @param pin_dt PinName of the data pin (digital input) * @param gain channel selection is made by passing the appropriate gain: * 128 or 64 for channel A, 32 for channel B + * TODO: constructor overloading is not allowed? */ Hx711(PinName pin_sck, PinName pin_dt, uint8_t gain = 128) : sck_(pin_sck), @@ -53,6 +51,8 @@ * 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. * @return true if dt_.read() == LOW + * TODO: this is not ideal; the programm will hang if the chip never + * becomes ready... */ bool is_ready() { return dt_.read() == LOW; @@ -136,12 +136,18 @@ private: + + static const uint8_t LSBFIRST = 0; // least significant bit first + static const uint8_t MSBFIRST = 1; // most significant bit first + static const uint8_t LOW = 0; // digital low + static const uint8_t HIGH = 1; // digital high + DigitalOut sck_; // clock line DigitalIn dt_; // data line uint8_t gain_; // amplification factor at chip - int offset_; // zet zero - float scale_; // scale output + int offset_; // offset chip value + float scale_; // scale output after offset /** * Port of the Arduino shiftIn function; shifts a byte one bit at a time