Skip to content

Commit 6ecbf48

Browse files
committed
0.3.2 HX711_MP
1 parent ceb4d58 commit 6ecbf48

File tree

13 files changed

+69
-27
lines changed

13 files changed

+69
-27
lines changed

libraries/HX711_MP/CHANGELOG..md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ 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.2] - 2025-06-19
9+
- fix **is_ready()** (see HX711 #65)
10+
- add **last_time_read()** to replace **last_read()**
11+
- minor edits
12+
813
## [0.3.1] - 2024-11-08
914
- fix #7, sync with HX711 0.5.1
1015
- clean up examples a bit

libraries/HX711_MP/HX711_MP.cpp

Lines changed: 24 additions & 17 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.1
4+
// VERSION: 0.3.2
55
// PURPOSE: Library for load cells for UNO
66
// URL: https://github.com/RobTillaart/HX711_MP
77
// URL: https://github.com/RobTillaart/HX711
@@ -22,7 +22,7 @@ HX711_MP::HX711_MP(uint8_t size)
2222
_size = 2; // hard coded minimum!!
2323
}
2424
_gain = HX711_CHANNEL_A_GAIN_128;
25-
_lastRead = 0;
25+
_lastTimeRead = 0;
2626
_mode = HX711_AVERAGE_MODE;
2727
}
2828

@@ -38,7 +38,7 @@ void HX711_MP::begin(uint8_t dataPin, uint8_t clockPin, bool fastProcessor )
3838
_clockPin = clockPin;
3939
_fastProcessor = fastProcessor;
4040

41-
pinMode(_dataPin, INPUT);
41+
pinMode(_dataPin, INPUT_PULLUP);
4242
pinMode(_clockPin, OUTPUT);
4343
digitalWrite(_clockPin, LOW);
4444

@@ -51,7 +51,7 @@ void HX711_MP::reset()
5151
power_down();
5252
power_up();
5353
_gain = HX711_CHANNEL_A_GAIN_128;
54-
_lastRead = 0;
54+
_lastTimeRead = 0;
5555
_mode = HX711_AVERAGE_MODE;
5656
}
5757

@@ -143,13 +143,13 @@ float HX711_MP::read()
143143

144144
while (m > 0)
145145
{
146-
// delayMicroSeconds(1) needed for fast processors?
146+
// delayMicroSeconds(1) is needed for fast processors
147+
// T2 >= 0.2 us
147148
digitalWrite(_clockPin, HIGH);
148-
if (_fastProcessor)
149-
delayMicroseconds(1);
149+
if (_fastProcessor) delayMicroseconds(1);
150150
digitalWrite(_clockPin, LOW);
151-
if (_fastProcessor)
152-
delayMicroseconds(1);
151+
// keep duty cycle ~50%
152+
if (_fastProcessor) delayMicroseconds(1);
153153
m--;
154154
}
155155

@@ -159,7 +159,7 @@ float HX711_MP::read()
159159
// SIGN extend
160160
if (v.data[2] & 0x80) v.data[3] = 0xFF;
161161

162-
_lastRead = millis();
162+
_lastTimeRead = millis();
163163
return 1.0 * v.value;
164164
}
165165

@@ -302,7 +302,8 @@ float HX711_MP::get_value(uint8_t times)
302302

303303
float HX711_MP::get_units(uint8_t times)
304304
{
305-
return _multiMap(get_value(times));
305+
float units = _multiMap(get_value(times));
306+
return units;
306307
}
307308

308309

@@ -383,7 +384,7 @@ float HX711_MP::getCalibrateWeight(uint8_t index)
383384
//
384385
void HX711_MP::power_down()
385386
{
386-
// at least 60 us HIGH
387+
// at least 60 us HIGH
387388
digitalWrite(_clockPin, HIGH);
388389
delayMicroseconds(64);
389390
}
@@ -399,9 +400,15 @@ void HX711_MP::power_up()
399400
//
400401
// MISC
401402
//
403+
uint32_t HX711_MP::last_time_read()
404+
{
405+
return _lastTimeRead;
406+
}
407+
408+
// obsolete future
402409
uint32_t HX711_MP::last_read()
403410
{
404-
return _lastRead;
411+
return _lastTimeRead;
405412
}
406413

407414

@@ -440,15 +447,15 @@ uint8_t HX711_MP::_shiftIn()
440447
while (mask > 0)
441448
{
442449
digitalWrite(clk, HIGH);
443-
if(_fastProcessor) // T2 >= 0.2 us
444-
delayMicroseconds(1);
450+
// T2 >= 0.2 us
451+
if(_fastProcessor) delayMicroseconds(1);
445452
if (digitalRead(data) == HIGH)
446453
{
447454
value |= mask;
448455
}
449456
digitalWrite(clk, LOW);
450-
if(_fastProcessor)
451-
delayMicroseconds(1); // keep duty cycle ~50%
457+
// keep duty cycle ~50%
458+
if(_fastProcessor) delayMicroseconds(1);
452459
mask >>= 1;
453460
}
454461
return value;

libraries/HX711_MP/HX711_MP.h

Lines changed: 6 additions & 3 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.1
5+
// VERSION: 0.3.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_MP_LIB_VERSION (F("0.3.1"))
18+
#define HX711_MP_LIB_VERSION (F("0.3.2"))
1919

2020

2121
const uint8_t HX711_AVERAGE_MODE = 0x00;
@@ -160,6 +160,9 @@ class HX711_MP
160160

161161

