Interface 3kg loadcell with HX711 module using Nucleo-F746ZG

I am using 3kg loadcell with HX711 module and interface it with Nucleo-F746ZG. I am using this library.

http://os.mbed.com/users/laskowsk/code/HX711/

But everytime the values from this loadcell are different.
Help me to calibrate the loadcell and get correct values.

@JohnnyK Can u plz help me with this

Hello,

I can try and I like doing it, this is why I am still here but I expect something for that. Nothing special, just feedback - ok, thank you or sorry I need something differend.

Few days ago we discussed about loadcell without any feedback.

Because you shared very little, like usually, I do not know what a method of this library you used and also how much different those values are.

You probably need a static load for the load cell. Then try to set a gain, offset and scale for approx expected values.

BR, Jan

@JohnnyK Apologies for not giving you proper feedback. I tried this HX711 - Library for communication with the HX711 24-Bit A… | Mbed library but its not properly working for me. So I decide to proceed with this http://os.mbed.com/users/laskowsk/code/HX711/ library.

The code I am using for the calibration is :-


#include "mbed.h"
#include "HX711.h"

HX711 scale(PB_11, PB_10);
Serial pc(USBTX, USBRX);    // USB Serial Terminal
float calibration_factor = -7050; //-7050 worked for my 440lb max scale setup
int averageSamples = 100;

int main(void)
{
    pc.baud(115200);
    pc.printf("Starting Scale");
    pc.printf("Starting Scale");
    pc.printf("HX711 calibration sketch");
    pc.printf("Remove all weight from scale");
    pc.printf("After readings begin, place known weight on scale");
    pc.printf("Press + or a to increase calibration factor");
    pc.printf("Press - or z to decrease calibration factor");
    
      
    scale.setScale(0);
    scale.tare(); //Reset the scale to 0
    
    long zero_factor = scale.averageValue(averageSamples); //Get a baseline reading
    pc.printf("Zero factor: %.4f\n" , zero_factor); //This can be used to remove the need to tare the scale. Useful in permanent scale projects.
    
    while (true) {
        scale.setScale(calibration_factor); //Adjust to this calibration factor
        float weight = scale.getGram();
        //float raw = scaleRaw.read();
        pc.printf("Reading: %.2f\n", weight);
        //pc.printf("Raw Value: %.7f\n", raw);
        pc.printf(" calibration_factor: %.2f\n", calibration_factor);

       if(pc.readable()) {
            char temp = pc.getc();
            if(temp == '+' || temp == 'a')
               calibration_factor += 10;
            else if(temp == '-' || temp == 'z')
                calibration_factor -= 10;
            }
    }
}

This is the output I am getting without putting any weight :-

Starting ScaleStarting ScaleHX711 calibration sketchRemove all weight from scale After readings begin, place known weight on scalePress + or a to increase calibr ation factorPress - or z to decrease calibration factorZero factor: 0.0000
 Reading: -260.85
 calibration_factor: -7050.00
 Reading: -260.85
 calibration_factor: -705 0.00
 Reading: 311.03
 calibration_factor: -7050.00
 Reading: -260.92
 calibration_fac tor: -7050.00
 Reading: 308.80
 calibration_factor: -7050.00
 Reading: -263.09
 calibr ation_factor: -7050.00
 Reading: -262.50
 calibration_factor: -7050.00
 Reading: -261 .58
 calibration_factor: -7050.00
 Reading: -261.05
 calibration_factor: -7050.00
 Rea ding: -260.85
 calibration_factor: -7050.00
 Reading: -260.84
 calibration_factor: - 7050.00
 Reading: -260.84
 calibration_factor: -7050.00
 Reading: 311.01
 calibration_ factor: -7050.00
 Reading: 311.02
 calibration_factor: -7050.00
 Reading: -260.85
 calibration_factor: -7050.00
 Reading: 311.02

As you can see the reading value keep on changing even i didn’t put any weight on the loadcell.

  • I suppose you have the board and the load cell connected to same ground
  • Did you tried directly getValue()? That should return raw data and when it does same then the “Noise” could come from ADC probably.

BR, Jan

@JohnnyK Yes, whole circuit has common ground and the output of getValue() function is also changing.

