This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to calculate real weight from HX711 50kg sensors?

I'm now using HX711 50kg sensors to build a scale

Now I can read the data from HX711, and try some method from internet, but still can't get the real weight

does anybody know some math can help me to calculate the real weight? thanks a lot

and here is my code, reading the data from HX711 50kg A and B

#include <stdint.h>
#include <string.h>
#include "nrf_gpio.h"
#include "nrf_delay.h"
#include "boards.h"

#define HX711_SCK_ON      nrf_gpio_pin_set(SCK)   // set SCK high
#define HX711_SCK_OFF     nrf_gpio_pin_clear(SCK) // set SCK low
#define HX711_DOUT_Read   nrf_gpio_pin_read(DOUT) // read DOUT high or low
#define GapValue          116.18 


unsigned long  Orig_WeightA;
unsigned long  Orig_WeightB;
unsigned long  dataA;
unsigned long  dataB;

static void leds_init(void)
{
    bsp_board_init(BSP_INIT_LEDS);
}

static void HX711_init(void)
{
   nrf_gpio_cfg_output(PRESS);  
   nrf_gpio_cfg_output(SCK);                       // set SCK output
   nrf_gpio_cfg_input(DOUT, NRF_GPIO_PIN_NOPULL);  // set DOUT input
}

unsigned long HX711_ReadA(void)
{
      unsigned long count = 0;
      int i;

      HX711_SCK_OFF;

    while(HX711_DOUT_Read);  // wait for ADC finish and read 24 times
       
      for(i = 0; i < 24; i++)
      {
          
          HX711_SCK_ON;
          count = count << 1; 
          nrf_delay_us(2);
          HX711_SCK_OFF;
          nrf_delay_us(2);
          
      
      if(HX711_DOUT_Read) 
        {
          count++; 
        }
          
      }
       
          HX711_SCK_ON;
          nrf_delay_us(2);
          HX711_SCK_OFF;
         
      if(count & 0x800000)
        {
          count |= (long) ~0xffffff;
        }

      return count;
   
       
}

unsigned long HX711_ReadB(void)
{
    long count = 0;
    int i;

    HX711_SCK_OFF;

    while(HX711_DOUT_Read); // wait for ADC finish and read 24 times
       
      for(i = 0; i < 24; i++)
      {
          
          HX711_SCK_ON;
          count = count << 1; 
          nrf_delay_us(2);
          HX711_SCK_OFF;
          nrf_delay_us(2);
          
      
      if(HX711_DOUT_Read) 
        {
          count++; 
        }
          
      }
       
          HX711_SCK_ON;
          nrf_delay_us(2);
          HX711_SCK_OFF;
          nrf_delay_us(2);
          HX711_SCK_ON; 
          nrf_delay_us(2);
          HX711_SCK_OFF;
      if(count & 0x800000)
        {
          count |= (long) ~0xffffff;
        }

      return count;
   
       
}

unsigned long get_OrigWeightA(void) // get original data from HX711
{
   nrf_delay_ms(100);
   Orig_WeightA = HX711_ReadA() ;
}

unsigned long get_OrigWeightB(void) // get original data from HX711
{
   nrf_delay_ms(100);
   Orig_WeightB = HX711_ReadB() ;
}



int main(void)
{
    // Initialize.
        leds_init();
        HX711_init();
        bsp_board_led_on(BSP_BOARD_LED_0);

    for (;;)
    {
  
        HX711_ReadA();
        HX711_ReadB();
        dataA = get_OrigWeightA();
        dataB = get_OrigWeightB();
     
       
        
        
    } 
    

}
  

Related