Skip to content

Commit 1752f99

Browse files
authored
fix #56, make breaking change more explicit (#57)
- fix #56, update readme.md - add parameter default for **fastProcessor** - add **last_time_read()** to replace **last_read()** in future. - minor edits
1 parent 8dd2657 commit 1752f99

File tree

7 files changed

+59
-28
lines changed

7 files changed

+59
-28
lines changed

CHANGELOG..md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ 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.5.2] - 2024-11-18
9+
- fix #56, update readme.md
10+
- add parameter default for **fastProcessor**
11+
- add **last_time_read()** to replace **last_read()** in future.
12+
- minor edits
13+
14+
815
## [0.5.1] - 2024-11-08
916
- fix #54, calibration sketch should output int32_t for offset.
1017
- update examples

HX711.cpp

Lines changed: 20 additions & 14 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.1
4+
// VERSION: 0.5.2
55
// PURPOSE: Library for load cells for UNO
66
// URL: https://github.com/RobTillaart/HX711_MP
77
// URL: https://github.com/RobTillaart/HX711
@@ -15,7 +15,7 @@ HX711::HX711()
1515
_gain = HX711_CHANNEL_A_GAIN_128;
1616
_offset = 0;
1717
_scale = 1;
18-
_lastRead = 0;
18+
_lastTimeRead = 0;
1919
_price = 0;
2020
_mode = HX711_AVERAGE_MODE;
2121
_fastProcessor = false;
@@ -48,7 +48,7 @@ void HX711::reset()
4848
_gain = HX711_CHANNEL_A_GAIN_128;
4949
_offset = 0;
5050
_scale = 1;
51-
_lastRead = 0;
51+
_lastTimeRead = 0;
5252
_price = 0;
5353
_mode = HX711_AVERAGE_MODE;
5454
}
@@ -141,13 +141,13 @@ float HX711::read()
141141

142142
while (m > 0)
143143
{
144-
// delayMicroSeconds(1) needed for fast processors?
144+
// delayMicroSeconds(1) is needed for fast processors
145+
// T2 >= 0.2 us
145146
digitalWrite(_clockPin, HIGH);
146-
if (_fastProcessor)
147-
delayMicroseconds(1);
147+
if (_fastProcessor) delayMicroseconds(1);
148148
digitalWrite(_clockPin, LOW);
149-
if (_fastProcessor)
150-
delayMicroseconds(1);
149+
// keep duty cycle ~50%
150+
if (_fastProcessor) delayMicroseconds(1);
151151
m--;
152152
}
153153

@@ -157,7 +157,7 @@ float HX711::read()
157157
// SIGN extend
158158
if (v.data[2] & 0x80) v.data[3] = 0xFF;
159159

160-
_lastRead = millis();
160+
_lastTimeRead = millis();
161161
return 1.0 * v.value;
162162
}
163163

@@ -416,9 +416,15 @@ void HX711::power_up()
416416
//
417417
// MISC
418418
//
419+
uint32_t HX711::last_time_read()
420+
{
421+
return _lastTimeRead;
422+
}
423+
424+
// obsolete future
419425
uint32_t HX711::last_read()
420426
{
421-
return _lastRead;
427+
return _lastTimeRead;
422428
}
423429

424430

@@ -458,15 +464,15 @@ uint8_t HX711::_shiftIn()
458464
while (mask > 0)
459465
{
460466
digitalWrite(clk, HIGH);
461-
if(_fastProcessor) // T2 >= 0.2 us
462-
delayMicroseconds(1);
467+
// T2 >= 0.2 us
468+
if(_fastProcessor) delayMicroseconds(1);
463469
if (digitalRead(data) == HIGH)
464470
{
465471
value |= mask;
466472
}
467473
digitalWrite(clk, LOW);
468-
if(_fastProcessor)
469-
delayMicroseconds(1); // keep duty cycle ~50%
474+
// keep duty cycle ~50%
475+
if(_fastProcessor) delayMicroseconds(1);
470476
mask >>= 1;
471477
}
472478
return value;

HX711.h

Lines changed: 5 additions & 4 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.1
5+
// VERSION: 0.5.2
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.1"))
18+
#define HX711_LIB_VERSION (F("0.5.2"))
1919

2020

2121
const uint8_t HX711_AVERAGE_MODE = 0x00;
@@ -163,7 +163,8 @@ class HX711
163163

164164

165165
// TIME OF LAST READ
166-
uint32_t last_read();
166+
uint32_t last_time_read();
167+
uint32_t last_read(); // obsolete in the future
167168

168169

169170
// PRICING
@@ -179,7 +180,7 @@ class HX711
179180
uint8_t _gain;
180181
int32_t _offset;
181182
float _scale;
182-
uint32_t _lastRead;
183+
uint32_t _lastTimeRead;
183184
float _price;
184185
uint8_t _mode;
185186
bool _fastProcessor;

README.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ This translates roughly to 4 or max 5 significant digits in a single measurement
2929
That's why multiple measurements are advised to average and reduce the noise.
3030

