HX711 load cell issues

britney123

New member
Hi all

I'm new to these forums and picaxe/microcontrollers in general and I was hoping to get some help integrating with a hx711 load cell amplifiers.

I've started my programming journey with an ambitious project of automating a keg fridge. I currently have temp control, differential temp equalising fan and a led display working. However, the "cool" part of this project is a weight sensor that sits under the keg to tell me how much beer is left in it. This is what I cant get working

I purchased a digital scale kit from eBay that included 4 load cells and a hx711. After some googling on how to interface with this unit, I was directed to this forum where there are several code examples on how to do this. Being a beginner programmer I have followed the code examples and tried to understand what I can along the way. My code seems to work in simulation yet when I connect the HX711 to the picaxe and run it the low medium and high stored values all go high no matter what weight is on the cells

Ive tried several different varients of code and have been pulling my hair out for weeks trying to get it to work.

If someone would be able to run there eyes over my code and tell me what I'm doing wrong it would be greatly apreciated

Thanks in advance
 

Attachments

AllyCat

Senior Member
Hi,

Welcome to the forum. It's "nice" if you post a link to the sensor in question, and personally I prefer code "in line" (i.e within [ code ] tags) , so that I don't have to clutter up my PC with other people's (non-working) files. ;) But the data was easy enough to find.

The usual way to solve problems like this is to include SERTXD commands to confirm that the data you're receiving / processing is what you think it should be. For example at the end of the following section:

Code:
    for weight_bit_count = 0 to 7
        pulsout c.1, 1        ;pulses c.1 for 1 millisecond
        weight1_low = weight1_low * 2 | pinc.0    ;add the data from hx711 to the byte, shifting bits by multipying by 2 and OR'ing
    next
    pulsout c.1, 1            ;clears the last last bit from the hx711
    next weight_loop_count
    weight_loop_count = 0
    weight1_mid = b28                ;stores mid and low bytes into current weight word
    weight1_low = b29