calibration_factor: -7050.00
 Get Value: 8711479.00
 Reading: 228.87
 calibration_factor: -7050.00
 Get Value: 8711909.00
 Reading: -343.22
 calibration_factor: -7050.00
 Get Value: 8711607.00
 Reading: -343.18
 calibration_factor: -7050.00
 Get Value: 8711516.00
 Reading: -343.17

This values I am getting without any load.

@JohnnyK I tried this loadcell and HX711 with arduino, it is working perfectly. But for certain requirements I have to run it with Nucleo-F746ZG.

Ok, be so kind make a test please. I would like to see raw data via another library. Try the library what I mentioned in your second topic with this code.

#include "mbed.h"
#include "HX711.h"

DigitalOut      led1(LED1);
HX711           hx711(3.2f, PB_10, PB_11, 32);    // avdd in Volts, sck pin, dout pin, gain
Ticker          ticker;
volatile bool   tick = false;

void onTick(){ tick = true;}

int main()
{
    printf("Starting...\r\n");
    ticker.attach_us(onTick, 500 * 1000);   // 500ms
    hx711.powerUp();
    while (true) {
        if (tick) {
            tick = false;
            led1 = !led1;
            if (hx711.isReady()) {
                float mV = hx711.read();    // read voltage in mV
                printf("hx711 voltage \t= %fmV\r\n", mV);
            }
        }
    }
}

BR, Jan

@JohnnyK As mentioned I tried that code and getting this output :-

Starting...
hx711 voltage   = 1.937038mV
hx711 voltage   = 1.937825mV
hx711 voltage   = 1.936889mV
hx711 voltage   = 1.936609mV
hx711 voltage   = 1.937759mV
hx711 voltage   = 1.936233mV
hx711 voltage   = 1.937980mV
hx711 voltage   = 1.937050mV
hx711 voltage   = 1.937640mV
hx711 voltage   = 1.937026mV
hx711 voltage   = 1.937372mV
hx711 voltage   = 1.937461mV
hx711 voltage   = 1.937002mV
hx711 voltage   = 1.937527mV
hx711 voltage   = 1.936883mV
hx711 voltage   = 1.937020mV
hx711 voltage   = 1.937086mV
hx711 voltage   = 1.936430mV
hx711 voltage   = 1.937586mV
hx711 voltage   = 1.937133mV
hx711 voltage   = 1.937491mV
hx711 voltage   = 1.936817mV
hx711 voltage   = 1.936668mV
hx711 voltage   = 1.937783mV
hx711 voltage   = 1.936376mV
hx711 voltage   = 1.936996mV
hx711 voltage   = 1.936913mV
hx711 voltage   = 1.937592mV
hx711 voltage   = 1.936877mV
hx711 voltage   = 1.937574mV
hx711 voltage   = 1.936931mV
hx711 voltage   = 1.937723mV
hx711 voltage   = 1.937026mV
hx711 voltage   = 1.937127mV
hx711 voltage   = 1.937026mV
hx711 voltage   = 1.937509mV
hx711 voltage   = 1.937372mV
hx711 voltage   = 1.937366mV
hx711 voltage   = 1.937044mV
hx711 voltage   = 1.938176mV
hx711 voltage   = 1.937092mV
hx711 voltage   = 1.937109mV
hx711 voltage   = 1.937765mV
hx711 voltage   = 1.937825mV
hx711 voltage   = 1.937276mV
hx711 voltage   = 1.937115mV
hx711 voltage   = 1.937354mV
hx711 voltage   = 1.936609mV
hx711 voltage   = 1.937390mV
hx711 voltage   = 1.937431mV

The HX711 has two channels A and B. I suppose you use A channel so change

hx711(3.2f, PB_10, PB_11, 32); // B channell only -  fixed gain

to

hx711(3.2f, PB_10, PB_11, 128); 

BR, Jan

@JohnnyK I changed the channel to 128 gain and getting output as :-

hx711 voltage   = 0.483999mV
hx711 voltage   = 0.484565mV
hx711 voltage   = 0.484188mV
hx711 voltage   = 0.484647mV
hx711 voltage   = 0.484482mV
hx711 voltage   = 0.484712mV
hx711 voltage   = 0.484605mV
hx711 voltage   = 0.484432mV
hx711 voltage   = 0.484605mV
hx711 voltage   = 0.484718mV
hx711 voltage   = 0.484386mV
hx711 voltage   = 0.484347mV
hx711 voltage   = 0.484549mV
hx711 voltage   = 0.484532mV
hx711 voltage   = 0.484620mV
hx711 voltage   = 0.484459mV
hx711 voltage   = 0.484642mV
hx711 voltage   = 0.484662mV
hx711 voltage   = 0.484711mV
hx711 voltage   = 0.484614mV
hx711 voltage   = 0.484553mV
hx711 voltage   = 0.484657mV
hx711 voltage   = 0.484712mV
hx711 voltage   = 0.484879mV
hx711 voltage   = 0.484785mV
hx711 voltage   = 0.484404mV
hx711 voltage   = 0.484388mV
hx711 voltage   = 0.484455mV
hx711 voltage   = 0.484563mV
hx711 voltage   = 0.484651mV
hx711 voltage   = 0.484602mV
hx711 voltage   = 0.484599mV
hx711 voltage   = 0.484636mV
hx711 voltage   = 0.484517mV

One more thing

hx711(3.2f, PB_10, PB_11, 128); 

first value “3.2f” is used VDD. I do not know if you use 5V or 3V3 for the HX711 so fill the correct one.

The values above are state without load I suppose, right? What happens when you put on a load?

BR, Jan

@JohnnyK I am using 5V so I changed it to 5.0f. Yes earlier the values was without load only, now I will provide the output with and without loads.
Here are some output with different conditions :-

(Without load) using hx711(5.0f, PB_10, PB_11, 128);

hx711 voltage   = 0.909620mV
hx711 voltage   = 0.907527mV
hx711 voltage   = 0.906764mV
hx711 voltage   = 0.906834mV
hx711 voltage   = 0.907190mV
hx711 voltage   = 0.906936mV
hx711 voltage   = 0.909590mV
hx711 voltage   = 0.759610mV
hx711 voltage   = 0.758956mV
hx711 voltage   = 0.907804mV
hx711 voltage   = 0.759100mV
hx711 voltage   = 0.909234mV
hx711 voltage   = 0.758793mV
hx711 voltage   = 0.908019mV
hx711 voltage   = 0.907851mV
hx711 voltage   = 0.908179mV
hx711 voltage   = 0.770071mV
hx711 voltage   = 0.763186mV
hx711 voltage   = 0.758283mV
hx711 voltage   = 0.908123mV
hx711 voltage   = 0.907462mV
hx711 voltage   = 0.908151mV
hx711 voltage   = 0.907499mV
hx711 voltage   = 0.759105mV
hx711 voltage   = 0.759182mV
hx711 voltage   = 0.758383mV
hx711 voltage   = 0.909066mV
hx711 voltage   = 0.905357mV
hx711 voltage   = 0.907551mV
hx711 voltage   = 0.908591mV
hx711 voltage   = 0.908033mV
hx711 voltage   = 0.907215mV
hx711 voltage   = 0.908838mV
hx711 voltage   = 0.908063mV
hx711 voltage   = 0.907311mV
hx711 voltage   = 0.907863mV

(With load) using hx711(5.0f, PB_10, PB_11, 128);

hx711 voltage   = -18.640808mV
hx711 voltage   = 0.890510mV
hx711 voltage   = 0.891055mV
hx711 voltage   = 1.182256mV
hx711 voltage   = 0.892396mV
hx711 voltage   = 0.901271mV
hx711 voltage   = 0.894687mV
hx711 voltage   = 1.168177mV
hx711 voltage   = -18.346226mV
hx711 voltage   = 0.883453mV
hx711 voltage   = 1.182922mV
hx711 voltage   = 0.890470mV
hx711 voltage   = 1.182936mV
hx711 voltage   = 1.164319mV
hx711 voltage   = 1.188943mV
hx711 voltage   = 1.159518mV
hx711 voltage   = 0.901052mV
hx711 voltage   = 1.161960mV
hx711 voltage   = 0.898901mV
hx711 voltage   = 0.891772mV
hx711 voltage   = -18.350845mV
hx711 voltage   = 1.189052mV
hx711 voltage   = 1.203255mV
hx711 voltage   = 1.141329mV
hx711 voltage   = 1.197574mV
hx711 voltage   = 1.171923mV
hx711 voltage   = 1.185173mV
hx711 voltage   = 1.194438mV
hx711 voltage   = 1.176426mV
hx711 voltage   = 1.200477mV
hx711 voltage   = 0.893609mV
hx711 voltage   = 0.899530mV
hx711 voltage   = 1.176319mV
hx711 voltage   = 0.875597mV
hx711 voltage   = 0.902123mV
hx711 voltage   = 1.140158mV
hx711 voltage   = 0.890214mV
hx711 voltage   = 0.892105mV
hx711 voltage   = 0.886531mV

