Bee hive weight with HX711

Inspired by a youtube video on making an IoT bathroom weighing scale I was planning to weigh my beehives to be able to monitor their health.

Setup:

Test code (example as provided in HX711.h):

#include "HX711.h"

// HX711 circuit wiring
const int LOADCELL_DOUT_PIN = 5;
const int LOADCELL_SCK_PIN = 6;

HX711 scale;

void setup() {
  Serial.begin(115200);
  scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
}

void loop() {

  if (scale.is_ready()) {
    long reading = scale.read();
    Serial.print("HX711 reading: ");
    Serial.println(reading);
  } else {
    Serial.println("HX711 not found.");
  }

  delay(1000);
  
}

Attempts:
I tried many different baud rates and different pins. The serial monitor is sometimes unreadable but often the error looks like:

 ets Jan  8 2013,rst cause:4, boot mode:(3,6)

wdt reset
load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
vbc204a9b
~ld

Googling for this error didn't help me. Often one suggest to add delay(1). Does anybody know what's wrong here?

Please post a link (using the chain links icon on the forum toolbar to make it clickable) to where you downloaded the HX711 library from. Or if you installed it using Library Manger (Sketch > Include Library > Manage Libraries in the Arduino IDE or Libraries > Library Manager in the Arduino Web Editor) then say so and state the full name of the library.

It would also be useful for us to know which version of the library you are using.

Thank you for your quick reply. Sorry I thought I was complete with pasting the code.

The library was downloaded here:

I see that some code was added specifically to avoid having the ESP8266's watchdog timer time out and cause a reset if there is a long delay when waiting on the HX711:

That change was made before the breaking change to the library's API. From your sketch, I can see you're using the new version of the library.

So unfortunately I don't know what would cause that reset. Maybe someone else here will have an idea.

Here's a few things to try/ponder; I had a play with a nano+HX711+ESP01 followed by a D1 mini + HX711 a few years ago, and while it's hard to remember all problems and specifics, here's a few lessons I learnt..

This is a combined hardware and software project, so the hardware has to be right/mostly right/debugged before getting the software working.

Being a hardware guy and mostly "cutting and pasting" code with my own bits of "glue", I had to make sure the hardware + code was working properly on a Uno/Nano before progressing to an ESP, so researched alot around load cells and hook up guides in general, and whatever I could find for the HX711.

Sparkfun have pretty good information-

https://learn.sparkfun.com/tutorials/openscale-applications-and-hookup-guide

https://learn.sparkfun.com/tutorials/load-cell-amplifier-hx711-breakout-hookup-guide

Some cheap HX711 boards I bought were missing a connection between common and AGnd/Excitation- , I could see no reason why Agnd/E- should be isolated from common and they only worked properly with the connection, and a close look at other (and better pcb layouts) and cct diagrams always showed Analog ground connected to Gnd, as it normally should.

Progressing to the ESP D1, I remember having a wdt problem early on with code snippets, caused by too long a delay, so try shortening the delay. Googling esp wdt reset, or esp watchdog timer turns up alot of results worth looking at, including at least one in this forum involving the HX711. It's certainly worth getting the bulk of the code working on a non-ESP first, by the time one is ready for IOT, the loop times and wdt could well be under control.

I think I remember using 5v to power the HX711 and using level converters for the ESP too...

Your responses are highly appreciated.

Unfortunately I think I'm working out of my league here. I tried to read and test further but have to admit I'm more a hardware guy than a software guy at all :slightly_frowning_face:

Just pasting a delay was too easy thinking I'm afraid. I've tested with an external 5V power source as well.

Would someone please be so kind to have another look?

azeo:
Progressing to the ESP D1, I remember having a wdt problem early on with code snippets, caused by too long a delay

That should not be the case if you're using delay(), since this is written so that it can't cause a watchdog timer timeout no matter how long the delay is. Of course if you have a delay caused by some blocking code that doesn't call delay() or yield() (or some other function that calls those functions), then you will get a timeout.

ESF-nl:
Just pasting a delay was too easy thinking I'm afraid.

Did pasting a delay fix the problem?

No, the error remains. This is the loop in the monitor:

 ets Jan  8 2013,rst cause:4, boot mode:(3,6)

wdt reset
load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
vbc204a9b
~ld

 ets Jan  8 2013,rst cause:4, boot mode:(3,6)

wdt reset
load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d

pert:
That should not be the case if you're using delay(), since this is written so that it can't cause a watchdog timer timeout no matter how long the delay is. Of course if you have a delay caused by some blocking code that doesn't call delay() or yield() (or some other function that calls those functions), then you will get a timeout.
Did pasting a delay fix the problem?

