Skip to content

Commit dfed66b

Browse files
committed
0.6.0 HX711
1 parent 9e09f0e commit dfed66b

File tree

7 files changed

+111
-53
lines changed

7 files changed

+111
-53
lines changed

libraries/HX711/CHANGELOG..md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ 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.0] - 2025-04-10
9+
- fix #60, change parameter **void calibrate_scale(float weight, uint8_t times = 10)**
10+
- update readme.md
11+
12+
----
13+
814
## [0.5.2] - 2024-11-18
915
- fix #56, update readme.md
1016
- add parameter default for **fastProcessor**

libraries/HX711/HX711.cpp

Lines changed: 26 additions & 26 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.5.2
4+
// VERSION: 0.6.0
55
// PURPOSE: Library for load cells for UNO
66
// URL: https://github.com/RobTillaart/HX711_MP
77
// URL: https://github.com/RobTillaart/HX711
@@ -305,28 +305,6 @@ float HX711::get_units(uint8_t times)
305305
};
306306

307307

308-
///////////////////////////////////////////////////////
309-
//
310-
// TARE
311-
//
312-
void HX711::tare(uint8_t times)
313-
{
314-
_offset = read_average(times);
315-
}
316-
317-
318-
float HX711::get_tare()
319-
{
320-
return -_offset * _scale;
321-
}
322-
323-
324-
bool HX711::tare_set()
325-
{
326-
return _offset != 0;
327-
}
328-
329-
330308
///////////////////////////////////////////////////////////////
331309
//
332310
// GAIN
@@ -357,9 +335,31 @@ uint8_t HX711::get_gain()
357335
}
358336

359337

