Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NodeMCU + HX711 + 4 50kgs Load Cells Returns "-83388608" #132

Open
TommiPio opened this issue Mar 8, 2019 · 14 comments
Open

NodeMCU + HX711 + 4 50kgs Load Cells Returns "-83388608" #132

TommiPio opened this issue Mar 8, 2019 · 14 comments

Comments

@TommiPio
Copy link

TommiPio commented Mar 8, 2019

Hello, I'm trying to use 4 50kgs loadcells with a nodemcu and an hx711 to create a Bed Presence Sensor.

This is my circuit

What happen, is that the serial monitor just reports "-83388608" or "83388607" as value. I'm using the hx711 library by Bogde, but I also tried other two different hx711 libraries and all of them gave me the same result.

Anyway, this is the code I'm using now.

#include <Arduino.h>
#include <ArduinoOTA.h>
#include <ESP8266WiFi.h>
#include <PubSubClient.h>

#include "config.h"
#include "HX711.h"

WiFiClient espclient;
PubSubClient client(espclient);

HX711 scale;


void reconnect() {
    // Loop until we're reconnected
    while (!client.connected()) {
        Serial.print("Attempting MQTT connection...");
        // Attempt to connect
        if (client.connect(HOSTNAME, MQTT_USER, MQTT_PASSWORD)) {
            Serial.println("connected");
            // Once connected, publish an announcement...
            client.publish(AVAILABILITY_TOPIC, "online");
        } else {
            Serial.print("failed, rc=");
            Serial.print(client.state());
            Serial.println(" try again in 5 seconds");
            // Wait 5 seconds before retrying
            delay(5000);
        }
    }
}


void setup() {

    
    Serial.begin(115200);
    Serial.println();
    scale.begin(5, 4);

    WiFi.mode(WIFI_STA);
    WiFi.begin(SSID, PASSWORD);
    Serial.print("Connecting...");

    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
    }
    Serial.println();

    Serial.print("Connected, IP address: ");
    Serial.println(WiFi.localIP());

    client.setServer(MQTT_SERVER, 1883);
}


void loop() {
  static int lastValue = 0;
    int value;
  if (!client.connected()) {
      reconnect();
   
    }
   value = scale.read_average(5);
    Serial.println(value);

    // Only publish new value if difference of 500 or more
    if (abs(lastValue - value) >= 500) {
        String value_str = String(value);
        client.publish(STATE_TOPIC, (char *)value_str.c_str());
        lastValue = value;
    }


}

I also have two copies of this sensor, one soldered to a protoboard and one tested using a breadboard, both seems to give me the same problem.

What can I do?

The wifi and mqtt parts are working fine. The value output from the hx711 is "-8388608" when vcc connected to 3v pin or VU pin (that should output 5v).

I'm quite a noob, but if you guys could give me some advice I would love it.

@amotl
Copy link
Contributor

amotl commented Mar 8, 2019

Dear @TommiPio,

After a quick glimpse

read_average() says it would return a long, but your value for storing the outcome is defined as int. Maybe the automatic type cast going wrong yields the weird reading value you are seeing?

So, you might want to use long value = scale.read_average(5); for reading the scale. As I'm not a C/C++ expert, I'm really just guessing here but would be happy to hear about a positive outcome.

More thoughts

However, the returned value could actually be a high number as I don't see any calls to set_scale() or set_offset() within your code yet, which are probably obligatory.

@ClemensGruber: Would it actually be possible that reading the HX711 would yield such strange values when not properly configured through appropriate calls to set_scale() and set_offset()?

With kind regards,
Andreas.

@TommiPio
Copy link
Author

TommiPio commented Mar 8, 2019

Thanks @amotl , unfortunately this didn't solve it.

I kinda made it work, but in a strange way, I really need someone to explain me what is going on with this.

Normally, as seen in my schematic, the VCC pin on the hx711 should be connected to the 3v pin, but this stuck the output to the infamous value, -8388608.

I was playing with my cables, and I noticed that if I link the 3v pin of nodemcu, to the E+ pin on the HX711, suddenly the load cells are working fine.

What am I missing here? Could I actually wire my sensor this way without even passing from the vcc pin on hx711?

