Knižnica pre HX711: Github - HX711
Stiahnutý archív rozbaliť a importovať do zložky (Win 10): Dokumenty/Arduino/libraries, (Win 7): Program Files/Arduino/libraries
Kontakt: martinius96@gmail.com

Na tejto stránke nájdete:

  • Zdrojové kódy pre platformu Arduino s Ethernet shieldom / modulom Wiznet W5100 / W5500, platformy ESP8266, ESP32 ktoré odosielajú dáta na túto webovú lokalitu.
  • Testovací sketch pre ladenie a kalibráciu váhy v režime jemného ladenia po desatinách kalibračnej konštanty.
  • Testovací sketch obsahuje aj výpis offsetu, ktorý je použitý v sketchoch s odosielaním pre tzv. režim continous váhy - váha sa nemusí kalibrovať a nulovať po výpadku elektriny.
  • Kombinácia Arduina s Ethernetom umožňuje posielať dáta po HTTP protokole. Platformy ESP32 a ESP8266 umožňujú komunikáciu s webserverom po HTTP / HTTPS protokole

  • Offline tester - Arduino + HX711 - načítanie offsetu, možnosť ladiť kalibráciu cez UART monitor


    #include "HX711.h"
    
    #define DOUT  3
    #define CLK  2
    HX711 scale;
    
    float calibration_factor = -50.10; //KALIBRAČNÝ FAKTOR
    void setup() {
      scale.begin(DOUT, CLK);
      Serial.begin(115200);
      Serial.println("HX711 calibration sketch");
      Serial.println("Remove all weight from scale");
      Serial.println("After readings begin, place known weight on scale");
      Serial.println("Press + or a to increase calibration factor");
      Serial.println("Press - or z to decrease calibration factor");
    
      scale.set_scale();
      scale.tare(); //Reset the scale to 0
    
      long zero_factor = scale.read_average(); //Get a baseline reading
      Serial.print("Zero factor: "); //This can be used to remove the need to tare the scale. Useful in permanent scale projects.
      Serial.println(zero_factor);
    }
    
    void loop() {
      scale.set_scale(calibration_factor); //Adjust to this calibration factor
      Serial.print("Reading: ");
      Serial.print(scale.get_units(10), 2);
      Serial.print(" g"); //Change this to kg and re-adjust the calibration factor if you follow SI units like a sane person
      Serial.print(" calibration_factor: ");
      Serial.print(calibration_factor);
      Serial.println();
    
      if (Serial.available())
      {
      //LADENIE
        char temp = Serial.read();
        if (temp == '+' || temp == 'a')
          calibration_factor += 0.1;
        else if (temp == '-' || temp == 'z')
          calibration_factor -= 0.1;
      }
    }
      

    HTTP - nešifrované spojenie


    HTTPZdrojový kód - Ethernet W5100 - HTTP - odosielanie na túto webovú lokalitu


      
    /*|----------------------------------|*/
    /*|Projekt: Včelárska váha           |*/
    /*|Hardvér: Arduino + Ethernet W5100 |*/
    /*|Autor: Martin Chlebovec           |*/
    /*|E-mail: martinius96@gmail.com     |*/
    /*|Web: https://arduino.php5.sk      |*/
    /*|Licencia pouzitia: MIT            |*/
    /*|Revízia: 14. Marec 2020           |*/
    /*|----------------------------------|*/
    
    #include <avr\wdt.h>
    #include <SPI.h>
    #include <Ethernet.h>
    #include "HX711.h"
    
    float calibration_factor = -50.10;
    unsigned long zero_factor =  -90709;
    byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
    char* host = "www.arduino.php5.sk";
    IPAddress ip(192, 168, 1, 101);
    EthernetClient client;
    #define DOUT  3
    #define CLK  2
    HX711 scale;
    void setup() {
      Serial.begin(115200);
      scale.begin(DOUT, CLK);
      scale.set_scale(calibration_factor); //This value is obtained by using the SparkFun_HX711_Calibration sketch
      scale.set_offset(zero_factor); //Zero out the scale using a previously known zero_factor
      if (Ethernet.begin(mac) == 0) {
        Serial.println("Failed to configure Ethernet using DHCP");
        Ethernet.begin(mac, ip);
      }
      Serial.print("HX711 ready");
      wdt_enable(WDTO_8S);
    }
    
    void loop() {
      if (Ethernet.begin(mac) == 0) {
        Serial.println("Failed to configure Ethernet using DHCP");
        Ethernet.begin(mac, ip);
      }
      wdt_reset();
      float hodnota = (scale.get_units(10), 2);
      String hodnota_odosielanie = String(hodnota);
      delay(50);
      wdt_reset();
      String data = "hodnota=" + hodnota_odosielanie;
      String url = "/vaha/data.php";
      if (client.connect(host, 80)) {
        client.println("POST " + url + " HTTP/1.0");
        client.println("Host: " + (String)host);
        client.println("User-Agent: EthernetW5100");
        client.println("Connection: close");
        client.println("Content-Type: application/x-www-form-urlencoded;");
        client.print("Content-Length: ");
        client.println(data.length());
        client.println();
        client.println(data);
        Serial.println("Data uspesne odoslane na web");
      } else {
        Serial.println("Pripojenie zlyhalo...");
      }
      client.stop();
      scale.power_down();
      for (int i = 0; i <= 300; i++) {
        delay(1000);
        wdt_reset();
      }
      scale.power_up();
    }
    

    HTTPZdrojový kód - Ethernet W5500 - HTTP - odosielanie na túto webovú lokalitu


      
    /*|----------------------------------|*/
    /*|Projekt: Včelárska váha           |*/
    /*|Hardvér: Arduino + Ethernet W5500 |*/
    /*|Autor: Martin Chlebovec           |*/
    /*|E-mail: martinius96@gmail.com     |*/
    /*|Web: https://arduino.php5.sk      |*/
    /*|Licencia pouzitia: MIT            |*/
    /*|Revízia: 14. Marec 2020           |*/
    /*|----------------------------------|*/
    
    #include <avr\wdt.h>
    #include <SPI.h>
    #include <Ethernet2.h>
    #include "HX711.h"
    
    float calibration_factor = -50.10;
    unsigned long zero_factor =  -90709;
    byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
    char* host = "www.arduino.php5.sk";
    IPAddress ip(192, 168, 1, 101);
    EthernetClient client;
    #define DOUT  3
    #define CLK  2
    HX711 scale;
    void setup() {
      Serial.begin(115200);
      scale.begin(DOUT, CLK);
      scale.set_scale(calibration_factor); //This value is obtained by using the SparkFun_HX711_Calibration sketch
      scale.set_offset(zero_factor); //Zero out the scale using a previously known zero_factor
      if (Ethernet.begin(mac) == 0) {
        Serial.println("Failed to configure Ethernet using DHCP");
        Ethernet.begin(mac, ip);
      }
      Serial.print("HX711 ready");
      wdt_enable(WDTO_8S);
    }
    
    void loop() {
      if (Ethernet.begin(mac) == 0) {
        Serial.println("Failed to configure Ethernet using DHCP");
        Ethernet.begin(mac, ip);
      }
      wdt_reset();
      float hodnota = (scale.get_units(10), 2);
      String hodnota_odosielanie = String(hodnota);
      delay(50);
      wdt_reset();
      String data = "hodnota=" + hodnota_odosielanie;
      String url = "/vaha/data.php";
      if (client.connect(host, 80)) {
        client.println("POST " + url + " HTTP/1.0");
        client.println("Host: " + (String)host);
        client.println("User-Agent: EthernetW5500");
        client.println("Connection: close");
        client.println("Content-Type: application/x-www-form-urlencoded;");
        client.print("Content-Length: ");
        client.println(data.length());
        client.println();
        client.println(data);
        Serial.println("Data uspesne odoslane na web");
      } else {
        Serial.println("Pripojenie zlyhalo...");
      }
      client.stop();
      scale.power_down();
      for (int i = 0; i <= 300; i++) {
        delay(1000);
        wdt_reset();
      }
      scale.power_up();
    }
    

    HTTPZdrojový kód - NodeMCU / Wemos D1 Mini (ESP8266) - HTTP - odosielanie na túto webovú lokalitu


      
    /*|----------------------------------|*/
    /*|Projekt: Včelárska váha           |*/
    /*|Hardvér: NodeMCU v3 (ESP8266)     |*/
    /*|Autor: Martin Chlebovec           |*/
    /*|E-mail: martinius96@gmail.com     |*/
    /*|Web: https://arduino.php5.sk      |*/
    /*|Licencia pouzitia: MIT            |*/
    /*|Revízia: 15. Marec 2020           |*/
    /*|----------------------------------|*/
    
    #include <ESP8266WiFi.h>
    #include "HX711.h"
    
    float calibration_factor = -50.10;
    unsigned long zero_factor =  -90709;
    const char * ssid = "WIFI_MENO";
    const char * password = "WIFI_HESLO";
    const char * host = "www.arduino.php5.sk"; //bez https a www
    const int httpPort = 80; //https port
    #define DOUT  5
    #define CLK  4
    HX711 scale;
    WiFiClient client;
    void setup() {
      Serial.begin(115200);
      scale.begin(DOUT, CLK);
      scale.set_scale(calibration_factor); //This value is obtained by using the SparkFun_HX711_Calibration sketch
      scale.set_offset(zero_factor); //Zero out the scale using a previously known zero_factor
      WiFi.begin(ssid, password);
      while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
      }
      Serial.println("");
      Serial.println("WiFi uspesne pripojene");
      Serial.println("IP adresa: ");
      Serial.println(WiFi.localIP());
      Serial.println("HX711 ready");
    }
    
    void loop() {
      float hodnota = (scale.get_units(10), 2);
      String hodnota_odosielanie = String(hodnota);
      delay(50);
      client.stop();
      String data = "hodnota=" + hodnota_odosielanie;
      String url = "/vaha/data.php";
      if (client.connect(host, httpPort)) {
        client.println("POST " + url + " HTTP/1.0");
        client.println("Host: " + (String)host);
        client.println("User-Agent: ESP8266");
        client.println("Connection: close");
        client.println("Content-Type: application/x-www-form-urlencoded;");
        client.print("Content-Length: ");
        client.println(data.length());
        client.println();
        client.println(data);
        Serial.println("Data uspesne odoslane na webserver");
        while (client.connected()) {
          String line = client.readStringUntil('\n');
          Serial.println(line);
          if (line == "\r") {
            break;
          }
        }
        String line = client.readStringUntil('\n');
      } else {
        Serial.println("Problem s pripojenim na webserver");
      }
      client.stop();
      scale.power_down();
      for (int i = 0; i <= 300; i++) {
        delay(1000);
      }
      scale.power_up();
    }
    

    HTTPZdrojový kód - ESP32 DevKit - HTTP - odosielanie na túto webovú lokalitu


      
    /*|----------------------------------|*/
    /*|Projekt: Včelárska váha           |*/
    /*|Hardvér: ESP32 (DevKit)           |*/
    /*|Autor: Martin Chlebovec           |*/
    /*|E-mail: martinius96@gmail.com     |*/
    /*|Web: https://arduino.php5.sk      |*/
    /*|Licencia pouzitia: MIT            |*/
    /*|Revízia: 14. Marec 2020           |*/
    /*|----------------------------------|*/
    
    #include <WiFi.h>
    #include <WiFiClientSecure.h>
    #include "HX711.h"
    
    float calibration_factor = -50.10;
    unsigned long zero_factor =  -90709;
    
    const char * ssid = "WIFI_MENO";
    const char * password = "WIFI_HESLO";
    const char * host = "www.arduino.php5.sk";
    const int httpPort = 80; //http port
    
    WiFiClient client;
    #define DOUT  23
    #define CLK  22
    HX711 scale;
    void setup() {
      scale.begin(DOUT, CLK);
      scale.set_scale(calibration_factor); //This value is obtained by using the SparkFun_HX711_Calibration sketch
      scale.set_offset(zero_factor); //Zero out the scale using a previously known zero_factor
      Serial.begin(115200);
      WiFi.begin(ssid, password);
      while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
      }
      Serial.println("");
      Serial.println("WiFi uspesne pripojene");
      Serial.println("IP adresa: ");
      Serial.println(WiFi.localIP());
      Serial.println("HX711 Ready");
    }
    
    void loop() {
      if (WiFi.status() != WL_CONNECTED) {
        WiFi.begin(ssid, password);
      }
      while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
      }
      float hodnota = (scale.get_units(10), 2);
      String hodnota_odosielanie = String(hodnota);
      String data = "hodnota=" + hodnota_odosielanie;
      String url = "/vaha/data.php";
      client.stop();
      if (client.connect(host, httpPort)) {
        client.println("POST " + url + " HTTP/1.0");
        client.println("Host: " + (String)host);
        client.println("User-Agent: ESP32");
        client.println("Connection: close");
        client.println("Content-Type: application/x-www-form-urlencoded;");
        client.print("Content-Length: ");
        client.println(data.length());
        client.println();
        client.println(data);
        Serial.println("Data uspesne odoslane na webserver");
        while (client.connected()) {
          String line = client.readStringUntil('\n');
          if (line == "\r") {
            break;
          }
        }
        String line = client.readStringUntil('\n');
      } else {
        Serial.println("Nepodarilo sa pripojit na webserver");
      }
      client.stop();
      scale.power_down();
      for (int i = 0; i <= 300; i++) {
        delay(1000);
      }
      scale.power_up();
    }
    

    HTTPS - šifrované spojenie


    HTTPSZdrojový kód - NodeMCU / Wemos D1 Mini (ESP8266) - HTTPS - odosielanie na túto webovú lokalitu


      
    /*|----------------------------------|*/
    /*|Projekt: Včelárska váha           |*/
    /*|Hardvér: NodeMCU v3 (ESP8266)     |*/
    /*|Autor: Martin Chlebovec           |*/
    /*|E-mail: martinius96@gmail.com     |*/
    /*|Web: https://arduino.php5.sk      |*/
    /*|Licencia pouzitia: MIT            |*/
    /*|Revízia: 14. Marec 2020           |*/
    /*|----------------------------------|*/
    
    #include <ESP8266WiFi.h>
    #include <WiFiClientSecure.h>
    #include "HX711.h"
    
    float calibration_factor = -50.10;
    unsigned long zero_factor =  -90709;
    const char * ssid = "MENO_WIFI";
    const char * password = "HESLO_WIFI";
    const char * host = "arduino.php5.sk"; //bez https a www
    const int httpsPort = 443; //https port
    const char fingerprint[] PROGMEM = "00 2c c1 3a 3c fd a2 0a a3 f1 19 1a ee ee 54 72 93 56 7d 1b";
    #define DOUT  5
    #define CLK  4
    HX711 scale;
    void setup() {
      Serial.begin(115200);
      scale.begin(DOUT, CLK);
      scale.set_scale(calibration_factor); //This value is obtained by using the SparkFun_HX711_Calibration sketch
      scale.set_offset(zero_factor); //Zero out the scale using a previously known zero_factor
      WiFi.begin(ssid, password);
      while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
      }
      Serial.println("");
      Serial.println("WiFi uspesne pripojene");
      Serial.println("IP adresa: ");
      Serial.println(WiFi.localIP());
      Serial.println("HX711 ready");
    }
    
    void loop() {
      float hodnota = (scale.get_units(10), 2);
      String hodnota_odosielanie = String(hodnota);
      delay(50);
      WiFiClientSecure client;
      Serial.printf("Using fingerprint '%s'\n", fingerprint);
      client.setFingerprint(fingerprint);
      String data = "hodnota=" + hodnota_odosielanie;
      String url = "/vaha/data.php";
      if (client.connect(host, httpsPort)) {
        client.println("POST " + url + " HTTP/1.0");
        client.println("Host: " + (String)host);
        client.println("User-Agent: ESP8266");
        client.println("Connection: close");
        client.println("Content-Type: application/x-www-form-urlencoded;");
        client.print("Content-Length: ");
        client.println(data.length());
        client.println();
        client.println(data);
        Serial.println("Data uspesne odoslane na webserver"); while (client.connected()) {
          String line = client.readStringUntil('\n');
          if (line == "\r") {
            break;
          }
        }
        String line = client.readStringUntil('\n');
      } else {
        Serial.println("Problem s pripojenim na webserver");
      }
      client.stop();
      scale.power_down();
      for (int i = 0; i <= 300; i++) {
        delay(1000);
      }
      scale.power_up();
    }
    

    HTTPSZdrojový kód - ESP32 DevKit - HTTPS - odosielanie na túto webovú lokalitu


      
    /*|----------------------------------|*/
    /*|Projekt: Včelárska váha           |*/
    /*|Hardvér: ESP32 (DevKit)           |*/
    /*|Autor: Martin Chlebovec           |*/
    /*|E-mail: martinius96@gmail.com     |*/
    /*|Web: https://arduino.php5.sk      |*/
    /*|Licencia pouzitia: MIT            |*/
    /*|Revízia: 14. Marec 2020           |*/
    /*|----------------------------------|*/
    
    #include <WiFi.h>
    #include <WiFiClientSecure.h>
    #include "HX711.h"
    
    float calibration_factor = -50.10;
    unsigned long zero_factor =  -90709;
    
    const char * ssid = "WIFI_MENO";
    const char * password = "WIFI_HESLO";
    const char * host = "arduino.php5.sk";
    const int httpsPort = 443; //http port
    const char* test_root_ca = \
                               "-----BEGIN CERTIFICATE-----\n" \
                               "MIIEsTCCA5mgAwIBAgIQCKWiRs1LXIyD1wK0u6tTSTANBgkqhkiG9w0BAQsFADBh\n" \
                               "MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\n" \
                               "d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD\n" \
                               "QTAeFw0xNzExMDYxMjIzMzNaFw0yNzExMDYxMjIzMzNaMF4xCzAJBgNVBAYTAlVT\n" \
                               "MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j\n" \
                               "b20xHTAbBgNVBAMTFFJhcGlkU1NMIFJTQSBDQSAyMDE4MIIBIjANBgkqhkiG9w0B\n" \
                               "AQEFAAOCAQ8AMIIBCgKCAQEA5S2oihEo9nnpezoziDtx4WWLLCll/e0t1EYemE5n\n" \
                               "+MgP5viaHLy+VpHP+ndX5D18INIuuAV8wFq26KF5U0WNIZiQp6mLtIWjUeWDPA28\n" \
                               "OeyhTlj9TLk2beytbtFU6ypbpWUltmvY5V8ngspC7nFRNCjpfnDED2kRyJzO8yoK\n" \
                               "MFz4J4JE8N7NA1uJwUEFMUvHLs0scLoPZkKcewIRm1RV2AxmFQxJkdf7YN9Pckki\n" \
                               "f2Xgm3b48BZn0zf0qXsSeGu84ua9gwzjzI7tbTBjayTpT+/XpWuBVv6fvarI6bik\n" \
                               "KB859OSGQuw73XXgeuFwEPHTIRoUtkzu3/EQ+LtwznkkdQIDAQABo4IBZjCCAWIw\n" \
                               "HQYDVR0OBBYEFFPKF1n8a8ADIS8aruSqqByCVtp1MB8GA1UdIwQYMBaAFAPeUDVW\n" \
                               "0Uy7ZvCj4hsbw5eyPdFVMA4GA1UdDwEB/wQEAwIBhjAdBgNVHSUEFjAUBggrBgEF\n" \
                               "BQcDAQYIKwYBBQUHAwIwEgYDVR0TAQH/BAgwBgEB/wIBADA0BggrBgEFBQcBAQQo\n" \
                               "MCYwJAYIKwYBBQUHMAGGGGh0dHA6Ly9vY3NwLmRpZ2ljZXJ0LmNvbTBCBgNVHR8E\n" \
                               "OzA5MDegNaAzhjFodHRwOi8vY3JsMy5kaWdpY2VydC5jb20vRGlnaUNlcnRHbG9i\n" \
                               "YWxSb290Q0EuY3JsMGMGA1UdIARcMFowNwYJYIZIAYb9bAECMCowKAYIKwYBBQUH\n" \
                               "AgEWHGh0dHBzOi8vd3d3LmRpZ2ljZXJ0LmNvbS9DUFMwCwYJYIZIAYb9bAEBMAgG\n" \
                               "BmeBDAECATAIBgZngQwBAgIwDQYJKoZIhvcNAQELBQADggEBAH4jx/LKNW5ZklFc\n" \
                               "YWs8Ejbm0nyzKeZC2KOVYR7P8gevKyslWm4Xo4BSzKr235FsJ4aFt6yAiv1eY0tZ\n" \
                               "/ZN18bOGSGStoEc/JE4ocIzr8P5Mg11kRYHbmgYnr1Rxeki5mSeb39DGxTpJD4kG\n" \
                               "hs5lXNoo4conUiiJwKaqH7vh2baryd8pMISag83JUqyVGc2tWPpO0329/CWq2kry\n" \
                               "qv66OSMjwulUz0dXf4OHQasR7CNfIr+4KScc6ABlQ5RDF86PGeE6kdwSQkFiB/cQ\n" \
                               "ysNyq0jEDQTkfa2pjmuWtMCNbBnhFXBYejfubIhaUbEv2FOQB3dCav+FPg5eEveX\n" \
                               "TVyMnGo=\n" \
                               "-----END CERTIFICATE-----\n";
    WiFiClientSecure client;
    #define DOUT  23
    #define CLK  22
    HX711 scale;
    void setup() {
      scale.begin(DOUT, CLK);
      scale.set_scale(calibration_factor); //This value is obtained by using the SparkFun_HX711_Calibration sketch
      scale.set_offset(zero_factor); //Zero out the scale using a previously known zero_factor
      Serial.begin(115200);
      WiFi.begin(ssid, password);
      while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
      }
      client.setCACert(test_root_ca);
      Serial.println("");
      Serial.println("WiFi uspesne pripojene");
      Serial.println("IP adresa: ");
      Serial.println(WiFi.localIP());
      Serial.println("HX711 Ready");
    }
    
    void loop() {
      if (WiFi.status() != WL_CONNECTED) {
        WiFi.begin(ssid, password);
      }
      while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
      }
      float hodnota = (scale.get_units(10), 2);
      String hodnota_odosielanie = String(hodnota);
      String data = "hodnota=" + hodnota_odosielanie;
      String url = "/vaha/data.php";
      client.stop();
      if (client.connect(host, httpsPort)) {
        client.println("POST " + url + " HTTP/1.0");
        client.println("Host: " + (String)host);
        client.println("User-Agent: ESP32");
        client.println("Connection: close");
        client.println("Content-Type: application/x-www-form-urlencoded;");
        client.print("Content-Length: ");
        client.println(data.length());
        client.println();
        client.println(data);
        Serial.println("Data uspesne odoslane na webserver");
        while (client.connected()) {
          String line = client.readStringUntil('\n');
          if (line == "\r") {
            break;
          }
        }
        String line = client.readStringUntil('\n');
      } else {
        Serial.println("Nepodarilo sa pripojit na webserver");
      }
      client.stop();
      scale.power_down();
      for (int i = 0; i <= 300; i++) {
        delay(1000);
      }
      scale.power_up();
    }