(Without load) using hx711(5.0f, PB_10, PB_11, 32);

hx711 voltage   = 0.908894mV
hx711 voltage   = 0.748546mV
hx711 voltage   = 0.876186mV
hx711 voltage   = -10.092596mV
hx711 voltage   = -10.075344mV
hx711 voltage   = 0.896587mV
hx711 voltage   = 0.915525mV
hx711 voltage   = 0.751985mV
hx711 voltage   = 0.747035mV
hx711 voltage   = 0.895616mV
hx711 voltage   = 0.882146mV
hx711 voltage   = -10.089876mV
hx711 voltage   = 0.881094mV
hx711 voltage   = -14.972689mV
hx711 voltage   = 0.878465mV
hx711 voltage   = 0.751524mV
hx711 voltage   = 0.882146mV
hx711 voltage   = 0.891362mV
hx711 voltage   = 0.910489mV
hx711 voltage   = 0.749857mV
hx711 voltage   = 1.180170mV
hx711 voltage   = 0.014531mV
hx711 voltage   = 0.018852mV
hx711 voltage   = 0.014107mV
hx711 voltage   = 0.017951mV
hx711 voltage   = 0.879222mV
hx711 voltage   = 0.909872mV
hx711 voltage   = 0.874475mV
hx711 voltage   = 0.921069mV
hx711 voltage   = -18.617239mV
hx711 voltage   = -16.200815mV

(With load) using hx711(5.0f, PB_10, PB_11, 32);

hx711 voltage   = 1.153243mV
hx711 voltage   = -9.765642mV
hx711 voltage   = 1.159825mV
hx711 voltage   = -0.000002mV
hx711 voltage   = 0.885488mV
hx711 voltage   = -9.804270mV
hx711 voltage   = -9.854559mV
hx711 voltage   = 0.015143mV
hx711 voltage   = 3.662107mV
hx711 voltage   = 0.885252mV
hx711 voltage   = -11.031088mV
hx711 voltage   = -9.787907mV
hx711 voltage   = -18.373295mV
hx711 voltage   = -12.265192mV
hx711 voltage   = 1.159266mV
hx711 voltage   = 1.105506mV
hx711 voltage   = 0.013164mV
hx711 voltage   = 0.016380mV
hx711 voltage   = 0.885180mV
hx711 voltage   = -18.373075mV
hx711 voltage   = 1.159858mV
hx711 voltage   = 0.885783mV
hx711 voltage   = 1.160689mV
hx711 voltage   = 1.159345mV
hx711 voltage   = 1.155280mV
hx711 voltage   = 0.884561mV
hx711 voltage   = 0.882698mV
hx711 voltage   = -18.383577mV
hx711 voltage   = 0.906196mV
hx711 voltage   = 1.155087mV
hx711 voltage   = 1.140900mV
hx711 voltage   = 1.156917mV
hx711 voltage   = -18.374176mV
hx711 voltage   = 1.159881mV

Strange the result with 3.2 was stabile and with 5 seems to be broken.

Do not use the gain 32 if you do not reconnect wires to channel B on HX711.

I ordered my own load cell with HX711 because I was also interested about this. So please give a time, it will be eazy when I will have it in my hands.

BR, Jan

@JohnnyK Exactly the output is not stabilized, so it’s became difficult to calibrate.

I really appreciate your efforts to help me with this problem. I’ll be waiting for your response and till the time I will also try to find some alternative solutions.

Hi @JohnnyK, I read the datasheet and try the excitation voltage with 9V and 12V but the loadcell output have more unstabilized output.
I think 5V only can have accurate reading, but now I am unable to get it.

Hello,

Datasheet of Hx711 saying 5.5V max. So 9V+ does not seem to be safe and can lead to damage of the IC.

BR, Jan

@JohnnyK No, I am talking about loadcell datasheet, you can check


Here excitation voltage is shown 9 -12 V.

I really appreciate your effort that you put for me whenever I am facing problem.
Still I am not getting the expected results. I tried so many times.
Could please help me on this and kindly tell me if any alternative solutions is there.

Hello,

I did not forget. But my package was still not delivered, I expect it very soon.

BR, Jan