Skip to content

Commit

Permalink
Release 1.1.0
Browse files Browse the repository at this point in the history
- Data set configuration (data set, number of samples) has been moved from HX711_ADC.h to the new file config.h
- Included "yield" in function tare() to avoid crash on ESP8266 if wiring is incorrect
- Timeout added to the tare() function to avoid endless loop if wiring is incorrect
- Added function getSingleConversionRaw() for testing and debugging purpose
- Added function getReadIndex() for testing and debugging purpose
- Added function getConversionTime() for testing and debugging purpose
- Added function getSPS() for testing and debugging purpose
- Added function getTareTimeoutFlag() for testing and debugging purpose
- Added example sketch "HX711_ADC_Calibration" with option to save the calibration value to eeprom
- Added example sketch "HX711_ADC_Testing" with some of the above mentioned functions for tare timeout, samplerate, conversion time, etc
- In example sketches setup, option included to fetch calibration value from eeprom
  • Loading branch information
olkal committed Dec 25, 2018
1 parent 79fa34e commit 463e006
Show file tree
Hide file tree
Showing 11 changed files with 447 additions and 111 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ Wires between HX711 and load cell should be twisted and kept as short as possibl
Most available HX711 modules seems to follow the reference design, but be aware that some modules are poorly designed with under-sized capacitors, and noisy readings.
The Sparkfun module seems to differ from most other available modules as it has some additional components for noise reduction.

Update 1.1.0:
- Data set configuration (data set, number of samples) has been moved from HX711_ADC.h to the new file config.h
- Included "yield" in function tare() to avoid crash on ESP8266 if wiring is incorrect
- Timeout added to the tare() function to avoid endless loop if wiring is incorrect
- Added function getSingleConversionRaw() for testing and debugging purpose
- Added function getReadIndex() for testing and debugging purpose
- Added function getConversionTime() for testing and debugging purpose
- Added function getSPS() for testing and debugging purpose
- Added function getTareTimeoutFlag() for testing and debugging purpose
- Added example sketch "HX711_ADC_Calibration" with option to save the calibration value to eeprom
- Added example sketch "HX711_ADC_Testing" with some of the above mentioned functions for tare timeout, samplerate, conversion time, etc
- In example sketches setup, option included to fetch calibration value from eeprom

Update 1.0.2:
- Implemented requested function setTareOffset(long newoffset)
- Initializing of the index counter in the class declaration: readIndex = 0
75 changes: 0 additions & 75 deletions examples/Calibrate/Calibrate.ino

This file was deleted.

185 changes: 185 additions & 0 deletions examples/Calibration/Calibration.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
//-------------------------------------------------------------------------------------
// HX711_ADC.h
// Arduino master library for HX711 24-Bit Analog-to-Digital Converter for Weigh Scales
// Olav Kallhovd sept2017
// Tested with : HX711 asian module on channel A and YZC-133 3kg load cell
// Tested with MCU : Arduino Nano, ESP8266
//-------------------------------------------------------------------------------------
// This is an example sketch on how to use this library
// Settling time (number of samples) and data filtering can be adjusted in the config.h file

// This example shows how to calibrate the load cell and optionally save the calibration
// value to EEPROM, and also how to change the value.
// The value can later be fetched from EEPROM in your project sketch.

#include <HX711_ADC.h>
#include <EEPROM.h>

//HX711 constructor (dout pin, sck pin):
HX711_ADC LoadCell(4, 5);

int eepromAdress = 0;

long t;

void calibrate() {
Serial.println("***");
Serial.println("Start calibration:");
Serial.println("It is assumed that the mcu was started with no load applied to the load cell.");
Serial.println("Now, place your known mass on the loadcell,");
Serial.println("then send the weight of this mass (i.e. 100.0) from serial monitor.");
float m = 0;
boolean f = 0;
while (f == 0) {
LoadCell.update();
if (Serial.available() > 0) {
m = Serial.parseFloat();
if (m != 0) {
Serial.print("Known mass is: ");
Serial.println(m);
f = 1;
}
else {
Serial.println("Invalid value");
}
}
}
float c = LoadCell.getData() / m;
LoadCell.setCalFactor(c);
Serial.print("Calculated calibration value is: ");
Serial.print(c);
Serial.println(", use this in your project sketch");
f = 0;
Serial.print("Save this value to EEPROM adress ");
Serial.print(eepromAdress);
Serial.println("? y/n");
while (f == 0) {
if (Serial.available() > 0) {
char inByte = Serial.read();
if (inByte == 'y') {
#if defined(ESP8266)
EEPROM.begin(sizeof c);
#endif
EEPROM.put(eepromAdress, c);
#if defined(ESP8266)
EEPROM.commit();
//EEPROM.begin(sizeof c);
#endif
EEPROM.get(eepromAdress, c);
Serial.print("Value ");
Serial.print(c);
Serial.print(" saved to EEPROM address: ");
Serial.println(eepromAdress);
f = 1;

}
else if (inByte == 'n') {
Serial.println("Value not saved to EEPROM");
f = 1;
}
}
}
Serial.println("End calibration");
Serial.println("For manual edit, send 'c' from serial monitor");
Serial.println("***");
}

