News:

;) This forum is the property of Proton software developers

Main Menu

HX711 Loadcell / differential serial amplifier chip

Started by chris_cb_uk, Oct 29, 2021, 02:36 PM

Previous topic - Next topic

chris_cb_uk

Just to save anybody else wanting to play with these inexpensive loadcells and chips (picked it up from ebay in uk for less than £6 reading up to 20kg)  I've included some working code.

Once I got my head around the serial side it was very easy. The device has a variable gain structure which is set by sending the corresponding clock pulses.  Important to say that if you change the gain, you need to read the following serial data after the clock pulses you send, so effectively it's a data set behind.
The pulse table 3 on datasheet as follows:
25 pulses input chA gain 128
26 pulses input chB gain 32
27 pulses input chA gain 64

I made a little jig to mount the loadcell bar on to a set of scales so I could get the right weights / variable numbers to crunch the scales and display the weight correctly.  My measurement 0 is a size of 883, and there is no tare function on this code.  It's not something I need as this project is for indicating rough shear forces when pulling something so the device can slow down / create an alarm if it rapidly shoots up.   



Device = 18F4550
    Declare Xtal = 16
               
  Symbol loadclock PORTD.1
  Symbol loaddata  PORTD.2

  Dim loadraw As Word
  Dim rubbish  As Word
  Dim loadcellout As Word
  Dim calculatedload As Word
  Dim loadc As Byte

 Start:  If loaddata =1 then bypassmeasure ' if data line low it's ready, if not bypass until next try.
            Print $FE, 1                                                    ' reset screen
            SHIn loaddata,loadclock,MsbPost_L,[loadraw\16,rubbish\9]        ' shift in with 25 bits for gain 128 ch A
            calculatedload= (loadraw-883)*2.477291495                           ' 883 is 0g constant, have already calculated new scale based on 3kg = 2094, given ratio of 2.477 ish


bypassmeasure:
        Print At 1,1,Dec loadraw
        Print At 2,1, Dec calculatedload," g"
       DelayMS 100                                                         
       GoTo Start

trastikata

Quote from: chris_cb_uk on Oct 29, 2021, 02:36 PMJust to save anybody else wanting to play with these inexpensive loadcells and chips (picked it up from ebay in uk for less than £6 reading up to 20kg)  I've included some working code.

If this is something that needs reliability, I'd stay away from HX711 - my experience with it is overall not too positive.

I'd go with an inexpensive IA from AD or TI, 5v 0.5% LDO regulator plus couple of caps to ground and the PIC's internal 10b or 12b ADC with the built-in bandgap VREF. The overall cost will be the same but the stability, accuracy and reliability will be better.     

chris_cb_uk

Quote from: trastikata on Oct 29, 2021, 03:40 PMIf this is something that needs reliability, I'd stay away from HX711 - my experience with it is overall not too positive.     

In what way didn't it work for you?

trastikata

Quote from: chris_cb_uk on Oct 29, 2021, 04:17 PMIn what way didn't it work for you?

High zero drift and noisy data, noise free data was at much lower resolution - around 13-14 bits. 

chris_cb_uk

Fair enough, as I said in my post though it's just for giving a rough indication of shear force for a project where accuracy isn't important.  I just need to know if when something is being pulled if it snags and needs to be able to raise an alarm. 
I observed the noisy data bits on a scope which is why I read in details up to 16 bits, repeatability of weights seem ok so far when running for several hours.

Like everything, there is always more than one way to do something.  I just posted the code if anybody saw the chip and wanted to play with loadcells in a simple inexpensive manner.

trastikata

#5
Quote from: chris_cb_uk on Oct 29, 2021, 04:54 PMLike everything, there is always more than one way to do something.  I just posted the code if anybody saw the chip and wanted to play with loadcells in a simple inexpensive manner.

Indeed, if the hardware serves the purpose, then it should be used. And code examples are always welcome.

Cheers.

Edit: P.s the high zero drift was due to thermal drift, thus if you plan using it at different temperatures than calibration temp, keep this in mind.

chris_cb_uk

Quote from: trastikata on Oct 29, 2021, 05:07 PMP.s the high zero drift was due to thermal drift, thus if you plan using it at different temperatures than calibration temp, keep this in mind.

Will bear that in mind, not unlike any other precision differential amplifier then.  On the project I'm also using a BME280 temp/hydro/pressure I2C for other monitoring tasks so I can always reference to the temperature if the drift is significant enough to justify temperature compensation. Starting to play with an MPU 6050 gyro, which also has temperature reporting... Certainly not got a shortage of temperatures!

Pepe


Pepe

Other demo proteus 8.13 fixed for proton 3.7.5.5