B4R Tutorial HX711 code module

Hello;
this code module is for using HX711 load cell amplifier board with Arduino, I used it with UNO and MEGA without any problems, only 4 pins are required for voltage supply and communication (+5V, GND, CLK and DT). the code is very easy to use (thanks @rwblinn for help) code module includes most of original C++ library functions.

call this procedure to initialize scale:
B4X:
private Sub InitializeScale()
    HX711.Begin(3,2,128)
    HX711.Raed        ' read raw data from the ADC
    HX711.setscale(300)    ' this value is obtained by calibrating the scale with known weights
    Delay(100)
    HX711.tare()
End Sub

this function does weight calculations:
B4X:
private Sub GetWeight(RawUnits As Long, UnitMeasure As String) As String
    Dim weight As Double
    Dim Tmps As String
    Select UnitofMeasure
        Case "G" 'grams
            weight = RawUnits
            Tmps = NumberFormat(weight,1,0)
        Case "K" 'kilo grams
            weight = RawUnits /1000
            Tmps = NumberFormat(weight,1,3)
        Case "O" 'oz
            weight = RawUnits * 0.0352739619
            Tmps = NumberFormat(weight,1,3)
        Case "P" 'pounds
            weight = RawUnits * 0.0352739619 * 0.0625
            Tmps = NumberFormat(weight,1,3)
    End Select
    Return Tmps
End Sub


to get weight:
B4X:
Dim weight As String = GetWeight(HX711.GetUnits(2)) 'number of samples to read
Log(weight)


Connecting load cell to HX711 board and Arduino
loadcell_hx711.jpg
 

Attachments

  • HX711.bas
    2.2 KB · Views: 417
Last edited:
Top