void changeSavedCalFactor() {
float c = LoadCell.getCalFactor();
boolean f = 0;
Serial.println("***");
Serial.print("Current value is: ");
Serial.println(c);
Serial.println("Now, send the new value from serial monitor, i.e. 696.0");
while (f == 0) {
if (Serial.available() > 0) {
c = Serial.parseFloat();
if (c != 0) {
Serial.print("New calibration value is: ");
Serial.println(c);
LoadCell.setCalFactor(c);
f = 1;
}
else {
Serial.println("Invalid value, exit");
return;
}
}
}
f = 0;
Serial.print("Save this value to EEPROM adress ");
Serial.print(eepromAdress);
Serial.println("? y/n");
while (f == 0) {
if (Serial.available() > 0) {
char inByte = Serial.read();
if (inByte == 'y') {
#if defined(ESP8266)
EEPROM.begin(sizeof c);
#endif
EEPROM.put(eepromAdress, c);
#if defined(ESP8266)
EEPROM.commit();
//EEPROM.begin(sizeof c);
#endif
EEPROM.get(eepromAdress, c);
Serial.print("Value ");
Serial.print(c);
Serial.print(" saved to EEPROM address: ");
Serial.println(eepromAdress);
f = 1;
}
else if (inByte == 'n') {
Serial.println("Value not saved to EEPROM");
f = 1;
}
}
}
Serial.println("End change calibration value");
Serial.println("***");
}

void setup() {
Serial.begin(9600); delay(10);
Serial.println();
Serial.println("Starting...");
LoadCell.begin();
long stabilisingtime = 2000; // tare preciscion can be improved by adding a few seconds of stabilising time
LoadCell.start(stabilisingtime);
if (LoadCell.getTareTimeoutFlag()) {
Serial.println("Tare timeout, check MCU>HX711 wiring and pin designations");
}
else {
LoadCell.setCalFactor(1.0); // user set calibration value (float)
Serial.println("Startup + tare is complete");
}
while (!LoadCell.update());
calibrate();
}
void loop() {
//update() should be called at least as often as HX711 sample rate; >10Hz@10SPS, >80Hz@80SPS
//longer delay in sketch will reduce effective sample rate (be carefull with delay() in the loop)
LoadCell.update();

//get smoothed value from the data set
if (millis() > t + 250) {
float i = LoadCell.getData();
Serial.print("Load_cell output val: ");
Serial.println(i);
t = millis();
}

//receive from serial terminal
if (Serial.available() > 0) {
float i;
char inByte = Serial.read();
if (inByte == 't') LoadCell.tareNoDelay();
else if (inByte == 'c') changeSavedCalFactor();
}

//check if last tare operation is complete
if (LoadCell.getTareStatus() == true) {
Serial.println("Tare complete");
}

}
35 changes: 26 additions & 9 deletions examples/Read_1x_load_cell/Read_1x_load_cell.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,51 @@
// Arduino master library for HX711 24-Bit Analog-to-Digital Converter for Weigh Scales
// Olav Kallhovd sept2017
// Tested with : HX711 asian module on channel A and YZC-133 3kg load cell
// Tested with MCU : Arduino Nano
// Tested with MCU : Arduino Nano, ESP8266
//-------------------------------------------------------------------------------------
// This is an example sketch on how to use this library
// Settling time (number of samples) and data filtering can be adjusted in the HX711_ADC.h file
// Settling time (number of samples) and data filtering can be adjusted in the config.h file

#include <HX711_ADC.h>
#include <EEPROM.h>

//HX711 constructor (dout pin, sck pin)
//HX711 constructor (dout pin, sck pin):
HX711_ADC LoadCell(4, 5);

const int eepromAdress = 0;

long t;

void setup() {
Serial.begin(9600);
Serial.println("Wait...");

float calValue; // calibration value
calValue = 696.0; // uncomment this if you want to set this value in the sketch
#if defined(ESP8266)
//EEPROM.begin(sizeof calValue); // uncomment this if you use ESP8266 and want to fetch the value from eeprom
#endif
//EEPROM.get(eepromAdress, calValue); // uncomment this if you want to fetch the value from eeprom

Serial.begin(9600); delay(10);
Serial.println();
Serial.println("Starting...");
LoadCell.begin();
long stabilisingtime = 2000; // tare preciscion can be improved by adding a few seconds of stabilising time
LoadCell.start(stabilisingtime);
LoadCell.setCalFactor(696.0); // user set calibration factor (float)
Serial.println("Startup + tare is complete");
if(LoadCell.getTareTimeoutFlag()) {
Serial.println("Tare timeout, check MCU>HX711 wiring and pin designations");
}
else {
LoadCell.setCalFactor(calValue); // set calibration value (float)
Serial.println("Startup + tare is complete");
}
}

void loop() {
//update() should be called at least as often as HX711 sample rate; >10Hz@10SPS, >80Hz@80SPS
//longer delay in scetch will reduce effective sample rate (be carefull with delay() in loop)
//use of delay in sketch will reduce effective sample rate (be carefull with use of delay() in the loop)
LoadCell.update();

//get smoothed value from data set + current calibration factor
//get smoothed value from data set
if (millis() > t + 250) {
float i = LoadCell.getData();
Serial.print("Load_cell output val: ");
Expand Down
Loading

0 comments on commit 463e006

Please sign in to comment.