ESP8622 Restarts! WeMos D1 + HX711 + LCD

My respected gentlemen,

I have the following code where I am using WeMos D1 board + HX7111 Amp + Load Sensor + LCD
The following code runs fine (displaying everything on the screen, showing the WiFi Manager portal, connected and more)

But the issue i'm having is in the loop()

The moment the HX711 scale initiated and reading was attempted, ESP8266 (integrated) suddenly restarted.

I'm very new with Arduino and I dont understand what yield() / watchdog is doing to this code

I believe, if the wifi doesn't get restarted, everything will run super well (do note that the DB connection also working fine in my server DB)

/*
  Rui Santos
  Complete project details at https://RandomNerdTutorials.com/esp32-esp8266-mysql-database-php/
  
  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files.
  
  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.
*/

#ifdef ESP32
  #include <WiFi.h>
  #include <HTTPClient.h>
#else
  #include <ESP8266WiFi.h>
  #include <ESP8266HTTPClient.h>
  #include <WiFiClient.h>
#endif

#include <WiFiClientSecureBearSSL.h>

#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>



#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 18, 2);

#include "HX711.h"
// HX711 circuit wiring
const int LOADCELL_DOUT_PIN = D4;
const int LOADCELL_SCK_PIN = D5;

HX711 scale;

// Replace with your network credentials
const char* ssid     = "47B 2.4Ghz";
const char* password = "blt4397fuad";

// REPLACE with your Domain name and URL path or IP address with path
const char* serverName = "http://XXXXXXXXXX/writedata.php";

// Keep this API Key value to be compatible with the PHP code provided in the project page. 
// If you change the apiKeyValue value, the PHP file /post-esp-data.php also needs to have the same key 
String apiKeyValue = "XXXXXXXXXX";

int deviceID = 1;
float volume = 123.45;

void setup() {
  Serial.begin(115200);
}

