22//
33// FILE: HX710AB.h
44// AUTHOR: Rob Tillaart
5- // VERSION: 0.2.0
5+ // VERSION: 0.2.1
66// PURPOSE: Arduino library for the HX710A and HX710B 24-Bit ADC.
77// DATE: 2024-11-08
88// URL: https://github.com/RobTillaart/HX710AB
1212
1313#include " Arduino.h"
1414
15- #define HX710AB_LIB_VERSION (F(" 0.2.0 " ))
15+ #define HX710AB_LIB_VERSION (F(" 0.2.1 " ))
1616
1717
1818// ////////////////////////////////////////////////////////////////////////////
@@ -35,7 +35,7 @@ class HX710AB
3535
3636 void begin (bool fastProcessor = false )
3737 {
38- pinMode (_dataPin, INPUT );
38+ pinMode (_dataPin, INPUT_PULLUP );
3939 pinMode (_clockPin, OUTPUT);
4040 digitalWrite (_clockPin, LOW);
4141 _fastProcessor = fastProcessor;
@@ -70,17 +70,17 @@ class HX710AB
7070 request ();
7171 while (! is_ready ()) yield ();
7272 return fetch (differential);
73- };
73+ }
7474
7575 uint32_t last_time_read ()
7676 {
7777 return _lastTimeRead;
78- };
78+ }
7979
8080 uint32_t last_value_read ()
8181 {
8282 return _value;
83- };
83+ }
8484
8585 // //////////////////////////////////////////////////
8686 //
@@ -95,15 +95,15 @@ class HX710AB
9595 }
9696 x /= n;
9797 return (x - _offset) * _scale;
98- };
98+ }
9999
100100
101101 // //////////////////////////////////////////////////
102102 //
103103 // TWO POINT CALIBRATION
104104 //
105105 // keep offset scale "compatible" with HX711 library.
106- //
106+ //
107107 bool calibrate (int32_t x1, float y1, int32_t x2, float y2)
108108 {
109109 if ((x1 == x2) || (y2 == y1)) return false ;
@@ -115,24 +115,24 @@ class HX710AB
115115 void set_offset (float offset)
116116 {
117117 _offset = offset;
118- };
118+ }
119119
120120 float get_offset ()
121121 {
122122 return _offset;
123- };
123+ }
124124
125125 bool set_scale (float scale)
126126 {
127127 if (scale == 0 ) return false ;
128128 _scale = 1.0 / scale;
129129 return true ;
130- };
130+ }
131131
132132 float get_scale ()
133133 {
134134 return 1.0 / _scale;
135- };
135+ }
136136
137137
138138 // /////////////////////////////////////////////
@@ -142,12 +142,12 @@ class HX710AB
142142 void power_down ()
143143 {
144144 digitalWrite (_clockPin, HIGH);
145- };
145+ }
146146
147147 void power_up ()
148148 {
149149 digitalWrite (_clockPin, LOW);
150- };
150+ }
151151
152152
153153protected:
@@ -157,7 +157,7 @@ class HX710AB
157157 if (_fastProcessor) delayMicroseconds (1 );
158158 digitalWrite (_clockPin, LOW);
159159 if (_fastProcessor) delayMicroseconds (1 );
160- };
160+ }
161161
162162 uint8_t _dataPin;
163163 uint8_t _clockPin;
@@ -178,7 +178,7 @@ class HX710A : public HX710AB
178178public:
179179 HX710A (uint8_t dataPin, uint8_t clockPin) : HX710AB(dataPin, clockPin)
180180 {
181- };
181+ }
182182
183183
184184 int32_t fetch (bool differential = true )
@@ -221,7 +221,7 @@ class HX710B : public HX710AB
221221public:
222222 HX710B (uint8_t dataPin, uint8_t clockPin) : HX710AB(dataPin, clockPin)
223223 {
224- };
224+ }
225225
226226
227227 int32_t fetch (bool differential = true )
@@ -249,9 +249,9 @@ class HX710B : public HX710AB
249249 // extend sign if needed
250250 if (_value & 0x800000 ) _value |= 0xFF000000 ;
251251 return _value;
252- };
252+ }
253253
254- // TODO getVOltage ()
254+ // TODO getVoltage ()
255255};
256256
257257
0 commit comments