162162
// TIME OF LAST READ
163+
uint32_t last_time_read();
164+
// obsolete in the future
165+
[[deprecated("Use last_time_read() instead.")]]
163166
uint32_t last_read();
164167

165168

@@ -178,7 +181,7 @@ class HX711_MP
178181
uint8_t _clockPin;
179182

180183
uint8_t _gain;
181-
uint32_t _lastRead;
184+
uint32_t _lastTimeRead;
182185
uint8_t _mode;
183186
bool _fastProcessor;
184187

libraries/HX711_MP/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_MP/README.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,37 @@ This library does not provide means to control the **RATE** yet.
4848
If there is a need (issue) I will implement this in the library.
4949
For now one can add an IOpin for this and use **digitalWrite()**.
5050

51+
If you need more SPS you could consider using the HX71708 device.
52+
This is a close "relative" of the HX711 that allows to set the SPS to
53+
10, 20, 80, or 320 Hz.
54+
- https://github.com/beniseman/HX71708
55+
5156

5257
### Related
5358

5459
- https://github.com/bogde/HX711
5560
- https://github.com/RobTillaart/weight (conversions kg <> stone etc.)
61+
- https://github.com/RobTillaart/HX710AB
5662
- https://github.com/RobTillaart/HX711
5763
- https://github.com/RobTillaart/HX711_MP multipoint calibration version.
5864

65+
Discussion about resolution of the ADC
66+
- https://forum.arduino.cc/t/scale-from-50-kg-to-5000kg-what-adc/1139710
67+
68+
Support for the HX71708 device (close related)
69+
- https://github.com/beniseman/HX71708 allows to set the SPS to 10, 20, 80, or 320 Hz
70+
71+
Load cells go to very high weights, this side sells them up to 200 ton.
72+
Never seen one and cannot tell if it will work with this library.
73+
- https://stekon.nl/load-cells
74+
5975

6076
### Faulty boards
6177

6278
- https://forum.arduino.cc/t/load-cell-amplifier-hx711-wrong-ground/1046075
6379

6480

65-
#### Differences HX711
81+
### Differences HX711
6682

6783
Although the library is derived from the HX711 library they are not compatible.
6884
Almost is the right word here.
@@ -97,19 +113,25 @@ is more math involved for converting raw data to weights.
97113
Parameter sets the size of for the calibration arrays.
98114
Allowed range for size is 2..10.
99115
- **~HX711_MP()**
100-
- **void begin(uint8_t dataPin, uint8_t clockPin, bool fastProcessor)** sets a fixed gain 128 for now.
116+
- **void begin(uint8_t dataPin, uint8_t clockPin, bool fastProcessor = false)** sets a fixed gain 128 for now.
101117
The fastProcessor option adds a 1 uS delay for each clock half-cycle to keep the time greater than 200 nS.
102118
- **void reset()** set internal state to start condition.
103119
Reset also does a power down / up cycle.
104120
It does not reset the calibration data.
105121

106122

107-
### Read
123+
### isReady
124+
125+
Different ways to wait for a new measurement.
108126

109127
- **bool is_ready()** checks if load cell is ready to read.
110128
- **void wait_ready(uint32_t ms = 0)** wait until ready, check every ms.
111129
- **bool wait_ready_retry(uint8_t retries = 3, uint32_t ms = 0)** wait max retries.
112130
- **bool wait_ready_timeout(uint32_t timeout = 1000, uint32_t ms = 0)** wait max timeout milliseconds.
131+
132+
133+
### Read
134+
113135
- **float read()** raw read.
114136
- **float read_average(uint8_t times = 10)** get average of times raw reads. times = 1 or more.
115137
- **float read_median(uint8_t times = 7)** get median of multiple raw reads.

libraries/HX711_MP/examples/HX_MP_calibrate/HX_MP_calibrate.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ float f;
2424
void setup()
2525
{
2626
Serial.begin(115200);
27+
Serial.println();
2728
Serial.println(__FILE__);
2829
Serial.print("HX711_MP_LIB_VERSION: ");
2930
Serial.println(HX711_MP_LIB_VERSION);

libraries/HX711_MP/examples/HX_MP_performance/HX_MP_performance.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ volatile float f;
2424
void setup()
2525
{
2626
Serial.begin(115200);
27+
Serial.println();
2728
Serial.println(__FILE__);
2829
Serial.print("HX711_MP_LIB_VERSION: ");
2930
Serial.println(HX711_MP_LIB_VERSION);

libraries/HX711_MP/examples/HX_MP_performance2/HX_MP_performance2.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ volatile float f;
2424
void setup()
2525
{
2626
Serial.begin(115200);
27+
Serial.println();
2728
Serial.println(__FILE__);
2829
Serial.print("HX711_MP_LIB_VERSION: ");
2930
Serial.println(HX711_MP_LIB_VERSION);

libraries/HX711_MP/examples/HX_MP_plotter/HX_MP_plotter.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ float f;
2424
void setup()
2525
{
2626
Serial.begin(115200);
27+
// Serial.println();
2728
// Serial.println(__FILE__);
2829
// Serial.print("HX711_MP_LIB_VERSION: ");
2930
// Serial.println(HX711_MP_LIB_VERSION);

libraries/HX711_MP/examples/HX_MP_runtime_calibration/HX_MP_runtime_calibration.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ uint8_t PIN_DOWN = 19;
2424
void setup()
2525
{
2626
Serial.begin(115200);
27+
Serial.println();
2728
Serial.println(__FILE__);
2829
Serial.print("HX711_MP_LIB_VERSION: ");
2930
Serial.println(HX711_MP_LIB_VERSION);

0 commit comments

Comments
 (0)