SERTXD("Weight = ",#weight1_mid," : " ,#weight1_low)
As far as I can see, b28 and b29 (or w14) are not used elsewhere in the program, so will be at the default zero value(s). What did you intend to do?

BTW the data sheet says the maximum High Pulse width is 50 us, but your comment is incorrect, a PULSOUT... 1 generates a pulse 10 us wide, not 1 ms.

Cheers, Alan.
 

hippy

Technical Support
Staff member
I would go further than AllyCat and suggest the best starting point is to create a side-project to get the individual parts of hardware working separate to the main program.

This is what I'd start with, untested, but hopefully matches what you have, clock on C.1 and data on C.0 ...
Code:
#Picaxe 28X2						
#Terminal 9600
#No_Data
#No_Table

Symbol CLK = C.1
Symbol DIN = C.0 : Symbol DIN_PIN = pinC.0

Symbol reserveW0 = w0 ; b1:b0
Symbol reserveW1 = w1 ; b3:b2

Symbol bitCount  = b4
Symbol digitPair = b5
Symbol digitLsb  = b6
Symbol digitMsb  = b7

PowerOnReset:
  Input DIN
  High  CLK
  Paue 2000
  Low   CLK

MainLoop:
  SerTxd( "Started", CR, LF )
  Do
    Gosub Read_HX711
    SerTxd( "$" )
    digitPair = b2 : Gosub ShowHexDigitPair
    digitPair = b1 : Gosub ShowHexDigitPair
    digitPair = b0 : Gosub ShowHexDigitPair
    Sertxd( CR, LF )
    Pause 1000
  Loop

Read_HX711:
  Gosub Read_Channel_A_Gain_128
  Return

Read_Channel_A_Gain_128:
  Gosub Read_24bits
  PulsOut CLK, 1
  Return

Read_Channel_B_Gain_32:
  Gosub Read_24bits
  PulsOut CLK, 1
  PulsOut CLK, 1
  Return

Read_Channel_A_Gain_64:
  Gosub Read_24bits
  PulsOut CLK, 1
  PulsOut CLK, 1
  PulsOut CLK, 1
  Return

Read_24bits:
  Do : Loop Until DIN_PIN = 0
  w1 = 0
  w0 = 0
  For bitCount = 1 To 24
    PulsOut CLK, 1 
    w1 = w1 + w1 + bit15
    w0 = w0 + w0 + DIN_PIN
  Next
  Return

ShowHexDigitPair:
  digitMsb = digitPair / $10 + "0" : If digitMsb > "9" Then : digitMsb = digitMsb + 7 : End If
  digitLsb = digitPair & $0F + "0" : If digitLsb > "9" Then : digitLsb = digitLsb + 7 : End If
  SerTxd( digitMsb, digitLsb )
  Return
 

mortifyu

New Member
Hi,

That is a mighty fine effort, being that you consider yourself a 'beginner programmer'.

Good job!


Regards,
Mort.
 

britney123

New member
Hi Everyone

Thanks so much for the encouragement and speedy replies.

So I've had a go at running hippys code in my setup and the terminal is giving a constant reading of $7FFFFF no matter what weight is on the scale. This appears to follow the output I was getting when I ran my code. From the datasheet for the hx711 that value appears to be the max input range. Does this mean that the input from the loads cells it too high?

I've attached a few pics of the load cell kit that I purchased from eBay as well as a wiring diagram of how I have it connected to my picaxe. I'm relatively sure that it's connected right but if you have any pointers it would be greatly appreciated

Thanks
 

Attachments

hippy

Technical Support
Staff member
From the datasheet for the hx711 that value appears to be the max input range. Does this mean that the input from the loads cells it too high?
Could be. It might be worth replacing "Gosub Read_Channel_A_Gain_128" with "Gosub Read_Channel_A_Gain_64" in my code's "Read_HX711:" routine and trying that, but that's mostly clutching at straws.

That you are reading $7FFFFF not $000000 or $FFFFFF or random numbers would suggest the wiring is correct and that is what the HX711 is reporting.

It could be that the cells you have are wired differently to what the board expects but if they are part of the same kit I would expect them to be compatible.

I am wondering if the "PulsOut CLK,1" is creating a pulse which is too long so causing the HX711 to go into power-down mode. I wouldn't have thought it would be, but might be worth trying ...
Rich (BB code):
    SetFreq M16
    Gosub Read_HX711
    SetFreq M8
I'm not familiar with load-cell wiring but it might be worth investigating how you could create a faked load-cell which gives a near zero reading. If we can read somthing other than $7FFFFF back from the HX711 that will give added confidence that it is working, that meaningful data can be read.

It might also be worth taking a close look at the board to see exactly what chip is fitted in case it is slightly different to the one we think it is and has some subtle difference.

Added : I recall the datasheet suggesting the B-/B+ channel could be used to measure battery voltage, so it might be an idea to figure out how it can be wired to do that, reading a 1.5V battery perhaps. Will have a read of the datasheet. Just changing to "Gosub Read_Channel_B_Gain_32:" in the "Read_HX711;" routine will allow that.

Actually, it might be worth doing that, putting a finger across B-/B+ maybe touching 0V as well might cause some numbers different to $7FFFFF.
 
Last edited:

mortifyu

New Member
Hi,

I would suspect reducing the gain should provide a different result even if it is incorrect.

I am wondering why you have placed pull down resistors on the CLOCK and DATA lines?

To confirm all is at least well from DATA out of the module, if you were to disconnect the DATA line from the module and then put a 10K pullup between 5V and the DATA input pin of the PICAXE, then make 'dirty' connections from GND to the DATA input pin of the PICAXE, you should be able to see random different values appear. If there was no change by firstly lowering the GAIN and you then did this test aswell, I would then more likely suspect a wiring issue at the load cell end of town.

Hope this helps.



Regards,
Mort.
 

AllyCat

Senior Member
Hi,

It's disconcerting that the two diagrams in the first picture show different resistor sequences : R1, R2, R3, R4 and R1, R2, R4, R3. :(

It appears that each sensor has three wires, so two resistor / strain gauges in each? That might allow them to be used in either differential or summing mode, but I don't think you've shown us exactly how you've wired them?

Indeed, the data sheet says that 7FFFFF represents a "Saturated Maximum", so I would be looking for a wiring error (probably open circuit) somwhere in the bridge circuit.

Cheers, Alan.
 
Last edited:

hippy

Technical Support
Staff member

britney123

New member
Hi Everyone

So I've read up on Wheatstone bridges and strain gauges. After a bit of prodding and poking with my multimeter, I discovered that the 3 wire load cells I have are simply two strain gauges in a voltage divider configuration (not sure if this is the right term - new to electronics). From this, I drew out the circuit and realised that the wiring diagram from the eBay seller was wrong (I've attached a rough sketch of this).

With the circuit wired in this configuration, I am able to get a variable output from the HX711 unit using Hippys code. Success!!! The output is bouncing about but it appears to be within a consistent range when I put test weights on and off the sensor. Now I just need to figure out how to integrate hippys code into mine. I'll keep you all posted on how I'm going

Thank you all so much for your help. I was close to abandoning the project but now I've got the spark to finish it off
 

Attachments

premelec

Senior Member
Two series resistances in this case are a half bridge... glad you have it sorted out and ask it you have further questions...
 
Top