Skip to content

Commit 5b71d47

Browse files
committed
0.3.4 HX711_MP
1 parent 6e6adfd commit 5b71d47

File tree

6 files changed

+115
-41
lines changed

6 files changed

+115
-41
lines changed

libraries/HX711_MP/CHANGELOG..md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ 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.3.4] - 2025-09-16
9+
- fix #11, HX711 rate pin code (HX711 - #70)
10+
- 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.3.3] - 2025-09-06
918
- update license
1019
- implement experimental rate support.

libraries/HX711_MP/HX711_MP.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FILE: HX711_MP.cpp
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.3.3
4+
// VERSION: 0.3.4
55
// PURPOSE: Library for load cells for UNO
66
// URL: https://github.com/RobTillaart/HX711_MP
77
// URL: https://github.com/RobTillaart/HX711
@@ -24,6 +24,7 @@ HX711_MP::HX711_MP(uint8_t size)
2424
_gain = HX711_CHANNEL_A_GAIN_128;
2525
_lastTimeRead = 0;
2626
_mode = HX711_AVERAGE_MODE;
27+
_fastProcessor = false;
2728
}
2829

2930

@@ -32,7 +33,7 @@ HX711_MP::~HX711_MP()
3233
}
3334

3435

35-
void HX711_MP::begin(uint8_t dataPin, uint8_t clockPin, bool fastProcessor )
36+
void HX711_MP::begin(uint8_t dataPin, uint8_t clockPin, bool fastProcessor, bool doReset)
3637
{
3738
_dataPin = dataPin;
3839
_clockPin = clockPin;
@@ -42,7 +43,10 @@ void HX711_MP::begin(uint8_t dataPin, uint8_t clockPin, bool fastProcessor )
4243
pinMode(_clockPin, OUTPUT);
4344
digitalWrite(_clockPin, LOW);
4445

45-
reset();
46+
if (doReset)
47+
{
48+
reset();
49+
}
4650
}
4751

4852

@@ -103,10 +107,14 @@ bool HX711_MP::wait_ready_timeout(uint32_t timeout, uint32_t ms)
103107
// digital output pin DOUT is HIGH.
104108
// Serial clock input PD_SCK should be LOW.
105109
// When DOUT goes to LOW, it indicates data is ready for retrieval.
110+
// Blocking period can be long up to 400 ms in first read() call.
106111
float HX711_MP::read()
107112
{
108113
// this BLOCKING wait takes most time...
109-
while (digitalRead(_dataPin) == HIGH) yield();
114+
while (digitalRead(_dataPin) == HIGH)
115+
{
116+
yield();
117+
}
110118

111119
union
112120
{
@@ -398,11 +406,11 @@ void HX711_MP::power_up()
398406

399407
///////////////////////////////////////////////////////////////
400408
//
401-
// EXPERIMENTAL
402409
// RATE PIN - works only if rate pin is exposed.
403410
//
404411
void HX711_MP::set_rate_pin(uint8_t pin)
405412
{
413+
_ratePin = pin;
406414
pinMode(_ratePin, OUTPUT);
407415
set_rate_10SPS();
408416
}
@@ -434,12 +442,6 @@ uint32_t HX711_MP::last_time_read()
434442
return _lastTimeRead;
435443
}
436444

437-
// obsolete future
438-
uint32_t HX711_MP::last_read()
439-
{
440-
return _lastTimeRead;
441-
}
442-
443445

444446
///////////////////////////////////////////////////////////////
445447
//
@@ -510,6 +512,5 @@ float HX711_MP::_multiMap(float val)
510512
}
511513

512514

513-
514515
// -- END OF FILE --
515516

libraries/HX711_MP/HX711_MP.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// FILE: HX711_MP.h
44
// AUTHOR: Rob Tillaart
5-
// VERSION: 0.3.3
5+
// VERSION: 0.3.4
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_MP_LIB_VERSION (F("0.3.3"))
18+
#define HX711_MP_LIB_VERSION (F("0.3.4"))
1919

2020

2121
const uint8_t HX711_AVERAGE_MODE = 0x00;
@@ -46,11 +46,14 @@ class HX711_MP
4646
~HX711_MP();
4747

4848
// fixed gain 128 for now
49-
void begin(uint8_t dataPin, uint8_t clockPin, bool fastProcessor = false);
49+
void begin(uint8_t dataPin, uint8_t clockPin,
50+
bool fastProcessor = false,
51+
bool doReset = true);
5052

5153
void reset();
5254

5355
// checks if load cell is ready to read.
56+
// use this to prevent blocking reads, esp at startup, 1st read.
5457
bool is_ready();
5558

5659
// wait until ready,
@@ -66,7 +69,8 @@ class HX711_MP
6669
//
6770
// READ
6871
//
69-
// raw read
72+
// raw read, is blocking until device is ready to read().
73+
// this blocking period can be long up to 400 ms in first read() call.
7074
float read();
7175

7276
// get average of multiple raw reads
@@ -101,11 +105,10 @@ class HX711_MP
101105
void set_runavg_mode();
102106
uint8_t get_mode();
103107

104-
105-
// primary user functions
108+
// raw reads without offset == different than HX711 library.
106109
// in HX711_RAW_MODE the parameter times will be ignored.
107110
float get_value(uint8_t times = 1);
108-
// converted to proper units.
111+
// converted to proper units, corrected for scale.
109112
// in HX711_RAW_MODE the parameter times will be ignored.
110113
float get_units(uint8_t times = 1);
111114

@@ -174,7 +177,7 @@ class HX711_MP
174177
uint32_t last_time_read();
175178
// obsolete in the future
176179
[[deprecated("Use last_time_read() instead.")]]
177-
uint32_t last_read();
180+
uint32_t last_read() { return last_time_read(); };
178181

179182

180183
///////////////////////////////////////////////////////////////

libraries/HX711_MP/README.md

Lines changed: 80 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,21 @@ If problems occur or there are questions, please open an issue at GitHub.
3838

3939
### 10 or 80 SPS
4040

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

45+
Having the RATE set to 10 or 80 SPS also changes the time to start up.
46+
At 10 SPS it takes 400 milliseconds, at 80 SPS it takes 50 milliseconds.
47+
4548
All breakout boards I tested have **RATE** connected to GND and offer no
4649
pin to control this from the outside.
50+
Adafruit however has a breakout board with **RATE** exposed.
51+
See https://www.adafruit.com/product/5974
52+
There might be more.
53+
54+
If you have the schema of your board you should be able to expose the **RATE**
55+
pin, e.g. by removing the pull down resistor to GND.
4756

4857
This library provide experimental means to control the **RATE**, see below.
4958

@@ -71,6 +80,9 @@ Load cells go to very high weights, this side sells them up to 200 ton.
7180
Never seen one and cannot tell if it will work with this library.
7281
- https://stekon.nl/load-cells
7382

83+
Breakout with RATE exposed by ADAfruit
84+
- https://www.adafruit.com/product/5974
85+
7486

7587
### Faulty boards
7688

@@ -111,17 +123,23 @@ is more math involved for converting raw data to weights.
111123
- **HX711_MP(uint8_t size)** constructor.
112124
Parameter sets the size of for the calibration arrays.
113125
Allowed range for size is 2..10.
114-
- **~HX711_MP()**
115-
- **void begin(uint8_t dataPin, uint8_t clockPin, bool fastProcessor = false)** sets a fixed gain 128 for now.
116-
The fastProcessor option adds a 1 uS delay for each clock half-cycle to keep the time greater than 200 nS.
117-
- **void reset()** set internal state to start condition.
118-
Reset also does a power down / up cycle.
119-
It does not reset the calibration data.
126+
- **~HX711_MP()** destructor.
127+
- **void begin(uint8_t dataPin, uint8_t clockPin, bool fastProcessor = false, bool doReset = true)** sets a fixed gain 128 for now.
128+
- The parameter fastProcessor adds a 1 uS delay for each clock half-cycle to keep the time greater than 200 nS.
129+
- The parameter doReset is experimental in 0.6.3.
130+
It defaults to true (== backwards compatible) causing a call to reset(), taking extra time
131+
before the device is ready to make new measurements. See reset() below.
132+
Note that not calling reset() leaves the ADC in the previous or even an undefined state,
133+
so use with care. (needs testing)
134+
- **void reset()** set internal state to the start condition.
135+
Reset() also does a power_down() / power_up() cycle.
136+
This cycle adds a delay of 400 (RATE = 10 SPS) or 50 (RATE = 80 SPS) milliseconds.
137+
Reset() does not reset the calibration data.
120138

121139

122140
### isReady
123141

