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
303303float 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//
384385void 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
402409uint32_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;
0 commit comments