16:44:17.150 -> Connecting....
16:44:17.632 -> Connected, IP address: 192.168.1.136
16:44:17.632 -> Attempting MQTT connection...connected
16:44:19.946 -> -1 -------------> 3v pin not connected to anything
16:44:21.216 -> -1
16:44:22.451 -> -1
16:44:35.996 -> -8388608 -------------->3v pin connected to vcc, as in the diagram
16:44:38.131 -> -8388608
16:44:43.015 -> -8388608
16:44:45.150 -> -8388608
16:44:47.283 -> -8388608
16:44:48.525 -> -1 ------------->3v pin disconnected again
16:44:50.589 -> -327076 ------------> 3v pin connected to E+ pin (vcc not connected to anything)
16:44:52.714 -> -326920
16:44:54.885 -> -202974 ------>applying load to the loadcells, it works
16:44:57.010 -> -223136
16:44:59.142 -> -194757
16:45:01.278 -> -165867
16:45:03.413 -> -362636
16:45:05.581 -> -329727
16:45:07.712 -> -327398
16:45:09.850 -> -327435

@bogde
Copy link
Owner

bogde commented Mar 8, 2019

Are you sure your HX711 board is good? Do you have another one to test?

@TommiPio
Copy link
Author

TommiPio commented Mar 8, 2019

Hi @bogde, thanks for this library. I already tried on a breadboard with new hx711, loadcells, and nodemcu, same problem applied.

Everything came from the same reseller, so maybe both hx711 were faulty (?)

Anyway, I can confirm that at least with one of the hx711, this wiring is working. Do I risk of burning something with such a wiring? Does it have any sense that it's working like this for you?

@amotl i thought that too, it's a couple days that I was playing with different codes and even different libraries, but ALL the possible codes always gave me that value. And it's quite strange, I couldn't find anyone on the internet with such problems.

@ClemensGruber
Copy link

@TommiPio two things: doublecheck your wiring. You are using a half bridge setting, so perhaps the schematic of the Sparkfun load cell combinator can help: https://github.com/sparkfun/Load_Sensor_Combinator/blob/V_1.1/Hardware/SparkFun%20Load%20Sensor%20Combinator.sch Second: did you "calibrate" (more correct ist "justify") your setting and tare your setting? You have to do this before. Are this values in the config file already? Seems that you are reading the raw values only and no kg values, see the example https://github.com/bogde/HX711/blob/master/examples/HX711_full_example/HX711_full_example.ino

@isnainiahmadi
Copy link

I'm pretty sure that you use separated power supply (not directly from Arduino). If you do, connect power supply ground to Arduino too.

@piotrbazan
Copy link

Had same problem here with the same strange value. Spent several hours until I noticed that manufacturer did not conform to standard of sensor color cables. In my case conneting Black Power + , white Power - Red Signal + green signal - solved the issue. Hope it helps.

@amotl
Copy link
Contributor

amotl commented Oct 17, 2019

Things like constant readings of 8388607 [1] might also be caused by faulty hardware. Enjoy reading [2] just reported by @poesel. Thanks!

[1] INT24_MAX is defined as 8388607L through avr-gcc.
[2] https://community.hiveeyes.org/t/hx711-with-arduino-uno-constant-8388607-output/2603/3

@prof-kalabwa
Copy link

prof-kalabwa commented Jan 4, 2020

@amotl can i have your moment please. I've copied the above code. and variables with these ** ** .

#include <Arduino.h>
#include <ArduinoOTA.h>
#include <ESP8266WiFi.h>
#include <PubSubClient.h>

#include "config.h"
#include "HX711.h"

WiFiClient espclient;
PubSubClient client(espclient);

HX711 scale;


void reconnect() {
    // Loop until we're reconnected
    while (!client.connected()) {
        Serial.print("Attempting MQTT connection...");
        // Attempt to connect
        if (client.connect(**HOSTNAME**, **MQTT_USER**, **MQTT_PASSWORD**)) {
            Serial.println("connected");
            // Once connected, publish an announcement...
            client.publish(**AVAILABILITY_TOPIC**, "online");
        } else {
            Serial.print("failed, rc=");
            Serial.print(client.state());
            Serial.println(" try again in 5 seconds");
            // Wait 5 seconds before retrying
            delay(5000);
        }
    }
}


