HX711 Erratic Calibration

# Thread: HX711 Erratic Calibration – 127 days old

1. 0

## HX711 Erratic Calibration

Dear.
I am doing a small project with a PIC 16F877A, HX711 and a load cell of 150 Kg, at the moment I am simulating in Proteus 8.

I have problems with the calibration or adequacy of the signal of the HX711.
I can already read the module and see the weight that is in the load cell on an LCD, but the measurement is incorrect, as the value increases, the difference is greater. if I perform a tare or zero the difference is greater.

I would like to know if it is a simulation problem or my code.

I have reviewed in the forum and can not find how the HX711 is calibrated despite the fact that there is a topic entitled "Calibration HX711"

the code i am using:

Code:
```LoadCell:
Dataa = 1
Clock = 0
Hx711Cnt = 0
While Dataa = 1 : Wend
For i = 0 To 23
High Clock
Hx711Cnt = Hx711Cnt <<1
Low Clock
If Dataa = 1 Then Inc Hx711Cnt
Next
High Clock
Hx711Cnt = Hx711Cnt^0x800000
gram = ((Hx711Cnt-124000)*10)/500
gram = gram - 165090
gram = gram / 1000
Low Clock
Print At 2,1, "   Peso: ",Dec1 gram,"Kg   "

2. Attention
×

This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

If you can, please report issues in the forum area WebSite / Forum Issues

3. 0

## Re: HX711 Erratic Calibration

Hello,

You need to take at least two measurements, one for tare/offset with no weight and another with a well know weight. So you can calculate the real sensitivity of your load cell. Pay attention to the HX711 gain selection when reading it (datasheet page 4)

Ricardo Urio

4. Attention
×

This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

If you can, please report issues in the forum area WebSite / Forum Issues

5. 0

## Re: HX711 Erratic Calibration

I worked with that and I set the simulation hardware as real as possible.
You should consider your mV/V factor on the cell properties. Also to consider that the variation is in percentage rather than the real value. So if your cell is at 50% it should have a result of 25 Kg, as per 50 Kg cell.

You might use my procedure to read the cell

Code:
```\$define DEBUG 0                   ' no debugging
\$define MAXSAMPLES 40             ' set at least 40 samples
Dim avrg As Dword
Dim coun As Dword
Dim cnti As Byte
Dim cntn As Byte
Clear timed_out                 ' reset the flag
Clear avrg                      ' average variable counter
Clear cnti                      ' reset value
Clear ADSK                      ' lowering the clock pin
' next instruction gives a little delay before reading the input
Clear cntn                      ' reset value
Repeat                          ' loop over the wanted samples
Clear coun                    ' resetting the variable for the result
While ADDO = 1                ' probing the data pin to wait the start
If cnti < 250 Then          ' counting a time-out in case the cell fails
DelayMS 1                '  for one round
Else                        ' if exceeds
Set timed_out             ' flag a no ready signal
Return                    ' leave the subroutine
End If
Inc cnti                    ' keep counting track
Wend                          ' end of wait ADD0
cnti = 24                     ' reset the counter
Clear coun                    ' resetting the variable for the result
Clear INTCON.7                ' atomic operation no interrupts
Repeat                        ' counting for 24 bits
ADSK= 1                     ' ticking the serial clock
coun = coun << 1            ' shift left the variable
Clear ADSK                  ' reset the clock
Dec cnti
Until cnti <= 0                ' loop for the next bit
Set INTCON.7                  ' atomic operation completes, OK interrupts
Set ADSK                      ' reset the clock high
coun = coun ^ \$800000
Clear ADSK                    ' toggle last bit for 128 gain
\$if DEBUGGER == 3
HSerOut ["coun = ", Dec coun]
sendCRLF
\$endif
avrg = avrg + coun            ' sum the sample to the average value
Inc cntn
Until cntn >= MAXSAMPLES
' calculate the returned value
EndProc```
There no returning result, the global variable reading will gives the current value.
If you are interested I'll will publish the source on my Google drive.

6. Attention
×

This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

If you can, please report issues in the forum area WebSite / Forum Issues

7. 0

## Re: HX711 Erratic Calibration

honesty, I couldn't use your code, I've never used Proc...EndProc
I checked the manual and I understood the behavior, but I don't know how to couple it to my code.
How is the Proc called?

8. Attention
×

This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

If you can, please report issues in the forum area WebSite / Forum Issues

9. 0

## Re: HX711 Erratic Calibration

The use might be just as follow
Code:
```  readHX711()                       ' first reading
If timed_out = 1 Then             ' result is not available
offset = ZERO_OFFSET            ' use the default
Clear timed_out                 ' reset the flag
Else
offset = reading                ' value is good, set the current offset
End If                            ' <END> timeout == 1
Clear lastread                    ' force to refresh the display```
For a complete understanding in a real project you may download it. Forgive me if I haven't provided a English documentation. In case you will request I'll prepare one for you. Additionally you might have a look at this site, even that is an Italian document, but WordPress might translate it on the fly for you.

10. Attention
×

This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

If you can, please report issues in the forum area WebSite / Forum Issues