Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions HX711.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
#include <Arduino.h>
#include <HX711.h>

#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() {
Expand Down
58 changes: 58 additions & 0 deletions examples/HX711ESP8266/HX711ESP8266.ino
Original file line number Diff line number Diff line change
@@ -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();
}
30 changes: 30 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
@@ -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)
#######################################