Skip to content

Commit 6e6adfd

Browse files
committed
0.6.3 HX711
1 parent 394aab7 commit 6e6adfd

File tree

6 files changed

+89
-36
lines changed

6 files changed

+89
-36
lines changed

libraries/HX711/CHANGELOG..md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,17 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

77

8+
## [0.6.3] - 2025-09-16
9+
- fix #70, HX711 rate pin code
10+
- fix #70, add a doReset parameter to begin() to improve start up time.
11+
- update readme.md
12+
- add details about start up time (related to RATE).
13+
- add **isReady()** check in calibration
14+
- add reference to ADAfruit breakout with RATE
15+
- minor edits
16+
817
## [0.6.2] - 2025-09-06
9-
- Fix #68, add bogde to the license, to give credit for the API
18+
- fix #68, add bogde to the license, to give credit for the API
1019
- implement experimental rate support.
1120
- update keywords.txt
1221
- update readme.md

libraries/HX711/HX711.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FILE: HX711.cpp
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.6.2
4+
// VERSION: 0.6.3
55
// PURPOSE: Library for load cells for UNO
66
// URL: https://github.com/RobTillaart/HX711_MP
77
// URL: https://github.com/RobTillaart/HX711
@@ -12,13 +12,13 @@
1212

1313
HX711::HX711()
1414
{
15-
_gain = HX711_CHANNEL_A_GAIN_128;
1615
_offset = 0;
1716
_scale = 1;
17+
_gain = HX711_CHANNEL_A_GAIN_128;
1818
_lastTimeRead = 0;
19-
_price = 0;
2019
_mode = HX711_AVERAGE_MODE;
2120
_fastProcessor = false;
21+
_price = 0;
2222
}
2323

2424

@@ -27,7 +27,7 @@ HX711::~HX711()
2727
}
2828

2929

30-
void HX711::begin(uint8_t dataPin, uint8_t clockPin, bool fastProcessor )
30+
void HX711::begin(uint8_t dataPin, uint8_t clockPin, bool fastProcessor, bool doReset)
3131
{
3232
_dataPin = dataPin;
3333
_clockPin = clockPin;
@@ -37,20 +37,23 @@ void HX711::begin(uint8_t dataPin, uint8_t clockPin, bool fastProcessor )
3737
pinMode(_clockPin, OUTPUT);
3838
digitalWrite(_clockPin, LOW);
3939

40-
reset();
40+
if (doReset)
41+
{
42+
reset();
43+
}
4144
}
4245

4346

4447
void HX711::reset()
4548
{
4649
power_down();
4750
power_up();
48-
_gain = HX711_CHANNEL_A_GAIN_128;
4951
_offset = 0;
5052
_scale = 1;
53+
_gain = HX711_CHANNEL_A_GAIN_128;
5154
_lastTimeRead = 0;
52-
_price = 0;
5355
_mode = HX711_AVERAGE_MODE;
56+
_price = 0;
5457
}
5558

5659

