Skip to content

Commit b5e9278

Browse files
author
GatCode
committed
Update Readme
1 parent 6a73cc7 commit b5e9278

File tree

2 files changed

+105
-2
lines changed

2 files changed

+105
-2
lines changed

README.md

Lines changed: 105 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,105 @@
1-
# ScaleStabilizer
2-
a library to stabilize load cell readings
1+
<p align="center">
2+
<!-- <img width="300" src="assets/logo.png"> -->
3+
<h1 align="center">ScaleStabilizer</h1>
4+
<h3 align="center">Simple library to stabilize load cell readings</h3></br>
5+
<p align="center">
6+
<img alt="license" src="https://img.shields.io/badge/license-MIT-blue">
7+
<img alt="gitter" src="https://img.shields.io/badge/Arduino-blue">
8+
<img alt="gitter" src="https://img.shields.io/badge/PlatformIO-blue">
9+
</p>
10+
</p>
11+
<br>
12+
13+
## About
14+
15+
Since the usage of load cells for accurate weight measurement is always correlated with measurement errors (ADC, hardware, ...), the implementation of a reliable error correction / stabilization code is necessary.
16+
17+
This library provides an easy way to accommodate for these errors without sacrificing measurement speed or the implementation of accurate timing measurements.
18+
19+
The idea for the two basic algorithms behind this library were borrowed from *Colm Slattery* *and Mariah Nie's* [A Reference Design for High-Performance, Low-Cost Weigh Scales | Analog Devices](https://www.analog.com/en/analog-dialogue/articles/a-reference-design-for-weigh-scales.html), which describes an excellent way to solve these problems.
20+
21+
## Basic principle
22+
23+
In the image below, you can see the two basic algorithms, which are used in the library. To further improve the results, an [Moving average](https://en.wikipedia.org/wiki/Moving_average) filter is used.
24+
25+
![](assets/principle.png)
26+
27+
(Image copied from [A Reference Design for High-Performance, Low-Cost Weigh Scales](https://www.analog.com/en/analog-dialogue/articles/a-reference-design-for-weigh-scales.html))
28+
29+
## How can I use ScaleStabilizer in my project?
30+
31+
Simply include the library in your project, call the begin function in the setup part and then add the load cell measurements to the ScaleStabilizer object as follows.
32+
33+
**Note:** I've used a real word example below with measurements from an HX711 ADC and the according library.
34+
35+
```C
36+
#include "HX711.h"
37+
#include "ScaleStabilizer.h"
38+
39+
// Scale
40+
const int DOUT_PIN = 23;
41+
const int SCK_PIN = 22;
42+
HX711 scale;
43+
44+
// Scale Stabilizer
45+
const int WINDOW_SIZE = 10;
46+
const double WEIGHT_THRESHOLD = 0.01;
47+
ScaleStabilizer stabilizer;
48+
49+
void setup() {
50+
Serial.begin(115200);
51+
52+
scale.begin(DOUT_PIN, SCK_PIN);
53+
scale.set_scale(720);
54+
scale.tare();
55+
56+
stabilizer.begin(WINDOW_SIZE, WEIGHT_THRESHOLD);
57+
}
58+
59+
void loop() {
60+
double adcReading = scale.get_units();
61+
stabilizer.add(adcReading);
62+
Serial.println(stabilizer.getStablilizedReading());
63+
}
64+
```
65+
66+
## Functions and Parameters
67+
68+
#### void begin(int windowSize, double weightThreshold)
69+
70+
- the call of this function is necessary to start the stabilizer
71+
* @param windowSize represents the size of the moving window
72+
73+
* @param weightThreshold represents the weight/noise threshold - e.g. 0.1g
74+
75+
Try to adjust these two parameters to fit your project. The more you increase the windowSize, the smoother the output will be but at the same time the scale will become unresponsive.
76+
77+
Also weightThreshold or noise threshold will determine what you perceive as noise / measurement error and what should be real data. For example a weightThreshold of 0.01 means that every data change thats below +/- 0.0.1 is considered as noise.
78+
79+
#### void add(double reading)
80+
81+
- call this function to add a new data point to the ScaleStabilizer
82+
83+
- @param reading: ADC value/reading
84+
85+
#### double getStablilizedReading(double displayResolution = 0.1, int decimalPlaces = 1)
86+
87+
- returns the stabilized load cell reading
88+
89+
- @param displayResolution represents the output resolution - e.g. 0.1g accuracy
90+
91+
- @param decimalPlaces represents the decimal places present in the output
92+
93+
- @default values for the parameters are 0.1g and 1 decimal place
94+
95+
Try to adjust these two parameters to fit your project. Via the displayResolution you can set the expected output resolution. For example if you need a scale to only be able to display the weight in 0.5g steps, you can set the displayResolution to 0.5g and the output will be e.g. 15.0g ... 15.5g ... 16g ...
96+
97+
Accordingly, the parameter decimalPlaces allows you to set the preferred amount of decimal places e.g. decimalPlaces = 1 --> 15.5g or decimalPlaces = 2 --> 15.55g
98+
99+
## Limitations
100+
101+
This Software is provided as-is!
102+
103+
Please feel free to adapt it to your needs and contribute to the project. I would be very grateful to include your improvements. Thanks for your support!
104+
105+
**WARNING:** Everyone is responsible for what he/she is doing! I am not responsible if you hurt yourself, torch your house or anything that kind trying to do build something new! You are doing everything at your own risk!

assets/principle.png

159 KB
Loading

0 commit comments

Comments
 (0)