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
Pri záujme o kúpu webovej časti kontaktujte na: martinius96@gmail.com

Offline tester - Arduino + HX711


/**
 *
 * HX711 library for Arduino - example file
 * https://github.com/bogde/HX711
 *
 * MIT License
 * (c) 2018 Bogdan Necula
 *
**/
#include "HX711.h"


// HX711 circuit wiring
const int LOADCELL_DOUT_PIN = 2;
const int LOADCELL_SCK_PIN = 3;


HX711 scale;

void setup() {
  Serial.begin(115200);
  Serial.println("HX711 Demo");

  Serial.println("Initializing the scale");

  // Initialize library with data output pin, clock input pin and gain factor.
  // Channel selection is made by passing the appropriate gain:
  // - With a gain factor of 64 or 128, channel A is selected
  // - With a gain factor of 32, channel B is selected
  // By omitting the gain factor parameter, the library
  // default "128" (Channel A) is used here.
  scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);

  Serial.println("Before setting up the scale:");
  Serial.print("read: \t\t");
  Serial.println(scale.read());			// print a raw reading from the ADC

  Serial.print("read average: \t\t");
  Serial.println(scale.read_average(20));  	// print the average of 20 readings from the ADC

  Serial.print("get value: \t\t");
  Serial.println(scale.get_value(5));		// print the average of 5 readings from the ADC minus the tare weight (not set yet)

  Serial.print("get units: \t\t");
  Serial.println(scale.get_units(5), 1);	// print the average of 5 readings from the ADC minus tare weight (not set) divided
						// by the SCALE parameter (not set yet)

  scale.set_scale(2280.f);                      // this value is obtained by calibrating the scale with known weights; see the README for details
  scale.tare();				        // reset the scale to 0

  Serial.println("After setting up the scale:");

  Serial.print("read: \t\t");
  Serial.println(scale.read());                 // print a raw reading from the ADC

  Serial.print("read average: \t\t");
  Serial.println(scale.read_average(20));       // print the average of 20 readings from the ADC

  Serial.print("get value: \t\t");
  Serial.println(scale.get_value(5));		// print the average of 5 readings from the ADC minus the tare weight, set with tare()

  Serial.print("get units: \t\t");
  Serial.println(scale.get_units(5), 1);        // print the average of 5 readings from the ADC minus tare weight, divided
						// by the SCALE parameter set with set_scale

  Serial.println("Readings:");
}

void loop() {
  Serial.print("one reading:\t");
  Serial.print(scale.get_units(), 1);
  Serial.print("\t| average:\t");
  Serial.println(scale.get_units(10), 1);

  scale.power_down();			        // put the ADC in sleep mode
  delay(5000);
  scale.power_up();
}
  


Zdrojový kód - Ethernet W5100 - HTTP


  
/*|---------------------------------|*/
/*|Projekt: Včelárska váha          |*/
/*|Prenos: Ethernet Wiznet W5100    |*/
/*|Autor: Martin Chlebovec          |*/
/*|E-mail: martinius96@gmail.com    |*/
/*|Web: https://arduino.php5.sk     |*/
/*|Licencia pouzitia: MIT           |*/
/*|---------------------------------|*/

