Menu

HX711 Load cell data help

Help
2023-04-15
2023-04-16
  • tony golding

    tony golding - 2023-04-15

    hi everyone,

    i have been playing around with some 50kg load cells ( bathroom scale type ) X4 wired together and the well known HX711 module.

    i have managed to get data out from the module, thanks to code provide from one of our other forum members here, and get it to display on an SSD1306 0.96" i2c display but from where to go in terms of turning that basic data into a usable meaningful number of weight is where im now stuck.

    after countless google searches that mostly only ever yield arduino results that use floats and negative offsets or fractional negative numbers ect, none of it makes any sense regardless.

    if i send the data to the i2c oled then i get numbers that do change value with weight difference but the value decreases to underflow or vice versa, and if i output the data to terminal via usart then i get random numbers that seem to not make much more sense.

    how do i go about making use of the data from the module and converting it so i can weigh things lol.

    thanks
    tony

     
  • Anobium

    Anobium - 2023-04-15

    Not seen this sensor. But...to interface with the HX711 using integer maths, you may need to use the following steps:

    1. Set the gain of the amplifier. The gain can be set to 128 or 64.
    2. Configure the ADC. The ADC can be configured to work in single-shot or continuous mode.
      Read the ADC value. The ADC value will be a 24-bit number.
    3. Convert the ADC value to weight. The weight can be calculated using the following formula:
      weight = (ADC_value * gain) / 1024

    For example, if the ADC value is 1000 and the gain is 128, then the weight will be 1000 grams.

    Here is an example of how to interface with the HX711 using integer maths:

    // Set the gain of the amplifier
    HX711setGain(128);
    
    // Configure the ADC
    HX711setMode(CONTINUOUS)
    
    // Read the ADC value
    adc_value = ReadADC( ANn )
    
    // Convert the ADC value to weight
    // SysCalcTempX contains the remainder.  
    weight = (adc_value * 128) / 1024
    

    And, looking are you code. Is the TwoCompliment correct? I would use.

    function   TwoCompliment( in RawWordValue as long ) as Integer
    
        ' Is this a negative value?
        ' XOR with 65535 and add oneto get 2's compliment
        If RawWordValue.15 = 1 then
            RawWordValue = (RawWordValue XOR 65535) + 1       'convert twos complement to decimal by xor'ing with 65535 and adding 1
          TwoCompliment = 0 - RawWordValue
        else
                TwoCompliment = RawWordValue
        end if
    
    end function
    
     
  • tony golding

    tony golding - 2023-04-15

    hi anobium,

    thanks for the response, honestly im not sure about the 2's compliment as ive not used it before and had to rely on found code more or less just to get started but i have data of sorts being retrieved to start with lol.

    im just lost on how the data should be converted, i know you gave a pseudo example however i dont have to get the data via adc just clocking out the 24bits that the hx711 adc processed.

    the HX711 combines a PGA IN-AMP to boost the low mv then feeds it to the 24bit adc which as the datasheet says sends out in 2's compliment format as a 24bit result MSB first.

    i have added the datasheet in case it is more usefull, sorry i should have added that last night as well.

     
  • Anobium

    Anobium - 2023-04-16

    What happens when you remove the last clock?

    Comment out this code.

      ;but need CLK 25 times to set resolution and channel of next conversion
      ;Cycle clock one more Time
      HX711_SCK = 1
      wait 2 us
      HX711_SCK = 0
      wait 2 us
    

    The goal ( I think ) is just to get stability in the read operation. So, I think the extra clock is confusing the device.

     
  • tony golding

    tony golding - 2023-04-16

    ok ill give that a whirl, but from reading the datasheet i assume it is needed to tell the module what the gain is desired for the next conversion, i will let you know.

     
    • Anobium

      Anobium - 2023-04-16

      No... ignore that.. sort of .

      Shift 25 bits in the Long. That should give a gain of 128. Then, delete the extra clock.

      Because at the moment you are shifting 24bits, bit of a clock rest then an extra clock. I know this give 25 clocks but the I think you need 25bits out.

       
  • tony golding

    tony golding - 2023-04-16

    well not much difference really, i still get data out of it that varies when load is placed removed.

    all i know is the adc outputs the data in 2's complement, but as to how i can go about being able to convert that into a meaningful value of pounds or kiligrams is the part that i cant get any real insight to.

    i have tried to make sense from all the info out their but im still not sure as to how i convert the data and thats where im stuck so far.

     
  • Anobium

    Anobium - 2023-04-16

    So, at the moment you are not getting a consistent value from the sensor ?

    I would not worry about data conversion yet. I would want to see the the same set of data being returned consistently.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.