From b5126afe2d63d4b90103e6e24d6b00729736dbc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9m=27S?= Date: Sat, 14 May 2016 08:55:24 +0200 Subject: [PATCH] add links --- ...1 Weighing Sensors AD Module | eBay.webloc | Bin 0 -> 88 bytes ...711 24 bit ADC with four load cells.webloc | Bin 0 -> 102 bytes ...s-hx711 at master · aguegu-ardulibs.webloc | Bin 0 -> 105 bytes ...r HX711 24-Bit Analog-to-Digital C….webloc | Bin 0 -> 83 bytes .../LiquidCrystalScale/LiquidCrystalScale.ino | 44 ++++++++++ .../examples/SerialScale/SerialScale.ino | 33 +++++++ library/hx711/hx711.cpp | 81 ++++++++++++++++++ library/hx711/hx711.h | 38 ++++++++ library/hx711/readme.md | 76 ++++++++++++++++ 9 files changed, 272 insertions(+) create mode 100644 Links/10kg Weight Weighing Sensor Scale Load Cell HX711 Weighing Sensors AD Module | eBay.webloc create mode 100644 Links/HX711 24 bit ADC with four load cells.webloc create mode 100644 Links/ardulibs-hx711 at master · aguegu-ardulibs.webloc create mode 100644 Links/bogde-HX711- An Arduino library to interface the Avia Semiconductor HX711 24-Bit Analog-to-Digital C….webloc create mode 100755 library/hx711/examples/LiquidCrystalScale/LiquidCrystalScale.ino create mode 100755 library/hx711/examples/SerialScale/SerialScale.ino create mode 100755 library/hx711/hx711.cpp create mode 100755 library/hx711/hx711.h create mode 100755 library/hx711/readme.md diff --git a/Links/10kg Weight Weighing Sensor Scale Load Cell HX711 Weighing Sensors AD Module | eBay.webloc b/Links/10kg Weight Weighing Sensor Scale Load Cell HX711 Weighing Sensors AD Module | eBay.webloc new file mode 100644 index 0000000000000000000000000000000000000000..672a39b19f46ae8b4d7676a3b3995284d68a481a GIT binary patch literal 88 zcmYc)$jK}&F)+Bu$P^qJTg!zfb#7(o!O literal 0 HcmV?d00001 diff --git a/Links/HX711 24 bit ADC with four load cells.webloc b/Links/HX711 24 bit ADC with four load cells.webloc new file mode 100644 index 0000000000000000000000000000000000000000..6ddae6ef649fe1a8b1f47fa95541007b954cb0c5 GIT binary patch literal 102 zcmYc)$jK}&F)+Bu$P^qJ$cte=^el3Jlx lkWpY?l3$RSY-?m>W^8DpXTZVD&j1FDj1ZcE8A`(_X8<$77XttQ literal 0 HcmV?d00001 diff --git a/Links/ardulibs-hx711 at master · aguegu-ardulibs.webloc b/Links/ardulibs-hx711 at master · aguegu-ardulibs.webloc new file mode 100644 index 0000000000000000000000000000000000000000..20f6bfa702fd8d9b8a574545c69dbcf28c47bf20 GIT binary patch literal 105 zcmYc)$jK}&F)+Bu$P^qJ +#include + +LiquidCrystal lcd(12, 11, 5, 4, 3, 2); +Hx711 scale(A1, A0); + +void setup() { + + lcd.begin(16, 2); + +} + +void loop() { + + lcd.setCursor(0, 0); + lcd.print(scale.getGram(), 1); + lcd.print(" g"); + lcd.print(" "); + + delay(200); +} + diff --git a/library/hx711/examples/SerialScale/SerialScale.ino b/library/hx711/examples/SerialScale/SerialScale.ino new file mode 100755 index 0000000..baf0e6b --- /dev/null +++ b/library/hx711/examples/SerialScale/SerialScale.ino @@ -0,0 +1,33 @@ +/* sample for digital weight scale of hx711, display with a HD44780 liquid crtstal monitor + * + * hardware design: syyyd + * available at http://syyyd.taobao.com + * + * library design: Weihong Guan (@aguegu) + * http://aguegu.net + * + * library host on + * https://github.com/aguegu/Arduino + */ + +// Hx711.DOUT - pin #A1 +// Hx711.SCK - pin #A0 + +#include "hx711.h" + +Hx711 scale(A1, A0); + +void setup() { + + Serial.begin(9600); + +} + +void loop() { + + Serial.print(scale.getGram(), 1); + Serial.println(" g"); + + delay(200); +} + diff --git a/library/hx711/hx711.cpp b/library/hx711/hx711.cpp new file mode 100755 index 0000000..ff03ab9 --- /dev/null +++ b/library/hx711/hx711.cpp @@ -0,0 +1,81 @@ +/* + * Hx711.cpp + * + * Created on: Oct 31, 2012 + * Author: agu + */ + +#include "hx711.h" + +Hx711::Hx711(uint8_t pin_dout, uint8_t pin_slk) : + _pin_dout(pin_dout), _pin_slk(pin_slk) +{ + pinMode(_pin_slk, OUTPUT); + pinMode(_pin_dout, INPUT); + + digitalWrite(_pin_slk, HIGH); + delayMicroseconds(100); + digitalWrite(_pin_slk, LOW); + + averageValue(); + this->setOffset(averageValue()); + this->setScale(); +} + +Hx711::~Hx711() +{ + +} + +long Hx711::averageValue(byte times) +{ + long sum = 0; + for (byte i = 0; i < times; i++) + { + sum += getValue(); + } + + return sum / times; +} + +long Hx711::getValue() +{ + byte data[3]; + + while (digitalRead(_pin_dout)) + ; + + for (byte j = 3; j--;) + { + for (char i = 8; i--;) + { + digitalWrite(_pin_slk, HIGH); + bitWrite(data[j], i, digitalRead(_pin_dout)); + digitalWrite(_pin_slk, LOW); + } + } + + digitalWrite(_pin_slk, HIGH); + digitalWrite(_pin_slk, LOW); + + data[2] ^= 0x80; + + return ((uint32_t) data[2] << 16) | ((uint32_t) data[1] << 8) + | (uint32_t) data[0]; +} + +void Hx711::setOffset(long offset) +{ + _offset = offset; +} + +void Hx711::setScale(float scale) +{ + _scale = scale; +} + +float Hx711::getGram() +{ + long val = (averageValue() - _offset); + return (float) val / _scale; +} diff --git a/library/hx711/hx711.h b/library/hx711/hx711.h new file mode 100755 index 0000000..abcb3e8 --- /dev/null +++ b/library/hx711/hx711.h @@ -0,0 +1,38 @@ +/* Arduino library for digital weight scale of hx711 + * + * hardware design: syyyd + * available at http://syyyd.taobao.com + * + * library design: Weihong Guan (@aguegu) + * http://aguegu.net + * + * library host on + * https://github.com/aguegu/Arduino + * + * Created on: Oct 31, 2012 + */ + +#ifndef HX711_H_ +#define HX711_H_ + +#include "Arduino.h" + +class Hx711 +{ +public: + Hx711(uint8_t pin_din, uint8_t pin_slk); + virtual ~Hx711(); + long getValue(); + long averageValue(byte times = 32); + void setOffset(long offset); + void setScale(float scale = 742.f); + float getGram(); + +private: + const uint8_t _pin_dout; + const uint8_t _pin_slk; + long _offset; + float _scale; +}; + +#endif /* HX711_H_ */ diff --git a/library/hx711/readme.md b/library/hx711/readme.md new file mode 100755 index 0000000..0d765b9 --- /dev/null +++ b/library/hx711/readme.md @@ -0,0 +1,76 @@ +Thanks for trying my lib. It has been quite a while, and there are still people email me about how to use it. I really appreciate that. + +I have written [an blog about hx711](http://aguegu.net/?p=1327), well, in Chiese... + +To config the module right, you need to config the offset and the scale. The `setScale` function should be named `setRatio` to make its function more clear. But for now, just leave it the way it is. + +The offset and scale value are got by experiments, which means they vary according to different setups. + +To do the test right: +```cpp +#include "hx711.h" + +Hx711 scale(A1, A0); + +void setup() { + Serial.begin(9600); +} + +void loop() { + Serial.println(scale.averageValue()); + delay(200); +} +``` + +1. place nothing on the scale, then run the example code, which means reset your arduino that runs the example code above. + +record the output. that is the `offset`. + +2. place a stand weight, like 1kg(1000g), record the output as `w`. + +3. Do the math + +ratio = (`w` - `offset`) / 1000 + +4. modify your application code to + +```cpp +#include "hx711.h" + +Hx711 scale(A1, A0); + +void setup() { + Serial.begin(9600); + scale.setOffset(fill in the `offset` value here); + scale.setScale(fill in the `ratio` value here); +} + +void loop() { + Serial.println(scale.getGram()); + delay(200); +} +``` + +Then arduino should give you the right result in unit gram. + +The init program has set the average value for the first few runs to the offset, with the function `setOffset`. It is written in the lib. + +My example code is supposed to work with scale that got a few seconds of zero weight when the program start running. But we still need to do the test to calculate the ratio. It is just happen to be 742 in my setup, but it dose not fit for other setups. + +If the setup got weight already when the program start running, and you do not want its getGram() output to be zero. Then you have to setOffset() again manually with the tested value to override the auto offset, just like the example code above. + +the averageValue() basically is the raw output. It is not affected by the offest or the scale(ratio). The offset determind your zero point. while the scale(ratio) determind what unit you want the getGram() output to be. With different ratio value, the output can be in g, kg, oz, pound, whatever, as long as the value in the range of the setup and makes sense to you. + +``` +0g = 0kg = 0oz = 0pound +1000g = 1kg = 35.274oz = 2.20462 pound +``` + +Just remember that the raw output and the calculated (`getGram()`) output, are linear related. + + +``` +getGram() = (averageValue() - offset) / ratio; +``` + +Just middle school math. :)