#include <avr\wdt.h>
#include <SPI.h>
#include <Ethernet.h>
#include "HX711.h"
const int LOADCELL_DOUT_PIN = 2;
const int LOADCELL_SCK_PIN = 3;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
const char * host = "www.arduino.php5.sk";
IPAddress ip(192, 168, 1, 101);
EthernetClient client;
HX711 scale;
void setup() {
  Serial.begin(115200);
  scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);

  Serial.println("Before setting up the scale:");
  Serial.print("read: \t\t");
  Serial.println(scale.read());      //raw from ADC

  Serial.print("read average: \t\t");
  Serial.println(scale.read_average(20));   //average of 20 readings from the ADC

  Serial.print("get value: \t\t");
  Serial.println(scale.get_value(5));   //average of 5 readings from the ADC

  Serial.print("get units: \t\t");
  Serial.println(scale.get_units(5), 1);  //average of 5 readings from the ADC
  // by the SCALE parameter (not set yet)

  scale.set_scale(2280.f);  // this value is obtained by calibrating the scale with known weights; see the README for details
  scale.tare();  // reset the scale to 0

  Serial.println("After setting up the scale:");

  Serial.print("read: \t\t");
  Serial.println(scale.read());                 //raw reading from ADC

  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() {
  wdt_reset();
  float hodnota = scale.get_units(10);
  String hodnota_odosielanie = String(hodnota);
  delay(50);
  client.stop();
  String data = "hodnota=" + hodnota_odosielanie;
  String url = "/vaha/data.php";
  if (client.connect(host, 80)) {
    Serial.println("PRIPOJENIE NA WEBSERVER USPESNE");
    client.println("POST " + url + " HTTP/1.0");
    client.println("Host: " + (String)host);
    client.println("User-Agent: ArduinoEthernetW5100");
    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);
    while (client.connected()) {
      String line = client.readStringUntil('\n');
      if (line == "\r") {
        break;
      }
    }
    String line = client.readStringUntil('\n');
    if (line == "OK") {
      Serial.println("DATA USPESNE ZAPISANE DO DATABAZY");
    } else {
        Serial.println("PROBLEM SO ZAPISOM DO DATABAZY");
      }
    } else {
      Serial.println("PROBLEM S PRIPOJENIM NA WEBSERVER");
    }
    scale.power_down();
    for (int i = 0; i <= 300; i++) {
      delay(1000);
      wdt_reset();
    }
    scale.power_up();
  }

Zdrojový kód - Ethernet W5500 - HTTP


  
/*|---------------------------------|*/
/*|Projekt: Včelárska váha          |*/
/*|Prenos: Ethernet Wiznet W5500    |*/
/*|Autor: Martin Chlebovec          |*/
/*|E-mail: martinius96@gmail.com    |*/
/*|Web: https://arduino.php5.sk     |*/
/*|Licencia pouzitia: MIT           |*/
/*|---------------------------------|*/

#include <avr\wdt.h>
#include <SPI.h>
#include <Ethernet2.h>
#include "HX711.h"
const int LOADCELL_DOUT_PIN = 2;
const int LOADCELL_SCK_PIN = 3;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
const char * host = "www.arduino.php5.sk";
IPAddress ip(192, 168, 1, 101);
EthernetClient client;
HX711 scale;
void setup() {
  Serial.begin(115200);
  scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);

  Serial.println("Before setting up the scale:");
  Serial.print("read: \t\t");
  Serial.println(scale.read());      //raw from ADC

  Serial.print("read average: \t\t");
  Serial.println(scale.read_average(20));   //average of 20 readings from the ADC

  Serial.print("get value: \t\t");
  Serial.println(scale.get_value(5));   //average of 5 readings from the ADC

  Serial.print("get units: \t\t");
  Serial.println(scale.get_units(5), 1);  //average of 5 readings from the ADC
  // by the SCALE parameter (not set yet)

  scale.set_scale(2280.f);  // this value is obtained by calibrating the scale with known weights; see the README for details
  scale.tare();  // reset the scale to 0

  Serial.println("After setting up the scale:");

  Serial.print("read: \t\t");
  Serial.println(scale.read());                 //raw reading from ADC

  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() {
  wdt_reset();
  float hodnota = scale.get_units(10);
  String hodnota_odosielanie = String(hodnota);
  delay(50);
  client.stop();
  String data = "hodnota=" + hodnota_odosielanie;
  String url = "/vaha/data.php";
  if (client.connect(host, 80)) {
    Serial.println("PRIPOJENIE NA WEBSERVER USPESNE");
    client.println("POST " + url + " HTTP/1.0");
    client.println("Host: " + (String)host);
    client.println("User-Agent: ArduinoEthernetW5500");
    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);
    while (client.connected()) {
      String line = client.readStringUntil('\n');
      if (line == "\r") {
        break;
      }
    }
    String line = client.readStringUntil('\n');
    if (line == "OK") {
      Serial.println("DATA USPESNE ZAPISANE DO DATABAZY");
    } else {
        Serial.println("PROBLEM SO ZAPISOM DO DATABAZY");
      }
    } else {
      Serial.println("PROBLEM S PRIPOJENIM NA WEBSERVER");
    }
    scale.power_down();
    for (int i = 0; i <= 300; i++) {
      delay(1000);
      wdt_reset();
    }
    scale.power_up();
  }