-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChopFiller_Calibaration_LoadCell.txt
92 lines (80 loc) · 2.07 KB
/
ChopFiller_Calibaration_LoadCell.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "HX711.h"
#define DAT 2
#define CLK 3
HX711 scale;
long int calibration_factor = 5050,
prev_calibration_factor =0,
known_mass=0,
read_mass,
flag=0,
state =1,
bytestr;
char
str[100];
void readingFunc()
{
while(known_mass==0) { while (Serial.available()>0) {
bytestr = Serial.readBytesUntil('\0',str,10);
str[bytestr] = '\0';
sscanf(str,"%d",&known_mass);
}}}
void setup()
{
Serial.begin(9600);
scale.begin(DAT, CLK);
scale.set_scale();
Serial.println("Remove all weight from scale");
Serial.println("Wait, reset scale...");
scale.tare(); //Reset the scale to 0
delay(500);
Serial.println("Place your Mass..");
Serial.println("Then Write the weight of this mass in grams");
readingFunc();
long zero_factor = scale.read_average();
Serial.print("Zero factor: ");
Serial.println(zero_factor);
}
void loop() {
switch (state)
{
case 0:
Serial.print("Final calibration factor is: ");
Serial.println(prev_calibration_factor);
delay(500);
Serial.println("Try again with another mass, Write the weight of this mass in grams..");
known_mass=0;
prev_calibration_factor=0;
state=1;
readingFunc();
break;
case 1:
scale.set_scale(calibration_factor);
Serial.print("Target: ");
Serial.print(known_mass);
Serial.print(" Reading: ");
Serial.print(scale.get_units());
Serial.print(" g");
Serial.print(" calibration_factor: ");
Serial.print(calibration_factor);
Serial.println();
if (Serial.available() > 0)
{
bytestr = Serial.readBytesUntil('\0',str,10);
str[bytestr] = '\0';
sscanf(str,"%d",&known_mass);
if(known_mass==0){state=0; break;}
}
read_mass=scale.get_units();
if(known_mass!=0){
if(known_mass<read_mass) {calibration_factor += 10;}
else if (known_mass>read_mass) {calibration_factor -= 10;}
}
if(prev_calibration_factor==calibration_factor)
{
state=0;
}
prev_calibration_factor = calibration_factor;
delay(10);
break;
}
}