@@ -101,10 +104,14 @@ bool HX711::wait_ready_timeout(uint32_t timeout, uint32_t ms)
101104
// digital output pin DOUT is HIGH.
102105
// Serial clock input PD_SCK should be LOW.
103106
// When DOUT goes to LOW, it indicates data is ready for retrieval.
107+
// Blocking period can be long up to 400 ms in first read() call.
104108
float HX711::read()
105109
{
106110
// this BLOCKING wait takes most time...
107-
while (digitalRead(_dataPin) == HIGH) yield();
111+
while (digitalRead(_dataPin) == HIGH)
112+
{
113+
yield();
114+
}
108115

109116
union
110117
{
@@ -414,11 +421,11 @@ void HX711::power_up()
414421

415422
///////////////////////////////////////////////////////////////
416423
//
417-
// EXPERIMENTAL
418424
// RATE PIN - works only if rate pin is exposed.
419425
//
420426
void HX711::set_rate_pin(uint8_t pin)
421427
{
428+
_ratePin = pin;
422429
pinMode(_ratePin, OUTPUT);
423430
set_rate_10SPS();
424431
}

libraries/HX711/HX711.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// FILE: HX711.h
44
// AUTHOR: Rob Tillaart
5-
// VERSION: 0.6.2
5+
// VERSION: 0.6.3
66
// PURPOSE: Library for load cells for Arduino
77
// URL: https://github.com/RobTillaart/HX711_MP
88
// URL: https://github.com/RobTillaart/HX711
@@ -15,7 +15,7 @@
1515

1616
#include "Arduino.h"
1717

18-
#define HX711_LIB_VERSION (F("0.6.2"))
18+
#define HX711_LIB_VERSION (F("0.6.3"))
1919

2020

2121
const uint8_t HX711_AVERAGE_MODE = 0x00;
@@ -43,11 +43,14 @@ class HX711
4343
~HX711();
4444

4545
// fixed gain 128 for now
46-
void begin(uint8_t dataPin, uint8_t clockPin, bool fastProcessor = false);
46+
void begin(uint8_t dataPin, uint8_t clockPin,
47+
bool fastProcessor = false,
48+
bool doReset = true);
4749

4850
void reset();
4951

5052
// checks if load cell is ready to read.
53+
// use this to prevent blocking reads, esp at startup, 1st read.
5154
bool is_ready();
5255

5356
// wait until ready,
@@ -63,7 +66,8 @@ class HX711
6366
//
6467
// READ
6568
//
66-
// raw read
69+
// raw read, is blocking until device is ready to read().
70+
// this blocking period can be long up to 400 ms in first read() call.
6771
float read();
6872

6973
// get average of multiple raw reads
@@ -192,15 +196,15 @@ class HX711
192196
uint8_t _dataPin;
193197
uint8_t _clockPin;
194198

195-
uint8_t _gain;
196199
int32_t _offset;
197200
float _scale;
201+
uint8_t _gain;
198202
uint32_t _lastTimeRead;
199-
float _price;
200203
uint8_t _mode;
201204
bool _fastProcessor;
202205
uint8_t _ratePin = 255;
203206
uint8_t _rate = 10;
207+
float _price;
204208

205209
void _insertSort(float * array, uint8_t size);
206210
uint8_t _shiftIn();

libraries/HX711/README.md

Lines changed: 51 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,21 @@ in the sensor readings.
8080

8181
### 10 or 80 SPS
8282

83-
The datasheet mentions that the HX711 can run at 80 samples per second SPS.
83+
The datasheet mentions that the HX711 can run at 80 samples per second (SPS).
8484
To select this mode connect the **RATE** pin(15) of the chip to VCC (HIGH).
8585
Connecting **RATE** to GND (LOW) gives 10 SPS.
8686

87+
Having the RATE set to 10 or 80 SPS also changes the time to start up.
88+
At 10 SPS it takes 400 milliseconds, at 80 SPS it takes 50 milliseconds.
89+
8790
All breakout boards I tested have **RATE** connected to GND and offer no
8891
pin to control this from the outside.
92+
Adafruit however has a breakout board with **RATE** exposed.
93+
See https://www.adafruit.com/product/5974
94+
There might be more.
95+
96+
If you have the schema of your board you should be able to expose the **RATE**
97+
pin, e.g. by removing the pull down resistor to GND.
8998

9099
This library provide experimental means to control the **RATE**, see below.
91100

@@ -113,6 +122,9 @@ Load cells go to very high weights, this side sells them up to 200 ton.
113122
Never seen one and cannot tell if it will work with this library.
114123
- https://stekon.nl/load-cells
115124

125+
Breakout with RATE exposed by ADAfruit
126+
- https://www.adafruit.com/product/5974
127+
116128

117129
### Faulty boards
118130

@@ -123,14 +135,18 @@ Never seen one and cannot tell if it will work with this library.
123135

124136
First action is to call **begin(dataPin, clockPin)** to make connection to the **HX711**.
125137

126-
Second step is calibration for which a number of functions exist.
127-
- **tare()** measures zero point.
138+
Second step is to check **isReady()** to wait until the device is ready for measurements.
139+
140+
Next step is calibration for which a number of functions exist.
141+
- **tare()** measures the offset of the zero point.
128142
- **set_scale(factor)** set a known conversion factor e.g. from EEPROM.
129143
- **calibrate_scale(weight, times)** determines the scale factor based upon a known weight e.g. 1 Kg.
130-
The weight is typical in grams, however any unit can be used.
144+
The weight is typical in grams, however any unit can be used, depending on the
145+
load cell used.
131146

132147
Steps to take for calibration
133148
1. clear the scale.
149+
1. wait until **isReady()** returns true.
134150
1. call **tare()** to determine and set the zero weight offset.
135151
1. put a known weight on the scale.
136152
1. call **calibrate_scale(float weight)**, weight typical in grams, however any unit can be used.
@@ -149,16 +165,22 @@ Note that the units used in **calibrate_scale()** will be returned by **get_unit
149165
### Constructor
150166

151167
- **HX711()** constructor.
152-
- **~HX711()**
153-
- **void begin(uint8_t dataPin, uint8_t clockPin, bool fastProcessor = false)** sets a fixed gain 128 for now.
154-
The fastProcessor option adds a 1 uS delay for each clock half-cycle to keep the time greater than 200 nS.
155-
- **void reset()** set internal state to start condition.
156-
Since 0.3.4 reset also does a power down / up cycle.
168+
- **~HX711()** destructor.
169+
- **void begin(uint8_t dataPin, uint8_t clockPin, bool fastProcessor = false, bool doReset = true)** sets a fixed gain 128 for now.
170+
- The parameter fastProcessor adds a 1 uS delay for each clock half-cycle to keep the time greater than 200 nS.
171+
- The parameter doReset is experimental in 0.6.3.
172+
It defaults to true (== backwards compatible) causing a call to reset(), taking extra time
173+
before the device is ready to make new measurements. See reset() below.
174+
Note that not calling reset() leaves the ADC in the previous or even an undefined state,
175+
so use with care. (needs testing)
176+
- **void reset()** set internal state to the start condition.
177+
Reset() also does a power_down() / power_up() cycle.
178+
This cycle adds a delay of 400 (RATE = 10 SPS) or 50 (RATE = 80 SPS) milliseconds.
157179

158180

159181
### isReady
160182

161-
Different ways to wait for a new measurement.
183+
There are different ways to wait for a new measurement.
162184

163185
- **bool is_ready()** checks if load cell is ready to read.
164186
- **void wait_ready(uint32_t ms = 0)** wait until ready, check every ms.
@@ -168,7 +190,10 @@ Different ways to wait for a new measurement.
168190

169191
### Read
170192

171-
- **float read()** raw read.
193+
Warning: the read calls are blocking calls, which can take up to 400 ms in the first read() call.
194+
Best practice is to check with isReady() before calling read().
195+
196+
- **float read()** get a raw read.
172197
- **float read_average(uint8_t times = 10)** get average of times raw reads. times = 1 or more.
173198
- **float read_median(uint8_t times = 7)** get median of multiple raw reads.
174199
times = 3..15 - odd numbers preferred.
@@ -215,7 +240,7 @@ so the device is in a known state.
215240

216241
Warning 2: In practice it seems harder to get the channel and gain selection as reliable
217242
as the datasheet states it should be. So use with care. (feedback welcome)
218-
See discussion #27.
243+
See discussion #27 HX711.
219244

220245

221246
### Read mode
@@ -344,6 +369,10 @@ of the accuracy of the load cell.
344369
It should reset the HX711 to defaults but this is not always seen.
345370
See discussion issue #27 GitHub. Needs more testing.
346371

372+
Note: Having the RATE set to 10 or 80 SPS changes the time to start up.
373+
At 10 SPS it takes 400 milliseconds, at 80 SPS it takes 50 milliseconds.
374+
(See datasheet, Output settling time on page 3)
375+
347376

348377
### Rate
349378

@@ -480,29 +509,33 @@ See https://github.com/RobTillaart/HX711/issues/40
480509

481510
#### Must
482511

483-
- update documentation HX711
484-
- keep in sync with HX711_MP, HX710AB
512+
- update documentation
513+
- keep in sync with HX711_MP, HX710AB library.
485514

486515
#### Should
487516

488-
- test B channel explicitly.
489-
- test reset and reboot behaviours.
517+
- test
518+
- different load cells.
519+
- B channel explicitly.
520+
- test reset and reboot behaviours.
521+
- test and verify the proper working of the rate functions.
490522
- investigate read()
491523
- investigate the need of yield after interrupts
492524
- investigate blocking loop at begin => less yield() calls ?
493-
- test and verify the proper working of the rate functions.
525+
- add performance figures
494526

495527
#### Could
496528

529+
- add error handling?
497530
- optimize fastProcessor code (possible better performance)
498531
- injecting 2 micro delays is not always needed.
499532
- int flag instead of bool.
500-
- test different load cells
501533
- make enum of the MODE's
502534
- add examples
503535
- example the adding scale
504536
- void weight_clr(), void weight_add(), float weight_get() - adding scale
505537
- example for using rate functions.
538+
- investigate temperature compensation.
506539
- decide pricing keep/not => move to .cpp
507540

508541
#### Wont

libraries/HX711/library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"type": "git",
1616
"url": "https://github.com/RobTillaart/HX711"
1717
},
18-
"version": "0.6.2",
18+
"version": "0.6.3",
1919
"license": "MIT",
2020
"frameworks": "*",
2121
"platforms": "*",

libraries/HX711/library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=HX711
2-
version=0.6.2
2+
version=0.6.3
33
author=Rob Tillaart <[email protected]>
44
maintainer=Rob Tillaart <[email protected]>
55
sentence=Arduino library for HX711 load cell amplifier.

0 commit comments

Comments
 (0)