From bb979353e704c934ab05b178b2b1d7eda111f090 Mon Sep 17 00:00:00 2001 From: olkal Date: Sat, 20 Nov 2021 20:58:08 +0100 Subject: [PATCH] 1.2.10 --- README.md | 4 ++-- examples/Calibration/Calibration.ino | 1 + .../Persistent_zero_offset/Persistent_zero_offset.ino | 1 + examples/Read_1x_load_cell/Read_1x_load_cell.ino | 1 + examples/Read_2x_load_cell/Read_2x_load_cell.ino | 2 ++ examples/Testing/Testing.ino | 1 + keywords.txt | 2 +- library.properties | 2 +- src/HX711_ADC.cpp | 9 +++++++++ src/HX711_ADC.h | 2 ++ 10 files changed, 21 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 57b7d28..bc36857 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ Latest release and change log here: https://github.com/olkal/HX711_ADC/releases This an Arduino library for the HX711 24-bit ADC for weight scales. -Data retrieval from the HX711 is done without halting the mcu, also on the 10SPS rate setting and with Multiple HX711's performing conversions simultaneously. -Tare function can also be performed without halting the mcu. +Data retrieval from the HX711 is done without blocking the mcu, also on the 10SPS rate setting and with Multiple HX711's performing conversions simultaneously. +Tare function can also be performed without blocking the mcu. Filtering and smoothing: "Moving average" method from a rolling data set combined with removal of high/low outliers is used for the retrieved value. diff --git a/examples/Calibration/Calibration.ino b/examples/Calibration/Calibration.ino index 7922203..913aa25 100644 --- a/examples/Calibration/Calibration.ino +++ b/examples/Calibration/Calibration.ino @@ -39,6 +39,7 @@ void setup() { Serial.println("Starting..."); LoadCell.begin(); + //LoadCell.setReverseVal(); //uncomment to turn a negative output value to positive unsigned long stabilizingtime = 2000; // preciscion right after power-up can be improved by adding a few seconds of stabilizing time boolean _tare = true; //set this to false if you don't want tare to be performed in the next step LoadCell.start(stabilizingtime, _tare); diff --git a/examples/Persistent_zero_offset/Persistent_zero_offset.ino b/examples/Persistent_zero_offset/Persistent_zero_offset.ino index 308057a..6e1b74c 100644 --- a/examples/Persistent_zero_offset/Persistent_zero_offset.ino +++ b/examples/Persistent_zero_offset/Persistent_zero_offset.ino @@ -41,6 +41,7 @@ void setup() { Serial.println("Starting..."); LoadCell.begin(); + //LoadCell.setReverseVal(); //uncomment to turn a negative output value to positive float calibrationValue; // calibration value (see example file "Calibration.ino") calibrationValue = 696.0; // uncomment this if you want to set the calibration value in the sketch diff --git a/examples/Read_1x_load_cell/Read_1x_load_cell.ino b/examples/Read_1x_load_cell/Read_1x_load_cell.ino index fb07c42..91479ff 100644 --- a/examples/Read_1x_load_cell/Read_1x_load_cell.ino +++ b/examples/Read_1x_load_cell/Read_1x_load_cell.ino @@ -39,6 +39,7 @@ void setup() { Serial.println("Starting..."); LoadCell.begin(); + //LoadCell.setReverseVal(); //uncomment to turn a negative output value to positive float calibrationValue; // calibration value (see example file "Calibration.ino") calibrationValue = 696.0; // uncomment this if you want to set the calibration value in the sketch #if defined(ESP8266)|| defined(ESP32) diff --git a/examples/Read_2x_load_cell/Read_2x_load_cell.ino b/examples/Read_2x_load_cell/Read_2x_load_cell.ino index 77be1d0..b277a32 100644 --- a/examples/Read_2x_load_cell/Read_2x_load_cell.ino +++ b/examples/Read_2x_load_cell/Read_2x_load_cell.ino @@ -45,6 +45,8 @@ void setup() { LoadCell_1.begin(); LoadCell_2.begin(); + //LoadCell_1.setReverseVal(); //uncomment to turn a negative output value to positive + //LoadCell_2.setReverseVal(); //uncomment to turn a negative output value to positive unsigned long stabilizingtime = 2000; // tare preciscion can be improved by adding a few seconds of stabilizing time boolean _tare = true; //set this to false if you don't want tare to be performed in the next step byte loadcell_1_rdy = 0; diff --git a/examples/Testing/Testing.ino b/examples/Testing/Testing.ino index 3fabc68..0d3a3a0 100644 --- a/examples/Testing/Testing.ino +++ b/examples/Testing/Testing.ino @@ -46,6 +46,7 @@ void setup() { //EEPROM.get(calVal_eepromAdress, calibrationValue); // uncomment this if you want to fetch this value from eeprom LoadCell.begin(); + //LoadCell.setReverseVal(); //uncomment to turn a negative output value to positive unsigned long stabilizingtime = 2000; // tare preciscion can be improved by adding a few seconds of stabilizing time boolean _tare = true; //set this to false if you don't want tare to be performed in the next step LoadCell.start(stabilizingtime, _tare); diff --git a/keywords.txt b/keywords.txt index a951398..f96e664 100644 --- a/keywords.txt +++ b/keywords.txt @@ -40,7 +40,7 @@ refreshDataSet KEYWORD2 getDataSetStatus KEYWORD2 getNewCalibration KEYWORD2 getSignalTimeoutFlag KEYWORD2 - +setReverseVal KEYWORD2 ####################################### diff --git a/library.properties b/library.properties index 9fe8484..d6eb3d8 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=HX711_ADC -version=1.2.9 +version=1.2.10 author=Olav Kallhovd maintainer=Olav Kallhovd sentence=Library for the HX711 24-bit ADC for weight scales. diff --git a/src/HX711_ADC.cpp b/src/HX711_ADC.cpp index cbb65bf..8362aa0 100644 --- a/src/HX711_ADC.cpp +++ b/src/HX711_ADC.cpp @@ -322,6 +322,9 @@ void HX711_ADC::conversion24bit() //read 24 bit data, store in dataset and star dataOutOfRange = 1; //Serial.println("dataOutOfRange"); } + if (reverseVal) { + data = 0xFFFFFF - data; + } if (readIndex == samplesInUse + IGN_HIGH_SAMPLE + IGN_LOW_SAMPLE - 1) { readIndex = 0; @@ -505,3 +508,9 @@ bool HX711_ADC::getSignalTimeoutFlag() { return signalTimeoutFlag; } + +//reverse the output value (flip positive/negative value) +//tare/zero-offset must be re-set after calling this. +void HX711_ADC::setReverseVal() { + reverseVal = true; +} \ No newline at end of file diff --git a/src/HX711_ADC.h b/src/HX711_ADC.h index 8f395a6..8b79f3f 100644 --- a/src/HX711_ADC.h +++ b/src/HX711_ADC.h @@ -82,6 +82,7 @@ class HX711_ADC bool getDataSetStatus(); //returns 'true' when the whole dataset has been filled up with conversions, i.e. after a reset/restart float getNewCalibration(float known_mass); //returns and sets a new calibration value (calFactor) based on a known mass input bool getSignalTimeoutFlag(); //returns 'true' if it takes longer time then 'SIGNAL_TIMEOUT' for the dout pin to go low after a new conversion is started + void setReverseVal(); //reverse the output value protected: void conversion24bit(); //if conversion is ready: returns 24 bit data and starts the next conversion @@ -114,6 +115,7 @@ class HX711_ADC bool dataOutOfRange = 0; unsigned long lastDoutLowTime = 0; bool signalTimeoutFlag = 0; + bool reverseVal = 0; }; #endif