#include <ESP8266WiFi.h>
#include "HX711.h"
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
// HX711 circuit wiring
const int LOADCELL_DOUT_PIN = D4;
const int LOADCELL_SCK_PIN = D5;
HX711 scale;
void setup() {
Serial.begin(115200);
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
lcd.begin();
lcd.backlight();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Initializing");
lcd.setCursor(0, 1);
lcd.print("SBSS");
delay(1000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("WiFi starting");
lcd.setCursor(0, 1);
lcd.print("Connecting...");
delay(1000);
Serial.println("WiFi starting");
WiFi.begin("47B 2.4Ghz","blt4397fuad");
Serial.print("Connecting...");
while(WiFi.status()!=WL_CONNECTED){ //Loop which makes a point every 500ms until the connection process has finished
delay(500);
Serial.print(".");
}
Serial.println();
Serial.print("WiFi Connected!");
Serial.println(WiFi.localIP());
Serial.println(WiFi.SSID()); //Displaying the IP Address
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("WiFi Name");
lcd.setCursor(0, 1);
//lcd.print(WiFi.localIP());
lcd.print(WiFi.SSID());
delay(1000);
Serial.println("Initializing the scale");
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
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(895.640);
//scale.set_scale(-471.497); // 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:");
Serial.println(scale.get_units(5), 1);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Suu Balm");
lcd.setCursor(0, 1);
lcd.print("Smart Sensor");
delay(1000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Ready: Please");
lcd.setCursor(0, 1);
lcd.print("remove bottle");
delay(1000);
}
void loop() {
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
float i = scale.get_units();
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(1000);
}
the first bug fixed by removing delay in my while loop, turned out the delay line will cause error.
for the LCD, im trying to remove / uninstall the library and install a fresh new library and reconnect it.
it wasn't that it show all aliens kind of characters,
but when the lcd clear code fires, then there's where the weird characters appear on screen
im suspecting that there's a spike of current? but will be concluded after 2-3 library change
Which boards package are you using for the WeMos D1? I was under the impression that the ESP8266 variant of delay() called yield() and would not cause a watchdog timer reset.
I am still of the opinion that calling scale.begin() multiple times is going to cause you problems.
#include <ESP8266WiFi.h>
#include "HX711.h"
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
const int LOADCELL_DOUT_PIN = D4;
const int LOADCELL_SCK_PIN = D5;
HX711 scale;
LiquidCrystal_I2C lcd(0x27, 18, 2);<------ culprit 1
void setup()
{
lcd.begin();
lcd.backlight();
Serial.begin(115200);
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
Serial.println(scale.get_units(5), 1);
Serial.println("WiFi starting");
WiFi.begin("Suu Balm","fastitchrelief99");
//WiFi.begin("47B 2.4Ghz","blt4397fuad");
Serial.print("Connecting...");
while(WiFi.status()!=WL_CONNECTED)
{
Serial.print(".");
}
Serial.println();
Serial.print("WiFi Connected!");
Serial.println(WiFi.localIP());
Serial.println(WiFi.SSID());
delay(3000);
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()
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("SB Smart Sensor");
}
void loop()
{
float i = scale.get_units(5); // <------ culprit 2
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);
}
Im suspecting the LCD library works with 18 chars as previous code was initated with 16
and the average value taking from scale.get_units(5), it turned out the whole script will turn haywire if bigger average is set (Eg: 5 to 20)
The serial thrown the same error again when scale code should run.
I tried installing Exception decoder in my mac by creating tools folder and extracting the downloded jar file.
but when i closed IDE, compiled and ran the code: the Exception decoder not even showing in Tools menu on top of IDE
I don't know. I never use tools like the exception decoder. When I get something like that, I start examining the code, starting with the last change I made to it before it started happening.