B4R Tutorial HX711 code module

Discussion in 'B4R Tutorials' started by Mostez, Sep 19, 2018.

  1. Mostez

    Mostez Active Member

    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:
    Code:
    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:
    Code:
    private Sub GetWeight(RawUnits As Long, UnitMeasure As StringAs 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:
    Code:
    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
     

    Attached Files:

    Last edited: Sep 20, 2018
  2. Peter Simpson

    Peter Simpson Expert Licensed User

    Saved me from looking into it, cheers @Mostez.

    Nice job :)
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice