0.3.0 HX711_MP

This commit is contained in:
Rob Tillaart 2024-06-17 14:20:21 +02:00
parent 51f2cb1558
commit 04e2b8c617
5 changed files with 75 additions and 22 deletions

View File

@ -5,6 +5,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/). and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.3.0] - 2024-06-17
- fix #5, reset bug
- refactor constructor
- move code to .cpp file (to match HX711)
----
## [0.2.0] - 2024-03-02 ## [0.2.0] - 2024-03-02
- add fastProcessor option in **begin()** (Thanks to palmerr23) - add fastProcessor option in **begin()** (Thanks to palmerr23)
- updated license - updated license

View File

@ -1,7 +1,7 @@
// //
// FILE: HX711_MP.cpp // FILE: HX711_MP.cpp
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.2.0 // VERSION: 0.3.0
// PURPOSE: Library for load cells for UNO // PURPOSE: Library for load cells for UNO
// URL: https://github.com/RobTillaart/HX711_MP // URL: https://github.com/RobTillaart/HX711_MP
// URL: https://github.com/RobTillaart/HX711 // URL: https://github.com/RobTillaart/HX711
@ -21,7 +21,9 @@ HX711_MP::HX711_MP(uint8_t size)
{ {
_size = 2; // hard coded minimum!! _size = 2; // hard coded minimum!!
} }
reset(); _gain = HX711_CHANNEL_A_GAIN_128;
_lastRead = 0;
_mode = HX711_AVERAGE_MODE;
} }
@ -263,6 +265,46 @@ float HX711_MP::get_units(uint8_t times)
} }
///////////////////////////////////////////////////////////////
//
// MODE
//
void HX711_MP::set_raw_mode()
{
_mode = HX711_RAW_MODE;
}
void HX711_MP::set_average_mode()
{
_mode = HX711_AVERAGE_MODE;
}
void HX711_MP::set_median_mode()
{
_mode = HX711_MEDIAN_MODE;
}
void HX711_MP::set_medavg_mode()
{
_mode = HX711_MEDAVG_MODE;
}
void HX711_MP::set_runavg_mode()
{
_mode = HX711_RUNAVG_MODE;
}
uint8_t HX711_MP::get_mode()
{
return _mode;
}
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// //
// GAIN // GAIN
@ -352,6 +394,12 @@ void HX711_MP::power_up()
} }
uint32_t HX711_MP::last_read()
{
return _lastRead;
}
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// //
// PRIVATE // PRIVATE

View File

@ -2,19 +2,20 @@
// //
// FILE: HX711_MP.h // FILE: HX711_MP.h
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.2.0 // VERSION: 0.3.0
// PURPOSE: Library for load cells for Arduino // PURPOSE: Library for load cells for Arduino
// URL: https://github.com/RobTillaart/HX711_MP // URL: https://github.com/RobTillaart/HX711_MP
// URL: https://github.com/RobTillaart/HX711 // URL: https://github.com/RobTillaart/HX711
// //
// NOTES // NOTES
// Superset of interface of HX711 class of Bogde // Superset of interface of HX711 class of Bogde
// float instead of long as float has 23 bits mantissa. // uses float instead of long as float has 23 bits mantissa
// which almost perfectly matches the 24 bit ADC.
#include "Arduino.h" #include "Arduino.h"
#define HX711_MP_LIB_VERSION (F("0.2.0")) #define HX711_MP_LIB_VERSION (F("0.3.0"))
const uint8_t HX711_AVERAGE_MODE = 0x00; const uint8_t HX711_AVERAGE_MODE = 0x00;
@ -100,13 +101,13 @@ public:
// //
// get set mode for get_value() and indirect get_units(). // get set mode for get_value() and indirect get_units().
// in median and medavg mode only 3..15 samples are allowed. // in median and medavg mode only 3..15 samples are allowed.
void set_raw_mode() { _mode = HX711_RAW_MODE; }; void set_raw_mode();
void set_average_mode() { _mode = HX711_AVERAGE_MODE; }; void set_average_mode();
void set_median_mode() { _mode = HX711_MEDIAN_MODE; }; void set_median_mode();
void set_medavg_mode() { _mode = HX711_MEDAVG_MODE; }; void set_medavg_mode();
// set_run_avg will use a default alpha of 0.5. // set_run_avg will use a default alpha of 0.5.
void set_runavg_mode() { _mode = HX711_RUNAVG_MODE; }; void set_runavg_mode();
uint8_t get_mode() { return _mode; }; uint8_t get_mode();
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
@ -159,10 +160,7 @@ public:
// TIME OF LAST READ // TIME OF LAST READ
uint32_t last_read() uint32_t last_read();
{
return _lastRead;
}
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
@ -176,12 +174,12 @@ public:
private: private:
uint8_t _dataPin = -1; uint8_t _dataPin;
uint8_t _clockPin = -1; uint8_t _clockPin;
uint8_t _gain = 128; // default channel A uint8_t _gain;
uint32_t _lastRead = 0; uint32_t _lastRead;
uint8_t _mode = HX711_AVERAGE_MODE; uint8_t _mode;
void _insertSort(float * array, uint8_t size); void _insertSort(float * array, uint8_t size);
uint8_t _shiftIn(); uint8_t _shiftIn();

View File

@ -15,7 +15,7 @@
"type": "git", "type": "git",
"url": "https://github.com/RobTillaart/HX711_MP" "url": "https://github.com/RobTillaart/HX711_MP"
}, },
"version": "0.2.0", "version": "0.3.0",
"license": "MIT", "license": "MIT",
"frameworks": "*", "frameworks": "*",
"platforms": "*", "platforms": "*",

View File

@ -1,5 +1,5 @@
name=HX711_MP name=HX711_MP
version=0.2.0 version=0.3.0
author=Rob Tillaart <rob.tillaart@gmail.com> author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com> maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for HX711 load cell amplifier. sentence=Arduino library for HX711 load cell amplifier.