124-
Different ways to wait for a new measurement.
142+
There are different ways to wait for a new measurement.
125143

126144
- **bool is_ready()** checks if load cell is ready to read.
127145
- **void wait_ready(uint32_t ms = 0)** wait until ready, check every ms.
@@ -131,7 +149,10 @@ Different ways to wait for a new measurement.
131149

132150
### Read
133151

134-
- **float read()** raw read.
152+
Warning: the read calls are blocking calls, which can take up to 400 ms in the first read() call.
153+
Best practice is to check with isReady() before calling read().
154+
155+
- **float read()** get a raw read.
135156
- **float read_average(uint8_t times = 10)** get average of times raw reads. times = 1 or more.
136157
- **float read_median(uint8_t times = 7)** get median of multiple raw reads.
137158
times = 3..15 - odd numbers preferred.
@@ -253,6 +274,10 @@ This way of calibration allows:
253274
It should reset the HX711 to defaults but this is not always seen.
254275
See discussion issue #27 GitHub. Needs more testing.
255276

277+
Note: Having the RATE set to 10 or 80 SPS changes the time to start up.
278+
At 10 SPS it takes 400 milliseconds, at 80 SPS it takes 50 milliseconds.
279+
(See datasheet, Output settling time on page 3)
280+
256281

257282
### Rate
258283

@@ -301,34 +326,70 @@ Another way to handle this is to add a good temperature sensor
301326
differences in your code.
302327

303328

304-
## Future
329+
## Multiple HX711
330+
331+
332+
### Separate lines
333+
334+
Simplest way to control multiple HX711's is to have a separate **DOUT** and **CLK**
335+
line for every HX711 connected.
336+
337+
338+
### Multiplexer
339+
340+
Alternative one could use a multiplexer like the https://github.com/RobTillaart/HC4052
341+
or possibly an https://github.com/RobTillaart/TCA9548.
342+
Although to control the multiplexer one need some extra lines and code.
343+
344+
345+
### Share CLOCK line
305346

306-
Points from HX711 are not repeated here
347+
See **HX_loadcell_array.ino**
307348

349+
Another way to control multiple HX711's is to share the **CLK** line.
350+
This has a few side effects which might be acceptable or not.
351+
352+
Known side effects - page 4 and 5 datasheet.
353+
354+
- The **CLK** is used to select channel and to select gain for the NEXT sample.
355+
- The **CLK** is used for power down.
356+
- After wake up after power down all HX711's will reset to channel A and gain 128.
357+
**WARNING:** if one of the objects does a **powerDown()** or **reset()** it resets its internal states.
358+
The other objects however won't reset their internal state, so a mismatch can occur.
359+
360+
So in short, sharing the **CLK** line causes all HX711 modules share the same state.
361+
This can introduce extra complexity if one uses mixed gains or channels.
362+
If all HX711's use the same settings it should work, however extra care is needed for
363+
**powerDown()** and **reset()**.
364+
365+
**WARNING: Sharing the data lines is NOT possible as it could cause short circuit.**
366+
367+
See https://github.com/RobTillaart/HX711/issues/40
368+
369+
370+
## Future
371+
372+
Points from HX711 are not all repeated here
308373

309374
#### Must
310375

311-
- keep in sync with HX711 library where relevant.
312376
- update documentation
377+
- keep in sync with HX711 library.
313378

314379
#### Should
315380

316-
- test a lot
317-
- different load cells.
318381
- investigate interpolation beyond calibration range.
319-
- add examples
320-
- runtime changing of the mapping.
321382
- investigate malloc/free for the mapping arrays
322-
- add performance figures
323383
- Calibration
324384
- Returns 0 is index is out of range ==> NaN ?
325-
- add rate example
326385

327386
#### Could
328387

329388
- add error handling?
330389
- HX711_INDEX_OUT_OF_RANGE
331-
- ??
390+
- add examples
391+
- runtime changing of the mapping.
392+
- example for using rate functions.
332393
- investigate temperature compensation.
333394

334395
#### Wont

libraries/HX711_MP/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_MP"
1717
},
18-
"version": "0.3.3",
18+
"version": "0.3.4",
1919
"license": "MIT",
2020
"frameworks": "*",
2121
"platforms": "*",

libraries/HX711_MP/library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=HX711_MP
2-
version=0.3.3
2+
version=0.3.4
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)