I agree, it must have been blocking code rather long deIays - built around 2016 so recall of some specifics fading a bit! I have just revisited ESP8266 to try a couple of quick holiday investigations/updates, and yes, code examples from certain libraries (such as Oled) that had prolonged for loops caused some timeouts, and judicious use of yield() prevented this.

Also dug out and had a look at the last working version of my HX711 project code (which also used the same library (but 2016 version) and it had some long delays to allow viewing of serial messages etc, while it also looks like some small delays are sprinkled around to avoid freezing.The project H/W which is still around still runs as built then without freezing for long periods, so for my purposes, that certainly worked, so hopefully too for the OP

I can remember finding some useful clear info/help on yield/wdt back then, and thought I'd saved it, but has been hard to find, but found this from spark fun which looks useful for beginners ESP8266 Thing Hookup Guide - SparkFun Learn

and this might be interesting too ESP8266 Watchdogs in Arduino

Choosing slightly the wrong esp board can cause a few funny problems too, where code downloads and runs to a certain extent, but then freezes, (a recent problem I had when I thought I had a "lite" version) so it might be worth double checking which type of board you have, then appropriate IDE settings - board type, CPU frequency, upload speed etc, for eg Wemos D1 R2 & Mini, 80Mhz. Hope this helps....

Persistence and revisiting is the key with these darn microcontrollers (of any breed!)

Hmm, the newer library examples look a bit different from the older one, so I'm curious to try them. The example code looks so spartan, it should work....

I have a project in mind similar to monitoring beehives and have retrived working hardware I had at work in case I had a "play" during some holidays, and may find some time to try. If I find anything of interest, will report back. If I make headway on my own project, will definitely be looking at the sparkfun "Open Scale" for guidance, methods, and code to incorporate...

hmm, the bogde library readme is really worth reading through, more info than 3 years ago if I recall, eg a non blocking mode is described, and the appendix has some interesting/useful links...

The Hiveeyes Community, open source beehive monitoring toolkit google translate would be useful though - bi-lingual site

Thank you again for your help!

I'm also picking up some projects during the holidays. Hopefully I'll manage to get this simple code running.

ArduinoIDEsettings.png

No problem! try these pin settings, not only does the right number have to be used, but also the full -prefix-assignment.. for some reason... :slight_smile: I use pins according to info here (not the only source, but a very handy site), ESP8266 Pinout Reference: Which GPIO pins should you use? | Random Nerd Tutorials

I got the timeout example working first by referring to my previous working project example, then tried the new library basic example with the right pin settings, which is now also working, albeit with a few "not found" readings. It may still be a good idea to use the timeout version though for more reliable operation, perhaps in more remote circumstances that could report a problem instead of completely freezing.

// HX711 circuit wiring
const int LOADCELL_DOUT_PIN = D6;
const int LOADCELL_SCK_PIN = D5;

Good Luck!

Wow! For a moment I thought you found my mistake. I called those pins 5 and 6 and you called them D5 and D6.

Unfortunately after changing that the serial monitor remains empty. How come?

Looking closer to your settings I also saw you had rate 57600. So I tried but that gave me ⸮⸮⸮a\⸮dH⸮aH⸮⸮k⸮VqJ⸮⸮⸮⸮eJ⸮⸮⸮⸮TQ⸮⸮ޅH⸮S⸮f⸮a\ ⸮A⸮F`ʲ⸮⸮_⸮⸮

So I changed the rate back to 115200 but then again nothing in the monitor.

I also noticed multiple pins for both D5 and D6. 'SCK/D5' and 'MISO/D6' and just 'D5' and 'D6'. I've tried both but no luck :frowning:

Kind regards from the Netherlands and Merry Christmas!

Merry Christmas from New Zealand :slight_smile: I did notice that your pins assignments were swapped compared to mine, so do check that DOUT is assigned to D6, and SCK to D5, and also check that the wiring from the ESP also physically connects D6 to DOUT and D5 to SCK on the HX711...

The baud rate is not too important, as long as the serial monitor is set to the same rate as the program/sketch, 115200 does seem to allow the fail message to be readable....

I'm using a Wemos D1 mini and the D5/SCK D6/MISO pins seem to be the same as the R1 D1 .....
Cheers!

Ho-Ho-Ho Merry Christmas! Up and running!

Via the URL's you provided, I came across a load cell program which used another library. This one was called HX711_ADC instead of the HX711. So testing this library GitHub - olkal/HX711_ADC: Arduino library for the HX711 24-bit ADC for weight scales with its own example sketch finally worked!

Initially I got similar errors (the loop with load 0x4010f000, len 1384, room 16 as above, and later the weird characters).

The trick lies with the correct combination of D5, D6 pin numbers (instead of 5, 6 as in the example sketch) and correct baud rate. This is the one running now:

//-------------------------------------------------------------------------------------
// HX711_ADC.h
// Arduino master library for HX711 24-Bit Analog-to-Digital Converter for Weigh Scales
// Olav Kallhovd sept2017
// Tested with      : HX711 asian module on channel A and YZC-133 3kg load cell
// Tested with MCU  : Arduino Nano, ESP8266
//-------------------------------------------------------------------------------------
// This is an example sketch on how to use this library
// Settling time (number of samples) and data filtering can be adjusted in the config.h file

#include <HX711_ADC.h>
#include <EEPROM.h>

//HX711 constructor (dout pin, sck pin):
HX711_ADC LoadCell(D5, D6);

int eepromAdress = 0;

long t;

void setup() {
  float calValue; // calibration value
  calValue = 696.0; // uncomment this if you want to set this value in the sketch
  #if defined(ESP8266)
  //EEPROM.begin(512); // uncomment this if you use ESP8266 and want to fetch this value from eeprom
  #endif
  //EEPROM.get(eepromAdress, calValue); // uncomment this if you want to fetch this value from eeprom

  Serial.begin(115200); delay(10);
  Serial.println();
  Serial.println("Starting...");
  LoadCell.begin();
  long stabilisingtime = 2000; // tare preciscion can be improved by adding a few seconds of stabilising time
  LoadCell.start(stabilisingtime);
  if (LoadCell.getTareTimeoutFlag()) {
    Serial.println("Tare timeout, check MCU>HX711 wiring and pin designations");
  }
  else {
    LoadCell.setCalFactor(calValue); // set calibration factor (float)
    Serial.println("Startup + tare is complete");
  }
  while (!LoadCell.update());
  Serial.print("Calibration factor: ");
  Serial.println(LoadCell.getCalFactor());  
  Serial.print("HX711 measured conversion time ms: ");
  Serial.println(LoadCell.getConversionTime());
  Serial.print("HX711 measured sampling rate HZ: ");
  Serial.println(LoadCell.getSPS());
  Serial.print("HX711 measured settlingtime ms: ");
  Serial.println(LoadCell.getSettlingTime());
  Serial.println("Note that the settling time may increase significantly if you use delay() in your sketch!");
  if (LoadCell.getSPS() < 7) {
    Serial.println("!!Sampling rate is lower than specification, check MCU>HX711 wiring and pin designations");
  }
  else if (LoadCell.getSPS() > 100) {
    Serial.println("!!Sampling rate is higher than specification, check MCU>HX711 wiring and pin designations");
  }
}
void loop() {
  //update() should be called at least as often as HX711 sample rate; >10Hz@10SPS, >80Hz@80SPS
  //use of delay in sketch will reduce effective sample rate (be carefull with delay() in the loop)
  LoadCell.update();

  //get smoothed value from data set + current calibration factor
  if (millis() > t + 250) {
    float i = LoadCell.getData();
    Serial.print("Load_cell output val: ");
    Serial.println(i);
    t = millis();
  }
}

Now I'll start working on the WiFi and MQTT connection. Maybe that's a reason to come back to you later but for now: thanks again everybody.

ESF-nl, great, that's terrific! I was about to add a new suggestion/update before trying calibrating a 5kg scale with the HX711_ADC library and saw your latest update...

I tried the very same sketch this morning just before going out for the day, ... so was going to suggest trying the HX711_ADC library as it was working well with the calibration I use for a 40kg load cell with the bogde library. So great that it's working for you.

The key certainly seems to be correct naming of the pins (and the matching hardware connections of course). I'm not smart/knowledable enough about the programming side of things to understand why, but wonder maybe if it's a naming convention that applies when compiling for ESP rather than Uno, Nano etc.

Don't know if this is a useful tip or suggestion, but I have found existing scales, such as 5kg kitchen scales a great platform for testing and prototyping if one breaks into the load cell wiring fitting a header socket and plug, such that it can be plugged to an HX711, or when desired, plugged back into itself to act as a normal scale. Useful for verifying various weights etc when testing the HX711 and saves mounting a bare load cell beam. The wiring is a bit delicate though, so fine soldering skills and heatshrink useful. etc Coins make great standard known weights too.... for eg kiwi currency covers a range from 3-10g

Good luck particularly with the MQTT - not something I've tried yet, so interested to follow, but have used Thingspeak, Xively (no longer available), and remotexy (http://remotexy.com/) which is useful/interesting to try with Android via wifi, bluetooth or OTG Usb, and well worth a look.