kl25z with hx711 loadcell

Dependencies:   ESP8266 HX711 mbed

Files at this revision

API Documentation at this revision

Comitter:
padte
Date:
Mon Mar 20 13:11:21 2017 +0000
Commit message:
aa

Changed in this revision

ESP8266.lib Show annotated file Show diff for this revision Revisions of this file
HX711.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ESP8266.lib	Mon Mar 20 13:11:21 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/quevedo/code/ESP8266/#77388e8f0697
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HX711.lib	Mon Mar 20 13:11:21 2017 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/padte/code/HX711/#a2666eae3d06
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Mar 20 13:11:21 2017 +0000
@@ -0,0 +1,83 @@
+#include "mbed.h"
+#include "HX711.h"
+#include "ESP8266.h"
+
+ESP8266 esp(PTC4,PTC3,9600);
+DigitalIn hx711input(D5);
+DigitalOut green(LED2);
+DigitalOut red(LED1);
+Serial pc(USBTX, USBRX);    // USB Serial Terminal
+
+HX711 scale(D5,D13);
+char rs[100],rcv[100];
+int averageSamples = 100;
+float calibration_factor = 1000;
+int main(void)
+{
+    pc.baud(9600);
+    pc.printf("Starting Scale\r\n");
+    //wait(0.2f);
+   // pc.printf("HX711 calibration sketch\r\n");
+    //wait(0.2f);
+    pc.printf("Remove all weight from scale\r\n");
+    //wait(0.2f);
+    pc.printf("After readings begin, place known weight on scale\r\n");
+    //wait(0.2f);
+    
+      
+    scale.setScale(0);
+    scale.tare(); //Reset the scale to 0
+    
+    //long zero_factor = scale.averageValue(averageSamples); //Get a baseline reading
+   // pc.printf("Zero factor: %.4f\r\n" , zero_factor); //This can be used to remove the need to tare the scale. Useful in permanent scale projects.
+    
+     while (true) {
+          scale.setScale(calibration_factor); 
+         float weight = scale.getGram();
+         
+         
+        //float raw = scaleRaw.read();
+        if (weight >5 && weight <10)
+        weight = 50;
+        else if (weight >10 && weight <15)
+        weight = 100;
+        else if (weight >15 && weight <25)
+        weight = 100;
+        else if (weight >25 && weight <30)
+        weight = 200;
+        else if (weight >30 && weight <50)
+        weight = 300;
+        else if (weight >50 && weight <70)
+        weight = 400;
+        else if (weight >70 && weight <75)
+        weight = 500;
+        else if (weight >145 && weight <150)
+        weight = 1000;
+        
+        pc.printf("Reading: %.2f gms \r\n", weight);
+        pc.printf(" calibration_factor: %.2f\r\n", calibration_factor);
+        if(pc.readable()) {
+            char temp = pc.getc();
+            if(temp == '+' || temp == 'a')
+               calibration_factor += 10;
+            else if(temp == '-' || temp == 'z')
+                calibration_factor -= 10;
+            }
+       sprintf(rs,"&pr=%.3f", weight);
+       esp.SendCMD(rs);
+       esp.RcvReply(rcv, 1000);
+        //pc.printf("%s", rcv);
+        wait(1);
+       /* if(hx711input > 2000)
+        {
+            green = !green;
+            wait(0.2);
+        }
+        else 
+        {   red=!red;
+           wait(0.2);
+            }
+        //pc.printf("Raw Value: %.7f\n", raw);*/
+        // wait(0.2);
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Mar 20 13:11:21 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/e1686b8d5b90
\ No newline at end of file