Load cell does not measure weight in light sleep


I wanted measure some weight with a loadcell and ESP8266. After writing some code and testing it. Code worked but load cell didn't return an value. So I decided to delete light sleep function from the void loop. After that it worked awesome. However I can't use light sleep which means ESP8266 will consume way more power than before. My question is:
How can use load cell with light sleep?

This is my code

extern "C" {
#include "gpio.h"
// Required for LIGHT_SLEEP_T delay mode
extern "C" {
#include "user_interface.h"

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

#define HX711_DOUT D5 //mcu > HX711 dout pin
#define HX711_SCK D6 //mcu > HX711 sck pin

HX711_ADC LoadCell(HX711_DOUT, HX711_SCK);

//Function prototypes
void startLoadcell(void);
void startperipheral(void);
float measureWeight(void);
void light_sleep();
ICACHE_RAM_ATTR void tareSet(void);

void setup() {

void loop() {
  Serial.println("Going to Sleep");
  light_sleep();//Enter light sleep.
  Serial.println("Wake up");


void startperipheral(void) {
  pinMode(INTERRUPT_PIN, INPUT_PULLUP); //Tare button
  attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), tareSet, FALLING); //Attach tare button as interrupt

void startLoadcell(void) {
  LoadCell.begin();//Start loadcell
  float calibrationValue;
  int calVal_eepromAdress;
  EEPROM.get(calVal_eepromAdress, calibrationValue);//Get loadcell calibration dat from EEPROM.
  unsigned long stabilizingtime = 2000;
  boolean _tare = true;
  if (LoadCell.getTareTimeoutFlag()) {
    Serial.println("Timeout, check MCU>HX711 wiring and pin designations");
    while (1);
  else {
    LoadCell.setCalFactor(calibrationValue); // set calibration value (float)
    Serial.println("Startup is complete");

float measureWeight(void) {

  static boolean newDataReady = 0;
  const int serialPrintInterval = 0;
  unsigned long t = 0;
  if (LoadCell.update()) newDataReady = true;

  if (newDataReady) {
    if (millis() > t + serialPrintInterval) {
      newDataReady = 0;
      t = millis();
      return LoadCell.getData(); //Read loadcell

ICACHE_RAM_ATTR void tareSet(void) { // Interrupt for setting the tare

  LoadCell.tareNoDelay(); //Set tare

void light_sleep() { // Enter light sleep
  wifi_fpm_set_sleep_type(LIGHT_SLEEP_T); // set sleep type, the above    posters wifi_set_sleep_type() didnt seem to work for me although it did let me compile and upload with no errors
  wifi_fpm_open(); // Enables force sleep
  gpio_pin_wakeup_enable(GPIO_ID_PIN(2), GPIO_PIN_INTR_LOLEVEL); // GPIO_ID_PIN(2)(also known as D4) corresponds to GPIO2 on ESP8266-01 , GPIO_PIN_INTR_LOLEVEL for a logic low, can also do other interrupts, see gpio.h above

  wifi_fpm_do_sleep(36e8); // Sleep for 1 hour possible time

Thank you.

Your sleep time is outside the allowed range. You don't check return codes.

What does that mean? You don't get any output? You always get 0 as the value?

Thanks for the answer,

What can I write for 1 hour sleep time?
I actually checked return code. I got zero all the time.

In my opion I should not see anything in the serial monitor unless my code doesn't work. But I see zeros printed in the serial monitor.

You cannot, you have to split into two parts.

Post the exact output you get!

Sorry I can not test it again. Because I am in the dorm and I have no equipment with me but as I remember output is like this.

going to sleep

After pressing the button it is like this.

going to sleep
wake up

Can you post a complete wiring diagram as well as a link to the HX711 breakout board you're using?

Thanks for the answer.


Also D4 is connected to a button with internal pullup resistor activated.

You must not power the HX711 using 5V if the I/O signals are on 3.3V! Connect VCC of the HX711 board to 3.3V (the HX711 works in the range 2.6 - 5.5V). Check if D5 is already fried on the Wemos.

Try to call startLoadcell() after the Wemos woke up. Post the output you get.

You might want to call LoadCell.powerDown() and LoadCell.powerUp() before and after going to sleep.

Thanks for the answer.
I will test the code as soon as I go back to my home. As I mentioned earlier I am at the dorm.

Wish you all the best.

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