Hi
First project with Arduino and C coding. The project, a weighting system to evaluate residual quantity in a container.
I'm reading the weight value using HX711.h library
The problem is I'm loosing the weight after few hours and reading go back 0kg. I read that there is a shutoff mode where the HX711 go in low power mode after the CLK stay high for a given period.
Is there a way to keep the module up and running and not lose the weight information?
Martin
Note: The code is a work in progress. Some parts not debugged yet. But I got the problem since I first started with HX711
Note 2: Excuse for my bad English.
#include "HX711.h"
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x21,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
#define calibration_factor 16500.0 //This value is obtained using the SparkFun_HX711_Calibration sketch 5VDC
//#define calibration_factor 15350.0 //This value is obtained using the SparkFun_HX711_Calibration sketch 3.3 VDZ
#define DOUT 3
#define CLK 2
float weight;
int weight_read_step = 10;
int scale_wait_time =1000;
bool scale_in_wait_time = false;
byte _data; //KeySwitch
byte aButton;//KeySwitch
unsigned long previousMillis = 0;
const long interval = 1000;
long Poids;
int weight_count =0;
unsigned read_delay_time = 0;
int read_delay = 1000; //Read every 1 second
bool in_a_read_delay = false;
bool started_debounce = false;
int debounce = 15;
unsigned debounce_time = 0;
bool debounce_finish = false;
byte aButton_ = (0);
HX711 scale;
void setup() {
Serial.begin(115200);
//Key SwitchWire.begin();
Wire.beginTransmission(0x20);
Wire.write(0xff); // put a high level on pins
Wire.endTransmission();
Serial.println("HX711 scale demo");
scale.begin(DOUT, CLK);
scale.set_scale (calibration_factor); //(calibration_factor); //This value is obtained by using the SparkFun_HX711_Calibration sketch
scale.tare(); //Assuming there is no weight on the scale at start up, reset the scale to 0
lcd.init();
lcd.init();
lcd.setCursor(0,0);
lcd.print("Balance: ");
Serial.println("Readings:");
}
void loop() {
displayweight();
Button();
if (started_debounce == true){ a_debounce();}
if (aButton == 1) {(Button1);}
if (aButton == 3) {Serial.println(aButton);}
if (aButton == 4) {Serial.println(aButton);}
if (aButton == 5) {Serial.println(aButton);}
if (aButton == 6) {Serial.println(aButton);}
//Call reset
if (aButton == 7) {
lcd.setCursor(0,2);
lcd.print ("Reset");
delay(1000);
softReset();
}
aButton ==10;
//____________________
//Serial.print("Reading: ");
//Serial.print(scale.get_units(), 2); //scale.get_units() returns a float
//Serial.print(" kg"); //You can change this to kg but you'll need to refactor the calibration_factor
// Serial.println();
}
//Function______________________________________________
void displayweight(){ // will read
weight_count ++;
if (weight_count <weight_read_step){
scale.power_up();
weight = (weight + (scale.get_units()));
scale.power_down();
}
else {//weight_count >=6
weight_count = 0;
weight = (weight/weight_read_step);
lcd.setCursor(0,3);
lcd.print (weight,2);
lcd.print(" ");
lcd.print("kg");
lcd.print(" ");
}
}
byte Button(){
if (started_debounce == false){ // read key switch if not in a debounce
aButton = 0;
Wire.begin();
Wire.requestFrom(0x20, 1);
if(Wire.available()){
_data = Wire.read();
if(_data < 255){ // a button is pressed
Witch_Key();
started_debounce = true;
debounce_time = millis();
}
}
}
if (debounce_finish == true){
debounce_finish = false;
started_debounce = false;
aButton = aButton_;
}
}
// Witch_Key
void Witch_Key(){
if (_data ==254) aButton_=1;
if (_data ==251) aButton_=3;
if (_data ==247) aButton_=4;
if (_data ==239) aButton_=5;
if (_data ==223) aButton_=6;
if (_data ==191) aButton_=7;
}
void Button1(){
lcd.setCursor(0,1);
lcd.print("TARE");
scale.tare();
delay(1000);
lcd.setCursor(0,1);
lcd.print(" ");
}
//Reset
void softReset(){
asm volatile (" jmp 0");
}
//Base De Temp
void a_debounce(){
Serial.print("entering base_time");
if((unsigned long)(millis() - debounce_time) > debounce){
debounce_finish = true;
Serial.println("debounce finished");
}
}