0

I am using the following code to check if the value is 0 e.g there is no weights placed and if so, it will ignore this value and do nothing with it. The code runs correctly but keeps outputting the following:

Soft WDT reset

stack>>>

ctx: cont sp: 3ffffd70 end: 3fffffc0 offset: 01b0 3fffff20: 00000050 00000000 31310010 36323439 3fffff30: 00000000 00000000 00000010 00000001 3fffff40: 3ffee408 00000000 00000000 40202927 3fffff50: 4022dff2 a0000000 bf2cc404 3ffe84dc 3fffff60: 3ffee408 bf2cc404 3ffee408 40202962 3fffff70: 3ffeeb9c 40202c00 3ffee408 40202996
3fffff80: 3ffee448 bf2cc404 3ffee408 40202664 3fffff90: 3fffdad0 fffe2d7e 3ffee448 3ffee4b0 3fffffa0: 3fffdad0 00000000 3ffee480 40203848 3fffffb0: feefeffe feefeffe 3ffe8514 40100a41
<<

If I remove if(reading < 0.01){ the code runs fine. What could be causing this?

#include "HX711.h"
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

#define DOUT  D3
#define CLK  D2
const char* ssid = "Curtis"; 
const char* password = "password";


HX711 scale(DOUT, CLK);
float calibration_factor = -118470; //-7050 worked for my 440lb max scale setup
void joinwifi(){
    WiFi.begin(ssid, password);
  Serial.println();
  Serial.print("Connecting");
   while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println("success!");
  Serial.print("IP Address is: ");
  Serial.println(WiFi.localIP());
}
void setup() {
  Serial.begin(9600);
  joinwifi();
  Serial.println("HX711 calibration sketch");
  Serial.println("Remove all weight from scale");
  Serial.println("After readings begin, place known weight on scale");
  Serial.println("Press + or a to increase calibration factor");
  Serial.println("Press - or z to decrease calibration factor");
  scale.set_scale();
  scale.tare(); //Reset the scale to 0
  long zero_factor = scale.read_average(); //Get a baseline reading
  Serial.print("Zero factor: "); //This can be used to remove the need to tare the scale. Useful in permanent scale projects.
  Serial.println(zero_factor);
}
void loop() {
  while (WiFi.status() == WL_CONNECTED)
  {
    scale.set_scale(calibration_factor); //Adjust to this calibration factor
    float reading = scale.get_units(1);
    if(reading < 0.01){
      Serial.print("no need");
       Serial.println();
    }
    else{
      Serial.print("Reading: ");
      Serial.print(reading);
      Serial.print(" lbs"); //Change this to kg and re-adjust the calibration factor if you follow SI units like a sane person
      Serial.print(" calibration_factor: ");
      Serial.print(calibration_factor);
      Serial.println();
      if(Serial.available())
      {
        char temp = Serial.read();
        if(temp == '+' || temp == 'a')
          calibration_factor += 10;
        else if(temp == '-' || temp == 'z')
          calibration_factor -= 10;
      }
    }
  }
  while (WiFi.status() != WL_CONNECTED)
  {
    joinwifi();
  }

}
2

Because your code is all running in a while inside your loop (which is redundant - loop() loops, hence its name), and you have no delays or yield() calls, you are not giving the watchdog the required kick that it needs to stay alive.

Either remove your whiles and turn them into ifs instead, or add yeild() calls inside your while loops.

  • @CurtisBoylan if it solves the issue then please accept Majenko's answer as the solution. – John Romkey Apr 23 at 16:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.