338+
///////////////////////////////////////////////////////
339+
//
340+
// TARE
341+
//
342+
void HX711::tare(uint8_t times)
343+
{
344+
_offset = read_average(times);
345+
}
346+
347+
348+
float HX711::get_tare()
349+
{
350+
return -_offset * _scale;
351+
}
352+
353+
354+
bool HX711::tare_set()
355+
{
356+
return _offset != 0;
357+
}
358+
359+
360360
///////////////////////////////////////////////////////////////
361361
//
362-
// CALIBRATION
362+
// CALIBRATION (tare see above)
363363
//
364364
bool HX711::set_scale(float scale)
365365
{
@@ -388,9 +388,9 @@ int32_t HX711::get_offset()
388388

389389

390390
// assumes tare() has been set.
391-
void HX711::calibrate_scale(uint16_t weight, uint8_t times)
391+
void HX711::calibrate_scale(float weight, uint8_t times)
392392
{
393-
_scale = (1.0 * weight) / (read_average(times) - _offset);
393+
_scale = weight / (read_average(times) - _offset);
394394
}
395395

396396

libraries/HX711/HX711.h

Lines changed: 12 additions & 10 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.5.2
5+
// VERSION: 0.6.0
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.5.2"))
18+
#define HX711_LIB_VERSION (F("0.6.0"))
1919

2020

2121
const uint8_t HX711_AVERAGE_MODE = 0x00;
@@ -106,13 +106,6 @@ class HX711
106106
float get_units(uint8_t times = 1);
107107

108108

109-
// TARE
110-
// call tare to calibrate zero
111-
void tare(uint8_t times = 10);
112-
float get_tare();
113-
bool tare_set();
114-
115-
116109
///////////////////////////////////////////////////////////////
117110
//
118111
// GAIN
@@ -133,6 +126,15 @@ class HX711
133126
uint8_t get_gain();
134127

135128

129+
///////////////////////////////////////////////////////////////
130+
//
131+
// TARE
132+
// call tare to calibrate zero
133+
void tare(uint8_t times = 10);
134+
float get_tare();
135+
bool tare_set();
136+
137+
136138
///////////////////////////////////////////////////////////////
137139
//
138140
// CALIBRATION
@@ -151,7 +153,7 @@ class HX711
151153
// put a known weight on the scale
152154
// call calibrate_scale(weight)
153155
// scale is calculated.
154-
void calibrate_scale(uint16_t weight, uint8_t times = 10);
156+
void calibrate_scale(float weight, uint8_t times = 10);
155157

156158

157159
///////////////////////////////////////////////////////////////

libraries/HX711/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019-2024 Rob Tillaart
3+
Copyright (c) 2019-2025 Rob Tillaart
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

libraries/HX711/README.md

Lines changed: 64 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ This library does not provide means to control the **RATE** yet.
8383
If there is a need (issue) I will implement this in the library.
8484
For now one can add an IOpin for this and use **digitalWrite()**.
8585

86+
If you need more SPS you could consider using the HX71708 device.
87+
This is a close "relative" of the HX711 that allows to set the SPS to
88+
10, 20, 80, or 320 Hz.
89+
- https://github.com/beniseman/HX71708
90+
8691

8792
### Related
8893

@@ -95,6 +100,13 @@ For now one can add an IOpin for this and use **digitalWrite()**.
95100
Discussion about resolution of the ADC
96101
- https://forum.arduino.cc/t/scale-from-50-kg-to-5000kg-what-adc/1139710
97102

103+
Support for the HX71708 device (close related)
104+
- https://github.com/beniseman/HX71708 allows to set the SPS to 10, 20, 80, or 320 Hz
105+
106+
Load cells go to very high weights, this side sells them up to 200 ton.
107+
Never seen one and cannot tell if it will work with this library.
108+
- https://stekon.nl/load-cells
109+
98110

99111
### Faulty boards
100112

@@ -108,16 +120,19 @@ First action is to call **begin(dataPin, clockPin)** to make connection to the *
108120
Second step is calibration for which a number of functions exist.
109121
- **tare()** measures zero point.
110122
- **set_scale(factor)** set a known conversion factor e.g. from EEPROM.
111-
- **calibrate_scale(WEIGHT, TIMES)** determines the scale factor based upon a known weight e.g. 1 Kg.
123+
- **calibrate_scale(weight, times)** determines the scale factor based upon a known weight e.g. 1 Kg.
124+
The weight is typical in grams, however any unit can be used.
112125

113126
Steps to take for calibration
114-
1. clear the scale
115-
1. call tare() to set the zero offset
116-
1. put a known weight on the scale
117-
1. call calibrate_scale(weight)
118-
1. scale is calculated.
127+
1. clear the scale.
128+
1. call **tare()** to determine and set the zero weight offset.
129+
1. put a known weight on the scale.
130+
1. call **calibrate_scale(float weight)**, weight typical in grams, however any unit can be used.
131+
1. scale factor is calculated.
119132
1. save the offset and scale for later use e.g. EEPROM.
120133

134+
Note that the units used in **calibrate_scale()** will be returned by **get_units()**.
135+
121136

122137
## Interface
123138

@@ -135,12 +150,18 @@ The fastProcessor option adds a 1 uS delay for each clock half-cycle to keep the
135150
Since 0.3.4 reset also does a power down / up cycle.
136151

137152

138-
### Read
153+
### isReady
154+
155+
Different ways to wait for a new measurement.
139156

140157
- **bool is_ready()** checks if load cell is ready to read.
141158
- **void wait_ready(uint32_t ms = 0)** wait until ready, check every ms.
142159
- **bool wait_ready_retry(uint8_t retries = 3, uint32_t ms = 0)** wait max retries.
143160
- **bool wait_ready_timeout(uint32_t timeout = 1000, uint32_t ms = 0)** wait max timeout milliseconds.
161+
162+
163+
### Read
164+
144165
- **float read()** raw read.
145166
- **float read_average(uint8_t times = 10)** get average of times raw reads. times = 1 or more.
146167
- **float read_median(uint8_t times = 7)** get median of multiple raw reads.
@@ -222,8 +243,10 @@ Note that in **HX711_RAW_MODE** the times parameter will be ignored => just call
222243

223244
- **float get_value(uint8_t times = 1)** read value, corrected for offset.
224245
- **float get_units(uint8_t times = 1)** read value, converted to proper units.
225-
- **bool set_scale(float scale = 1.0)** set scale factor which is normally a positive number larger than 50. Depends on load-cell used.
246+
- **bool set_scale(float scale = 1.0)** set scale factor which is normally a positive
247+
number larger than 50. Depends on load-cell used.
226248
Returns false if scale == 0.
249+
Note that for some specific applications, scale might be negative.
227250
- **float get_scale()** returns set scale factor.
228251
- **void set_offset(int32_t offset = 0)** idem.
229252
- **int32_t get_offset()** idem.
@@ -233,20 +256,41 @@ Returns false if scale == 0.
233256

234257
Steps to take for calibration
235258
1. clear the scale.
236-
1. call **tare()** to determine and set the zero offset.
259+
1. call **tare()** to determine and set the zero weight offset.
237260
1. put a known weight on the scale.
238-
1. call **calibrate_scale(weight)**.
239-
1. scale is calculated.
261+
1. call **calibrate_scale(float weight)**, weight typical in grams, however any unit can be used.
262+
1. scale factor is calculated.
240263
1. save the offset and scale for later use e.g. EEPROM.
241264

265+
Note that the units used in **calibrate_scale()** will be returned by **get_units()**.
266+
242267
- **void tare(uint8_t times = 10)** call tare to determine the offset
243268
to calibrate the zero (reference) level. See below.
244269
- **float get_tare()** returns the offset \* scale.
245270
Note this differs after calls to **calibrate_scale()**.
246271
Use **get_offset()** to get only the offset.
247272
- **bool tare_set()** checks if a tare has been set.
248273
Assumes offset is not zero, which is true for all load cells tested.
249-
- **void calibrate_scale(uint16_t weight, uint8_t times = 10)** idem.
274+
- **void calibrate_scale(float weight, uint8_t times = 10)**
275+
The calibration weight averages times measurements to improve accuracy.
276+
Weight is typical in grams, however any unit can be used.
277+
Be aware this unit will also be returned by **get_units()**.
278+
279+
Since 0.6.0 the weight is defined as float which allows easier calibration in
280+
other units e.g. define the weight as 2.5 kg instead of 2500 gram.
281+
The function **GetUnits()** will then return its value in kg too.
282+
283+
Also by using a float the range of calibration weights is substantially increased.
284+
One can now define 250 gram as 250000 milligram, where before the value was max
285+
65535 units (theoretical increase of precision from 4.8 to 6.9 digits).
286+
This allows the calibration of superheavy load cells, e.g 500 kg and use a
287+
defined weight of 100000 gram.
288+
Finally the use of floats allow the use of decimals e.g. a calibration weight
289+
of 125.014 kg or 306.4 gram.
290+
291+
Note: calibrate_scale() uses averaging and does not use the mode set.
292+
293+
Note: calibrate_scale() can have a negative value as weight e.g. force of a balloon.
250294

251295

252296
### Tare & calibration II
@@ -256,15 +300,21 @@ The function **get_tare()** is used to measure this raw value and allows the use
256300
to define this value as a zero weight (force) point.
257301
This zero point is normally without any load, however it is possible to define
258302
a zero point with a "fixed" load e.g. a cup, a dish, even a spring or whatever.
259-
This allows the system to automatically subtract the weight of the cup etc.
303+
This allows the system to automatically subtract the weight / force of the cup etc.
260304

261-
Warning: The user must be aware that the "fixed" load together with the
305+
**Warning**: The user must be aware that the "fixed" load together with the
262306
"variable" load does not exceed the specifications of the load cell.
263307

264308
E.g. a load cell which can handle 1000 grams with a cup of 300 grams should not
265309
be calibrated with a weight of more than 700 grams.
266310
In fact it is better to calibrate with a weight in the order of 80 to 90% of
267311
the maximum load so in this example a weight of 500 to 600 grams.
312+
That would make the total 800-900 grams == 80/90% of the max load.
313+
314+
Another point to consider when calibrating is to use a weight that is
315+
in the range you want to make your measurements.
316+
E.g. if you want to measure coffee beans in portions of 250 grams, use
317+
a weight in the range 200-300 grams. Could just save an extra bit.
268318

269319
Furthermore it is also important to do the calibration at the temperature you
270320
expect to do the weight measurements. See temperature section below.

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.5.2",
18+
"version": "0.6.0",
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.5.2
2+
version=0.6.0
33
author=Rob Tillaart <rob.tillaart@gmail.com>
44
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
55
sentence=Arduino library for HX711 load cell amplifier.

0 commit comments

Comments
 (0)