void setup() {

    
    Serial.begin(115200);
    Serial.println();
    scale.begin(5, 4);

    WiFi.mode(WIFI_STA);
    WiFi.begin(**SSID**, **PASSWORD**);
    Serial.print("Connecting...");

    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
    }
    Serial.println();

    Serial.print("Connected, IP address: ");
    Serial.println(WiFi.localIP());

    client.setServer(**MQTT_SERVER**, 1883);
}


void loop() {
  static int lastValue = 0;
    int value;
  if (!client.connected()) {
      reconnect();
   
    }
   value = scale.read_average(5);
    Serial.println(value);

    // Only publish new value if difference of 500 or more
    if (abs(lastValue - value) >= 500) {
        String value_str = String(value);
        client.publish(STATE_TOPIC, (char *)value_str.c_str());
        lastValue = value;
    }


}

i don't know how to declare them. any help would be appreciated. thank you
i've got errors about how the highlighted variables are not declared and I don't know what to declare on that variables. please tell me how to declare that variables or reference for me to read about that variables. thank you

@ClemensGruber
Copy link

ClemensGruber commented Jan 4, 2020

@prof-kalabwa where is your code from? You may have a look at the example there. It seems that config.h is the file you should check. And you may have a look at https://github.com/knolleary/pubsubclient/blob/master/examples/mqtt_esp8266/mqtt_esp8266.ino

@HamzaHajeir
Copy link

Had same problem here with the same strange value. Spent several hours until I noticed that manufacturer did not conform to standard of sensor color cables. In my case conneting Black Power + , white Power - Red Signal + green signal - solved the issue. Hope it helps.

Same here, I lastly went to the selling page that describes this info, changed and fixed.

@rn-ksheer
Copy link

Thanks @amotl , unfortunately this didn't solve it.

I kinda made it work, but in a strange way, I really need someone to explain me what is going on with this.

Normally, as seen in my schematic, the VCC pin on the hx711 should be connected to the 3v pin, but this stuck the output to the infamous value, -8388608.

I was playing with my cables, and I noticed that if I link the 3v pin of nodemcu, to the E+ pin on the HX711, suddenly the load cells are working fine.

What am I missing here? Could I actually wire my sensor this way without even passing from the vcc pin on hx711?

16:44:17.150 -> Connecting....
16:44:17.632 -> Connected, IP address: 192.168.1.136
16:44:17.632 -> Attempting MQTT connection...connected
16:44:19.946 -> -1 -------------> 3v pin not connected to anything
16:44:21.216 -> -1
16:44:22.451 -> -1
16:44:35.996 -> -8388608 -------------->3v pin connected to vcc, as in the diagram
16:44:38.131 -> -8388608
16:44:43.015 -> -8388608
16:44:45.150 -> -8388608
16:44:47.283 -> -8388608
16:44:48.525 -> -1 ------------->3v pin disconnected again
16:44:50.589 -> -327076 ------------> 3v pin connected to E+ pin (vcc not connected to anything)
16:44:52.714 -> -326920
16:44:54.885 -> -202974 ------>applying load to the loadcells, it works
16:44:57.010 -> -223136
16:44:59.142 -> -194757
16:45:01.278 -> -165867
16:45:03.413 -> -362636
16:45:05.581 -> -329727
16:45:07.712 -> -327398
16:45:09.850 -> -327435

Excellent mod !!!!, After a day of search i was able to get loadcell to work. Leaving 5v connected to VCC on HX711 module or disconnecting it did not many any difference.

@TommiPio
Copy link
Author

I didn't end up using this wiring in the end because the value were not stable enough for me. I really think it depends on the Hx711 unit, I read that with the sparkfun one the problems are almost non-existent.

Anyway, I always dreamt about understanding why this nonsense wiring schemed I found out seemed to be working ahaha

@rn-ksheer
Copy link

I wanted to detect weight changes and trigger a action so value's accuracy was not a concern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants