From e3650ea51c3ff616cc132351601127508e5a90b3 Mon Sep 17 00:00:00 2001 From: el3ctrician Date: Fri, 28 Sep 2018 12:36:53 +0200 Subject: [PATCH 1/3] added keywords.txt --- keywords.txt | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 keywords.txt diff --git a/keywords.txt b/keywords.txt new file mode 100644 index 0000000..c0a5369 --- /dev/null +++ b/keywords.txt @@ -0,0 +1,30 @@ +####################################### +# HX711 +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +HX711 KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +is_ready KEYWORD2 +set_gain KEYWORD2 +read_average KEYWORD2 +get_value KEYWORD2 +get_units KEYWORD2 +tare KEYWORD2 +set_scale KEYWORD2 +get_scale KEYWORD2 +set_offset KEYWORD2 +get_offset KEYWORD2 +power_down KEYWORD2 +power_up KEYWORD2 + +####################################### +# Constants (LITERAL1) +####################################### \ No newline at end of file From 77863aa3877daad11e2d39eccb130dfe3782e666 Mon Sep 17 00:00:00 2001 From: el3ctrician Date: Tue, 9 Oct 2018 16:51:49 +0200 Subject: [PATCH 2/3] more stable esp8266 specific code --- HX711.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/HX711.cpp b/HX711.cpp index c80524e..c3f67cc 100644 --- a/HX711.cpp +++ b/HX711.cpp @@ -1,14 +1,18 @@ #include #include -#if ARDUINO_VERSION <= 106 +#ifndef ESP8266 + #if ARDUINO_VERSION <= 106 // "yield" is not implemented as noop in older Arduino Core releases, so let's define it. // See also: https://stackoverflow.com/questions/34497758/what-is-the-secret-of-the-arduino-yieldfunction/34498165#34498165 - void yield(void) {}; + void yield(void) {}; + #endif #endif HX711::HX711(byte dout, byte pd_sck, byte gain) { + #ifndef ESP8266 begin(dout, pd_sck, gain); + #endif } HX711::HX711() { From efcf6abb180f156f193dcf7172dcabd28460fc73 Mon Sep 17 00:00:00 2001 From: el3ctrician Date: Tue, 9 Oct 2018 16:52:03 +0200 Subject: [PATCH 3/3] example for esp8266 special case --- examples/HX711ESP8266/HX711ESP8266.ino | 58 ++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 examples/HX711ESP8266/HX711ESP8266.ino diff --git a/examples/HX711ESP8266/HX711ESP8266.ino b/examples/HX711ESP8266/HX711ESP8266.ino new file mode 100644 index 0000000..3d2022b --- /dev/null +++ b/examples/HX711ESP8266/HX711ESP8266.ino @@ -0,0 +1,58 @@ +#include "HX711.h" + +// HX711.DOUT - pin #D2 +// HX711.PD_SCK - pin #D3 + +HX711 scale(D2, D3); // parameter "gain" is ommited; the default value 128 is used by the library + +void setup() { + Serial.begin(38400); + // usually the begin method is called by the class builder but in case of esp8266 must be called explicitly in the setup + scale.begin(D2,D3); //esp specific statment + Serial.println("HX711 Demo"); + + 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(); +} \ No newline at end of file