void loop() {

  WiFiManager wifiManager;
  //wifiManager.resetSettings();

  Serial.begin(115200);
  wifiManager.autoConnect("Suu Balm Smart Sensor");
  Serial.println("Connected...");




  lcd.begin();
  lcd.backlight();
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Suu Balm");
  lcd.setCursor(0, 1);
  lcd.print("Smart Sensor");
  yield();
  delay(3000);
  

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Initializing...");
  lcd.setCursor(0, 1);
  lcd.print("Please wait");
  
  //WiFi.begin(ssid, password);
  Serial.println("Connecting");
  while(WiFi.status() != WL_CONNECTED) { 
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to WiFi network with IP Address: ");
  Serial.println(WiFi.localIP());

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("WiFi Connected!");
  lcd.setCursor(0, 1);
  lcd.print(WiFi.SSID());
  yield();
  delay(2000);



  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Dispense Now!");
  delay(1000); /// GIVE USER 1 minutes to apply product

  lcd.setCursor(0, 1);
  lcd.print("30");
  delay(1000); /// GIVE USER 1 minutes to apply product
  lcd.setCursor(0, 1);
  lcd.print("29");
  delay(1000); /// GIVE USER 1 minutes to apply product
  lcd.setCursor(0, 1);
  lcd.print("28");
  delay(1000); /// GIVE USER 1 minutes to apply product
  lcd.setCursor(0, 1);
  lcd.print("27");
  delay(1000); /// GIVE USER 1 minutes to apply product
  lcd.setCursor(0, 1);
  lcd.print("26");
  delay(1000); /// GIVE USER 1 minutes to apply product
  lcd.setCursor(0, 1);
  lcd.print("25");
  delay(1000); /// GIVE USER 1 minutes to apply product
  lcd.setCursor(0, 1);
  lcd.print("24");
  delay(1000); /// GIVE USER 1 minutes to apply product
  lcd.setCursor(0, 1);
  lcd.print("23");
  delay(1000); /// GIVE USER 1 minutes to apply product
  lcd.setCursor(0, 1);
  lcd.print("22");
  delay(1000); /// GIVE USER 1 minutes to apply product
  lcd.setCursor(0, 1);
  lcd.print("21");
  delay(1000); /// GIVE USER 1 minutes to apply product
  lcd.setCursor(0, 1);
  lcd.print("20");
  delay(1000); /// GIVE USER 1 minutes to apply product
  lcd.setCursor(0, 1);
  lcd.print("19");
  delay(1000); /// GIVE USER 1 minutes to apply product
  lcd.setCursor(0, 1);
  lcd.print("18");
  delay(1000); /// GIVE USER 1 minutes to apply product
  lcd.setCursor(0, 1);
  lcd.print("17");
  delay(1000); /// GIVE USER 1 minutes to apply product
  lcd.setCursor(0, 1);
  lcd.print("16");
  delay(1000); /// GIVE USER 1 minutes to apply product
  lcd.setCursor(0, 1);
  lcd.print("15");
  delay(1000); /// GIVE USER 1 minutes to apply product
  lcd.setCursor(0, 1);
  lcd.print("14");
  delay(1000); /// GIVE USER 1 minutes to apply product
  lcd.setCursor(0, 1);
  lcd.print("13");
  delay(1000); /// GIVE USER 1 minutes to apply product
  lcd.setCursor(0, 1);
  lcd.print("12");
  delay(1000); /// GIVE USER 1 minutes to apply product
  lcd.setCursor(0, 1);
  lcd.print("11");
  delay(1000); /// GIVE USER 1 minutes to apply product
  lcd.setCursor(0, 1);
  lcd.print("10");
  delay(1000); /// GIVE USER 1 minutes to apply product
  lcd.setCursor(0, 1);
  lcd.print("09");
  delay(1000); /// GIVE USER 1 minutes to apply product
  lcd.setCursor(0, 1);
  lcd.print("08");
  delay(1000); /// GIVE USER 1 minutes to apply product
  lcd.setCursor(0, 1);
  lcd.print("07");
  delay(1000); /// GIVE USER 1 minutes to apply product
  lcd.setCursor(0, 1);
  lcd.print("06");
  delay(1000); /// GIVE USER 1 minutes to apply product
  lcd.setCursor(0, 1);
  lcd.print("05");
  delay(1000); /// GIVE USER 1 minutes to apply product
  lcd.setCursor(0, 1);
  lcd.print("04");
  delay(1000); /// GIVE USER 1 minutes to apply product
  lcd.setCursor(0, 1);
  lcd.print("03");
  delay(1000); /// GIVE USER 1 minutes to apply product
  lcd.setCursor(0, 1);
  lcd.print("02");
  delay(1000); /// GIVE USER 1 minutes to apply product
  lcd.setCursor(0, 1);
  lcd.print("01");
  yield();
  delay(3000); /// GIVE USER 1 minutes to apply product

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Scale initiating");
  lcd.setCursor(0, 1);
  lcd.print("Place bottle Now");
  yield();
  delay(3000);

//My WEMOS D1 starts to restart from HERE when, please guide me  

scale.set_scale(895.640);
  scale.tare(); 
  Serial.print("read: \t\t");
  Serial.println(scale.read());  
  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()
  float i = scale.get_units(5); 
  if (i < 1)
  {
    i = 0.00;
  }
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("SB Smart Sensor");
  lcd.setCursor(0, 1);
  lcd.print("Vol = ");
  lcd.print(i,1);
  lcd.print(" g");
  delay(500);



  //Check WiFi connection status
  if(WiFi.status()== WL_CONNECTED){
    WiFiClient client;
    HTTPClient http;
    
    // Your Domain name with URL path or IP address with path
    http.begin(client, serverName);
    
    // Specify content-type header
    http.addHeader("Content-Type", "application/x-www-form-urlencoded");
    
    // Prepare your HTTP POST request data
    float i = 123.00; //i have to hardcode the parameter here to test the DB writing 
    String httpRequestData = "api_key=" + apiKeyValue + "&deviceid=" + deviceID + "&volume=" + i;
    /*
    String httpRequestData = "api_key=" + apiKeyValue + "&sensor=" + sensorName
                          + "&location=" + sensorLocation + "&value1=" + String(bme.readTemperature())
                          + "&value2=" + String(bme.readHumidity()) + "&value3=" + String(bme.readPressure()/100.0F) + "";
                          */
    Serial.print("httpRequestData: ");
    Serial.println(httpRequestData);
    
    // You can comment the httpRequestData variable above
    // then, use the httpRequestData variable below (for testing purposes without the BME280 sensor)
    //String httpRequestData = "api_key=tPmAT5Ab3j7F9&sensor=BME280&location=Office&value1=24.75&value2=49.54&value3=1005.14";

    // Send HTTP POST request
    int httpResponseCode = http.POST(httpRequestData);
     
    // If you need an HTTP request with a content type: text/plain
    //http.addHeader("Content-Type", "text/plain");
    //int httpResponseCode = http.POST("Hello, World!");
    
    // If you need an HTTP request with a content type: application/json, use the following:
    //http.addHeader("Content-Type", "application/json");
    //int httpResponseCode = http.POST("{\"value1\":\"19\",\"value2\":\"67\",\"value3\":\"78\"}");
        
    if (httpResponseCode>0) {
      Serial.print("HTTP Response code: ");
      Serial.println(httpResponseCode);

      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Data Upload:");
  

      if (httpResponseCode = 200)
      {
        lcd.setCursor(0, 1);
        lcd.print("Completed!  :)");
        yield();
        delay(10000);

        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("Switching Off");
        lcd.setCursor(0, 1);
        lcd.print("Good Bye!");
        yield();
        delay(2000);

        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("Please Power Off");
        lcd.setCursor(0, 1);
        lcd.print("& Well Done!");


      }
      else {
        lcd.print(httpResponseCode);
      }
    }
    else {
      Serial.print("Error code: ");
      Serial.println(httpResponseCode);
    }
    // Free resources
    http.end();
  }
  else {
    Serial.println("WiFi Disconnected");
  }
  //Send an HTTP POST request every 5 minutes
  yield();
  delay(500000);  
}

The error appeared in Serial screen was:

ets Jan 8 2013,rst cause:1, boot mode:(3,6)
load 0x4010f000, len 3424, room 16
tail 0
chksum 0x2e
load 0x3fff20b8, len 40, room 8
tail 0
chksum 0x2b
csum 0x2b
v0005a310
~ld

And i tried to install the decoder, but upon adding the .jar file into Arduino/tools folder and rebooting the IDE and compiled the code, the decoder doesn't appear in Tools menu

I'm using MacOS M1

Without trying to neglect your trouble, my experience with WEMOS D1 R1 is that the following things causes issues:

  1. uninitialized variables, and for sure pointers
  2. too long execution without calling the wdt (watch dog timer)

You also need to provide the real code. The code you have provided can neither compile nor run, so if you want assistance, you need to provide a code which works at your place.

I am aware of lots of issues with passwords etc. etc., but then you need to create an account which the rest of us who want to help you will be using. So, if you are working up against an end point, then please create the necessary endpoints so that we can try it out.

Without that it will be very very difficult for anyone to help you out.

So: Put in the real http addresses, and explain also how you have setup your wifi system, such that we can copy that and then we can try it out.

Have a wonderful day

David

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.