ACM txt out

Dependencies:   mbed HX711_3

Committer:
j8813
Date:
Thu Feb 28 03:36:09 2019 +0000
Revision:
0:2d84c250f000
ACM txt out

Who changed what in which revision?

UserRevisionLine numberNew contents of line
j8813 0:2d84c250f000 1 #include "mbed.h"
j8813 0:2d84c250f000 2 #include "HX711.h"
j8813 0:2d84c250f000 3
j8813 0:2d84c250f000 4 DigitalOut gpo(D0);
j8813 0:2d84c250f000 5 //DigitalOut led(LED_BLUE);
j8813 0:2d84c250f000 6 DigitalOut led(LED1);
j8813 0:2d84c250f000 7
j8813 0:2d84c250f000 8 HX711 scale(p6,p7);
j8813 0:2d84c250f000 9
j8813 0:2d84c250f000 10 AnalogIn scaleRaw(A3);
j8813 0:2d84c250f000 11 Serial pc(USBTX, USBRX); // USB Serial Terminal
j8813 0:2d84c250f000 12 float calibration_factor = 1.000; //-7050 worked for my 440lb max scale setup
j8813 0:2d84c250f000 13 int averageSamples = 100;
j8813 0:2d84c250f000 14
j8813 0:2d84c250f000 15 LocalFileSystem local("local"); // Create the local filesystem under the name "local"
j8813 0:2d84c250f000 16
j8813 0:2d84c250f000 17 int i;
j8813 0:2d84c250f000 18
j8813 0:2d84c250f000 19 int main(void)
j8813 0:2d84c250f000 20 {
j8813 0:2d84c250f000 21 // pc.printf("Starting Scale");
j8813 0:2d84c250f000 22 // pc.printf("HX711 calibration sketch");
j8813 0:2d84c250f000 23 // pc.printf("Remove all weight from scale");
j8813 0:2d84c250f000 24 // pc.printf("After readings begin, place known weight on scale");
j8813 0:2d84c250f000 25 // pc.printf("Press + or a to increase calibration factor");
j8813 0:2d84c250f000 26 // pc.printf("Press - or z to decrease calibration factor");
j8813 0:2d84c250f000 27
j8813 0:2d84c250f000 28
j8813 0:2d84c250f000 29 scale.setScale(0);
j8813 0:2d84c250f000 30 scale.tare(); //Reset the scale to 0
j8813 0:2d84c250f000 31
j8813 0:2d84c250f000 32 long zero_factor = scale.averageValue(averageSamples); //Get a baseline reading
j8813 0:2d84c250f000 33 // pc.printf("Zero factor: %.4f\n" , zero_factor); //This can be used to remove the need to tare the scale. Useful in permanent scale projects.
j8813 0:2d84c250f000 34
j8813 0:2d84c250f000 35 //while (true) {
j8813 0:2d84c250f000 36 scale.setScale(calibration_factor); //Adjust to this calibration factor
j8813 0:2d84c250f000 37 float weight = scale.getGram();
j8813 0:2d84c250f000 38 // pc.printf(" %5.3e\n", weight);
j8813 0:2d84c250f000 39
j8813 0:2d84c250f000 40 FILE *fp = fopen("/local/out.txt", "w"); // Open "out.txt" on the local file system for writing
j8813 0:2d84c250f000 41 fprintf(fp, " %5.3e\n", weight);
j8813 0:2d84c250f000 42 fclose(fp);
j8813 0:2d84c250f000 43
j8813 0:2d84c250f000 44
j8813 0:2d84c250f000 45 gpo = !gpo; // toggle pin
j8813 0:2d84c250f000 46 led = !led; // toggle led
j8813 0:2d84c250f000 47 wait(0.2f);
j8813 0:2d84c250f000 48 // }
j8813 0:2d84c250f000 49 }