3131

32+
### Breaking change 0.4.0
33+
34+
The **begin()** function has a new parameter **bool fastProcessor** which is default false.
35+
It is used to slow down the internal **shiftIn()** to keep clock pulses within the
36+
specification. For most processors the internal code is "slow enough".
37+
If the processor can set an IO pin faster than 0.4 us (spec datasheet == 0.2 us),
38+
the parameter **fastProcessor** must be set to true.
39+
40+
3241
### Breaking change 0.3.0
3342

3443
In issue #11 it became clear that the timing of the default **shiftIn()** function to
@@ -79,9 +88,13 @@ For now one can add an IOpin for this and use **digitalWrite()**.
7988

8089
- https://github.com/bogde/HX711
8190
- https://github.com/RobTillaart/weight (conversions kg <> stone etc.)
91+
- https://github.com/RobTillaart/HX710
8292
- https://github.com/RobTillaart/HX711
8393
- https://github.com/RobTillaart/HX711_MP multipoint calibration version.
8494

95+
Discussion about resolution of the ADC
96+
- https://forum.arduino.cc/t/scale-from-50-kg-to-5000kg-what-adc/1139710
97+
8598

8699
### Faulty boards
87100

@@ -116,7 +129,7 @@ Steps to take for calibration
116129

117130
- **HX711()** constructor.
118131
- **~HX711()**
119-
- **void begin(uint8_t dataPin, uint8_t clockPin, bool fastProcessor)** sets a fixed gain 128 for now.
132+
- **void begin(uint8_t dataPin, uint8_t clockPin, bool fastProcessor = false)** sets a fixed gain 128 for now.
120133
The fastProcessor option adds a 1 uS delay for each clock half-cycle to keep the time greater than 200 nS.
121134
- **void reset()** set internal state to start condition.
122135
Since 0.3.4 reset also does a power down / up cycle.
@@ -294,8 +307,8 @@ For weight conversion functions see https://github.com/RobTillaart/weight
294307

295308
To be verified in a test setup.
296309

297-
In issue #53, a question was asked to convert the input of the HX711 to milivolts.
298-
Thinking about this question resulted in a simple and imho an elegant idea:
310+
In issue #53, a question was asked to convert the input of the HX711 to millivolts.
311+
Thinking about this question resulted in a simple and elegant idea:
299312

300313
- Apply 0.000 mV to the system.
301314
- Call **tare(times)** to calibrate the zero point.
@@ -306,7 +319,7 @@ Assuming the scale is linear, the HX711 now works like a millivolt meter.
306319
And the **float get_units(uint8_t times = 1)** will return microvolts.
307320

308321
In fact, one could map any linear unit this way, e.g. if the voltage applied
309-
is linear with temperature, humidity or windspeed one can map this directly.
322+
is linear with temperature, humidity or wind speed one can map this directly.
310323

311324

312325
## Notes
@@ -400,6 +413,7 @@ See https://github.com/RobTillaart/HX711/issues/40
400413

401414
#### Should
402415

416+
- replace last_read() with last_time_read()
403417
- test B channel explicitly.
404418
- test reset and reboot behaviours.
405419
- investigate read()
@@ -408,6 +422,9 @@ See https://github.com/RobTillaart/HX711/issues/40
408422

409423
#### Could
410424

425+
- optimize fastProcessor code (possible better performance)
426+
- injecting 2 microdelays is not always needed.
427+
- int flag instead of bool.
411428
- test different load cells
412429
- make enum of the MODE's
413430
- add examples

library.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "HX711",
33
"keywords": "loadcell,weight,kilo,pound,gram,price,lbs,ounce,pound",
4-
"description": "Arduino library for HX711 load cell amplifier",
4+
"description": "Arduino library for HX711 load cell amplifier, includes calibrate functions, reading median and median_average.",
55
"authors":
66
[
77
{
@@ -15,7 +15,7 @@
1515
"type": "git",
1616
"url": "https://github.com/RobTillaart/HX711"
1717
},
18-
"version": "0.5.1",
18+
"version": "0.5.2",
1919
"license": "MIT",
2020
"frameworks": "*",
2121
"platforms": "*",

library.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name=HX711
2-
version=0.5.1
2+
version=0.5.2
33
author=Rob Tillaart <rob.tillaart@gmail.com>
44
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
5-
sentence=Arduino library for HX711 load cell amplifier
6-
paragraph=includes calibrate functions.
5+
sentence=Arduino library for HX711 load cell amplifier.
6+
paragraph=includes calibrate functions, reading median and median_average.
77
category=Signal Input/Output
88
url=https://github.com/RobTillaart/HX711
99
architectures=*

test/unit_test_001.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ unittest(test_constructor)
6464
// pins are default LOW apparently.
6565
assertTrue(scale.is_ready());
6666
// default not read
67-
assertEqual(0, scale.last_read());
67+
assertEqual(0, scale.last_time_read());
6868
}
6969

7070

0 commit comments

Comments
 (0)