Remove Text Formatting
Loading...

+ Reply to Thread
Results 1 to 20 of 20
  1. #1
    Join Date
    Sep 2016
    Posts
    23

    Default how to use HX711 Load Cell Module

    Hi,

    I want to use HX711 to my Weighing Scale.Iam new to External ADC.

    I Have Read Data sheet but Not able to write program.

    Pls help.

  2. #2
    Join Date
    Oct 2009
    Posts
    537

    Default Re: how to use HX711 Load Cell Module

    May not help directly, but there are plenty of arduino projects that you might be able to reverse engineer to work in PBP https://github.com/sparkfun/HX711-Lo...ier/tree/V_1.1

  3. #3
    Join Date
    Apr 2014
    Posts
    55

    Default Re: how to use HX711 Load Cell Module

    You didn't say anything about what you're trying to do, nor which MCU you want to use. For starters, readings will be 3 bytes long, so using a PIC18FXX series processor will allow you to store ADC values as LONGs. Furthermore, the ADC value will be signed ($800000 - $FFFFFF). LONGs work out very well for that.

    It looks like the software portion of operating this HX711 is fairly simple. I'll skip the SFRs etc and just get to the function part of code:

    Code:
    Weight VAR LONG
    b0 VAR BYTE
    DOUT VAR PORTA.0
    PD_SCK VAR PORTA.1
    
    Mainloop:
    LOW PD_SCK
    IF DOUT = 0 THEN
     FOR b0 = 25 TO 1 STEP -1 ;This would be for 128X Gain, use 26 for 64X or 1 TO 27 for 32X
      HIGH PD_SCK
      PAUSE 100
      Weight.b0 = DOUT
     NEXT b0
    ;More code
    This will allow retrieval of the individual bits at a 10 Hz rate as specified in the HX711 Data Sheet. It is capable of an 80 Hz rate. This would require a PAUSEUS 12500 (12.5 ms). Bits are shifted out MSB First, so the first bit will be Weight.23, then Weight.22 right on down to Weight.0 (where the number after the variable is for the individual bit within the LONG variable).

    There are hardware options listed in the Data Sheet as well. I only wanted to help you with the basic code for retrieving the data.

  4. #4
    Join Date
    Sep 2009
    Posts
    616

    Default Re: how to use HX711 Load Cell Module

    Where in loop you set clock to 0?

  5. #5
    Join Date
    Apr 2014
    Posts
    55

    Default Re: how to use HX711 Load Cell Module

    Quote Originally Posted by pedja089 View Post
    Where in loop you set clock to 0?
    Oops, good eye.
    For bo...
    HIGH PD_SCK
    PAUSE 100
    Weight.b0 = DOUT
    LOW PD_SCK
    PAUSE 100

    NEXT b0

    According to the Data Sheet, you can reduce PAUSE times until communication gets fuzzy, then back off a couple ms.

  6. #6
    Join Date
    Sep 2016
    Posts
    23

    Default Re: how to use HX711 Load Cell Module

    TRIED YOUR CODE WITH MY CODE.
    PROBLEM IS THAT IT ONLY SHOW 000001 (BLINK FREQUENTLY)

    '************************************************* ***************
    '* Name : UNTITLED.BAS *
    '* Author : [select VIEW...EDITOR OPTIONS] *
    '* Notice : Copyright (c) 2017 [select VIEW...EDITOR OPTIONS] *
    '* : All Rights Reserved *
    '* Date : 3/1/2017 *
    '* Version : 1.0 *
    '* Notes : *
    '* : *
    '************************************************* ***************
    'LOAD INDICATOR 16F877A'


    b0 VAR BYTE
    DOUT VAR PORTC.4
    PD_SCK VAR PORTC.3



    DG1 VAR WORD
    DG2 VAR WORD
    DG3 VAR WORD
    DG4 VAR WORD
    DG5 VAR WORD
    DG6 VAR WORD
    I VAR BYTE
    DIGIT VAR byte
    DG VAR byte
    COUNTT VAR BYTE
    N VAR word


    TRISA=0
    TRISB=0
    TRISC=%00010000
    TRISD=1
    TRISE=0
    ADCON0=7
    CMCON=7
    ADCON1=7

    GOSUB DISPLAY




    MAIN:

    LOW PD_SCK
    IF DOUT = 0 THEN MAIN
    FOR b0 = 0 TO 23
    HIGH PD_SCK
    N= DOUT
    LOW PD_SCK
    NEXT b0
    GOSUB DISPLAY
    GOSUB DIGITCALC
    GOTO MAIN


    __________________________________________________ _
    DISPLAY: ' 'DATA FOR DG1,DG2,DG3,DG4,DG5,DG6 IS PUT ON PORTC AND THE CORRESPONDING
    'PINS ON PORTB TOGGLED
    'THIS IS DONE 100 TIMES


    FOR COUNTT=0 TO 99

    PORTB=DG1
    PORTA.5=0
    PAUSEUS 100
    PORTA.5=1

    PORTB=DG2
    PORTA.4=0
    PAUSEUS 100
    PORTA.4=1

    PORTB=DG3
    PORTA.3=0
    PAUSEUS 100
    PORTA.3=1

    PORTB=DG4
    PORTA.2=0
    PAUSEUS 100
    PORTA.2=1

    PORTB=DG5
    PORTA.1=0
    PAUSEUS 100
    PORTA.1=1

    PORTB=DG6
    PORTE.0=0
    PAUSEUS 100
    PORTE.0=1

    NEXT COUNTT

    RETURN


    DIGITCALC: ''THIS ROUTINE BREAKS UP THE NUMBER INTO 3 DISTINCT PARTS - DG1,DG2,DG3,DG4,DG5,DG6
    'NOTICE THAT ANOTHER SUBROUTINE IS CALLED EACH TIME


    DIGIT=0
    LP1:
    IF N<10000 THEN DS1
    N=N-10000
    DIGIT=DIGIT+1
    GOTO LP1
    DS1:
    GOSUB FND
    DG1=DG
    DIGIT=0
    LP2:
    IF N<1000 THEN DS2
    N=N-1000
    DIGIT=DIGIT+1
    GOTO LP2
    DS2:
    GOSUB FND
    DG2=DG


    DIGIT=0
    LP3:
    IF N<100 THEN DS3
    N=N-100
    DIGIT=DIGIT+1
    GOTO LP3

    DS3:
    GOSUB FND
    DG3=DG


    DIGIT=0
    LP4:
    IF N<10 THEN DS4
    N=N-10
    DIGIT=DIGIT+1
    GOTO LP4

    DS4:
    GOSUB FND
    DG4=DG


    DIGIT=N
    GOSUB FND
    DG5=DG

    RETURN




    '_________________________________________________ _________________________


    '_________________________________________________ _________________________
    FND: ''THIS ROUTINE IDENTIFIES THE SEGMENTS TO LIGHT UP

    '7 SEGMENTS WIRED UP AS FOLLOWS

    'A -PORTB.7
    'B -PORTB.6
    'C -PORTB.5
    'D -PORTB.4
    'E -PORTB.3
    'F -PORTB.1
    'G -PORTB.2
    'DECMAL=PORTB.0

    FND0:
    IF DIGIT>0 THEN FND1
    DG=%00000101
    GOTO FNDEND

    FND1:
    IF DIGIT>1 THEN FND2
    DG=%10011111
    GOTO FNDEND

    FND2:
    IF DIGIT>2 THEN FND3
    DG=%00100011
    GOTO FNDEND

    FND3:
    IF DIGIT>3 THEN FND4
    DG=%00001011
    GOTO FNDEND

    FND4:
    IF DIGIT>4 THEN FND5
    DG=%10011001
    GOTO FNDEND

    FND5:
    IF DIGIT>5 THEN FND6
    DG=%01001001
    GOTO FNDEND

    FND6:
    IF DIGIT>6 THEN FND7
    DG=%01000001
    GOTO FNDEND

    FND7:
    IF DIGIT>7 THEN FND8
    DG=%00011111
    GOTO FNDEND

    FND8:
    IF DIGIT>8 THEN FND9
    DG=%00000001
    GOTO FNDEND

    FND9:
    DG=%00011001

    FNDEND:
    RETURN
    '______________________________

  7. #7
    Join Date
    Sep 2009
    Posts
    616

    Default Re: how to use HX711 Load Cell Module

    First N VAR LONG 'You have 23bits, so you need place to store them.
    Second in FOR loop you assign always same bit in N. N=DOUT should be N.0[bo]=DOUT

  8. #8
    Join Date
    Sep 2016
    Posts
    23

    Default Re: how to use HX711 Load Cell Module

    IAM USING 16F877A

    THIS CODE DISPLAYS 65535 .


    MAIN:
    DOUT=1
    LOW PD_SCK
    IF DOUT = 0 THEN MAIN
    FOR b0 = 0 TO 23 ;This would be for 128X Gain, use 26 for 64X or 1 TO 27 for 32X
    HIGH PD_SCK

    N.0[b0] = DOUT
    LOW PD_SCK
    NEXT b0

  9. #9
    Join Date
    Sep 2009
    Posts
    616

    Default Re: how to use HX711 Load Cell Module

    You can't store 23bit to single word.

  10. #10
    Join Date
    Sep 2016
    Posts
    23

    Default Re: how to use HX711 Load Cell Module

    if i want to use only 16 bits

  11. #11
    Join Date
    Sep 2016
    Posts
    23

    Default Re: how to use HX711 Load Cell Module

    iam using picbasic pro 2.60

  12. #12
    Join Date
    Sep 2009
    Posts
    616

    Default Re: how to use HX711 Load Cell Module

    Just reject lower 16bits.
    Try something like this
    IF b0>7 then N.0[b0-8]=...
    Did you set pin to input?
    And if so, why you try to set it to 1?

  13. #13
    Join Date
    Apr 2014
    Posts
    55

    Default Re: how to use HX711 Load Cell Module

    Quote Originally Posted by Kritika View Post
    IAM USING 16F877A

    THIS CODE DISPLAYS 65535 .


    MAIN:
    DOUT=1
    LOW PD_SCK
    IF DOUT = 0 THEN MAIN
    FOR b0 = 0 TO 23 ;This would be for 128X Gain, use 26 for 64X or 1 TO 27 for 32X
    HIGH PD_SCK

    N.0[b0] = DOUT
    LOW PD_SCK
    NEXT b0
    It looks like you gave it the answer before you asked the question. DOUT should be set as an input (TRIS pin = 1) in which case "DOUT = 1" in an inappropriate statement.

    You might want to look at the possibility of using a PIC18F processor for this project so you are able to use LONG variables.

  14. #14
    Join Date
    Sep 2016
    Posts
    23

    Default Re: how to use HX711 Load Cell Module

    GOT INSANE, TILL NOW NO SUCESS

    CHANGED MY CODE TO

    MAIN:
    ADDO=1
    ADSK=0
    COUNTY=0
    IF ADDO=0 THEN MAIN
    FOR b0 = 1 to 24
    ADSK=1
    COUNTY=COUNTY*10
    ADSK=0

    IF ADDO=1 THEN COUNTY=COUNTY+1

    ADSK=1
    county = county xor 65535
    n.0[b0]=county
    ADSK=0


    NEXT b0

  15. #15
    Join Date
    Apr 2014
    Posts
    55

    Default Re: how to use HX711 Load Cell Module

    If I want to play with USB, I buy a couple PIC18F25K50's. If I want to build an ignition timing controller, I buy a couple PIC16F1619's. You seemed determined to stick with the PIC16F877A. Would you be willing to spend the minimal amount of money for even a PIC18F45K22 (40 pins with same power supply pins as your PIC16F877A) if that means you get your project launched? I doubt the Great Pyramid on the Giza Plateau was built with bronze chisels (if you get my drift).

  16. #16
    Join Date
    May 2013
    Location
    australia
    Posts
    1,189

    Default Re: how to use HX711 Load Cell Module

    HX711_reading =$AABBCC and would be stored little-endian. I.E. if the address
    of HX711_reading starts at 30h, then $CC will be stored at 30h followed by $BB at 31h followed by $AA at 32h

    HX711_reading VAR BYTE[3]
    HX711_upper var word

    Then read your 24 bits into the array in little-endian style from the HX711

    then the upper 16 bits can be used

    HX711_upper = HX711_reading[1]+HX711_reading[2]*256

    no need for long , simple

    if you use an word EXT reference to the array address +1 the above calc can be avoided entirely

    eg
    @ HX711_upper = HX711_reading+1
    HX711_upper var word EXT
    This is more entertaining than Free to Air TV

  17. #17
    Join Date
    May 2013
    Location
    australia
    Posts
    1,189

    Default Re: how to use HX711 Load Cell Module

    one more thing if you spend a few minutes searching the forum you will find
    PutMulResult?D macro
    and
    GetMulResult?D macro

    which enable you to do 32 bit divides with pic16's and 12's with div32
    there are examples using 32 bit constants as well as arrays
    even getting and using the remainder too
    This is more entertaining than Free to Air TV

  18. #18
    Join Date
    Sep 2016
    Posts
    23

    Default Re: how to use HX711 Load Cell Module

    I GOT Fluctuating VALUES BY THIS CODE

    MAIN:

    DOUT=1
    LOW PD_SCK
    IF DOUT = 0 THEN MAIN
    FOR b0 = 1 TO 16 ;This would be for 128X Gain, use 26 for 64X or 1 TO 27 for 32X
    HIGH PD_SCK
    N.0[B0]=DOUT


    LOW PD_SCK
    NEXT b0.


    HOW CAN I MAKE THESE VALUES STABLE


    65535.........12584......

  19. #19
    Join Date
    May 2013
    Location
    australia
    Posts
    1,189

    Default Re: how to use HX711 Load Cell Module

    HOW CAN I MAKE THESE VALUES STABLE
    by interpreting the data correctly
    1, the HX711 clocks out the data MSB first , you are storing it as if LSB is first
    2, @128 gain the NX711 yields 25 bits of data , if you only read 16 of them you may need to reset the NX711 after read
    3, the dout data is ready to read immediately after the clk pulse not during
    4, the HX711 signals data ready by setting dout low
    Last edited by richard; - 21st September 2017 at 23:00.
    This is more entertaining than Free to Air TV

  20. #20
    Join Date
    Apr 2014
    Posts
    55

    Default Re: how to use HX711 Load Cell Module

    Get rid of "DOUT = 1"

Similar Threads

  1. Load needed for circuit to work ?
    By lerameur in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 6th May 2012, 09:48
  2. Patch 2.60a refuses to load
    By BrianT in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 27th July 2010, 12:33
  3. Load caps
    By grounded in forum Off Topic
    Replies: 0
    Last Post: - 30th November 2009, 15:43
  4. Measuring mains load
    By Freman in forum General
    Replies: 6
    Last Post: - 13th June 2008, 00:33
  5. ADC Load
    By CocaColaKid in forum General
    Replies: 3
    Last Post: - 19th November 2004, 12:43

Members who have read this thread : 19

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts