bogde / HX711

An Arduino library to interface the Avia Semiconductor HX711 24-Bit Analog-to-Digital Converter (ADC) for Weight Scales.
MIT License
890 stars 538 forks source link

Seting Up multiple amplifiers for multiple load cells #35

Open rtlop opened 8 years ago

rtlop commented 8 years ago

So the library works great for one amplifier and load cell. But what would I need to change if I wanted to set up to 2 load cell and amplifiers?

electrokean commented 8 years ago

Two ways I can suggest: 1) use channel B to connect the second load cell and select it using scale.set_gain(32) 2) instantiate a second HX711 object using a different pair of I/O pins, and use a second HX711 interface PCB, both using channel A for the load cell input - e.g. HX711 scale1(A1,A0), scale2(A3,A2);

Note that option 1 has some limitations (limited gain and limited library support), and relies on your HX711 interface PCB breaking out the channel B input pins. You would use the same excitation output for both load cells.

bneedhamia commented 8 years ago

I'm building a scale using 4 load sensors (each is half of a load cell) and Sparkfun's HX711 board (which has only one set of inputs). I recently decided to use a separate amplifier and HX711 object for each load sensor so that I can separately calibrate each load sensor. (Of course I'm adding two resistors to each load sensor to turn each sensor into a Wheatstone Bridge.) It's good to hear someone recommend using multiple HX711 objects in one Sketch.

electrokean commented 8 years ago

@bneedhamia you mention adding two resistors to create a wheatstone bridge from those half-load cells. What tolerance resistors are you using? Your blog post mentions 0.7lb variance for approx 15lb weight in different locations. That is just under a 5% variance. I hope you're not using 5% resistors :) Even if you use a pair of 1% resistors, you could see +/-2% variance or approx 4% variance between any two of the bridges (not even allowing for the load cell matching).

ghost commented 8 years ago

Hello, I use for test three HX11 with load cells.

And this code:

HX711 scale0(A1, A0); HX711 scale1(A2, A0); HX711 scale2(A3, A0);

define SENSORCNT 3

HX711 *scale[SENSORCNT]; ... void setup() { scale[0] = &scale0; scale[1] = &scale1; scale[2] = &scale2; ... }

void loop() { for (uint8_t i = 0; i < SENSORCNT; i++) { long read = scale[i]->read(); value[i] = (read - scale[i]->get_offset()) / scale[i]->get_scale(); Serial.print(" "); Serial.print(read); Serial.print(" "); Serial.print(value[i], 1); } ... }


Output:

Value: 238452 0.9 198543 0.0 217988 0.0 Value: 238448 0.1 198569 0.0 217965 0.0 ...

But sometimes (ie. 15 sec.) I got an error on one Channel: Value: -8388607 -1891.9 198575 0.0 217965 0.0 <- error !

This happens in different times on all channels and only if I run throught all sensors - not with a single on.

Pit

matouchat790te commented 7 years ago

I have the same issue as pit001, with one XH711 it's ok. With 3 , sometime values not valid. An idea ?

electrokean commented 7 years ago

@matouchat790te Are you sharing a pin for the HX711 clock like A0 in the above example? I believe this could be the cause. Can you try wiring two separate pins for each HX711. You don't want to be clocking all 3 HX711 chips every time you read one, as it could lead to this kind of issue.

matouchat790te commented 7 years ago

I'm not sharing pins. each HX711 has is own . If I do a squale_power_up / down at each loop, the problem disappear. But it's too slow.
One other way is to use three arduino board and 'OR' the ouputs, but it's not elegant . the project is for a touch probe for a cnc milling machine.

matouchat790te commented 7 years ago

I'll put an oscilloscope on the pins, and a logic analyzer to see if the problem is outside or not. may be I have crosstalk between channels which makes pulses on the wrong clock input. Disable interrupts has no effect. I'm glad to see I'm not alone with this issue.

matouchat790te commented 7 years ago

Hello all. I did some measurements And I noticed an important point: the HX711 periodically performs conversion without external application need. It works in free running.

With only one HX711 : If we wait for the conversion end signal, all goes well. ( Falling edge of DOUT ) This works for one XH711.
But as soon we use more, calling the ‘is_ready’ function becomes asynchronous. It is not clear in the datasheet, but the HX711 is free running at 80Hz. And if you activate CLOCK signal a few microseconds before the next end of conversion, you may just send the clock at the wrong time in the 10 microseconds time . Named # T1 1: falling edge to DOUT PD_SCK rising edge. (See datasheet). and data will be wrong. In all the tests I made the datas were false if the Arduino make a request exactly 12.75ms after the last end of conversion signal. ( falling edge of DOUT ) This bug could also appear with one HX711 if you make asynchronous read of the chip.

I have an imperfect workaround: make a loop for the FALLING edge of DOUT rather than checking its level and immediately start the clock for reading data. But you may be waiting 12 ms more than necessary.

Anyone have a better solution ?

electrokean commented 7 years ago

@matouchat790te Yes, I experienced this behaviour too. My original debug code was doing too much processing or serial output between readings. Even after some work I would occasionally still get an incorrect reading which I would have to filter out. In the end I gave up on the HX711 due to its limitations and poor documentation.

bneedhamia commented 7 years ago

I've had nothing but good luck using the HX711 board from Sparkfun and the https://github.com/bogde/HX711 library, connected to an Arduino

  1. I used them in both a dog bed weight scale and a dog water bowl scale. My app code is at https://github.com/bneedhamia/CurieBLEBowlScale and https://github.com/bneedhamia/CurieBLEWeightMonitor if you'd like to take a look. The Bowl project uses one load cell connected to the HX711; the bed uses 4 load sensors (each 1/2 a wheatstone bridge) plus matched resistors, and 4 HX711s.

Granted, all those projects do is read the weight and send it via BLE to a Raspberry Pi gateway - they don't do a lot of computation between HX711 readings.

On 9/12/2016 5:45 AM, Kean Maizels wrote:

@matouchat790te https://github.com/matouchat790te Yes, I experienced this behaviour too. My original debug code was doing too much processing or serial output between readings. Even after some work I would occasionally still get an incorrect reading which I would have to filter out. In the end I gave up on the HX711 due to its limitations and poor documentation.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/bogde/HX711/issues/35#issuecomment-246335763, or mute the thread https://github.com/notifications/unsubscribe-auth/AJqtSoNz2MK5RSmvqFQ95zhrsU_O5p-jks5qpUligaJpZM4ICbpk.

matouchat790te commented 7 years ago

One way could be using interrupts , one on each HX711. so moving on Mega . I found a similar AD with same serial link here : http://www.analog.com/media/en/technical-documentation/data-sheets/AD7780.pdf they spoke about 'ensure reading before new conversion signal '

compugician commented 7 years ago

Hi all,

I wrote a library that resolves most of the issues discussed here with multiple cells, while also sampling all of them at 80hz simultaneously.

check it out: https://github.com/compugician/hx711-multi

It is stripped at the moment of all the other functionality (tare, offset, units, etc.) but those are easy to implement on your own in or out of the library if you'd like.

I'll add them soon, hopefully, or if someone wants to contribute please do.

matouchat790te commented 7 years ago

Hello all, I replaced in the beginning of function read() long HX711::read() { // wait for the chip to become ready while (!is_ready());


by this long HX711::read() { // wait for the chip to become ready if (!is_ready()){ while (!is_ready()) { // we are at 1 ,0 we wait for falling edge // Will do nothing on Arduino but prevent resets of ESP8266 (Watchdog Issue) yield(); } } else { while (is_ready()) { // attend 1 yield(); } while (!is_ready()) { // wait for falling edge yield(); } }


waiting the FALLING edge of data ready ( DOUT ) ensuring the data is available for the next 10 ms

compugician commented 7 years ago

@matouchat790te

I'm looking to understand this problem better so I can fix it also in my copy of this repository.

If I understand your code correctly, doesn't that effectively reduce the sampling rate by at least half?

Maybe I'm misunderstanding the original issue, but if the issue that some samples are bad because we're sampling too 'late' after a ready signal, maybe the solution should be to check the timing from the last known good sample, and as long as it is within a threshold of a full cycle we go ahead and sample, and otherwise wait?

Of course that is not guaranteed to work forever because of the two-clocks problem, but that could be mitigated either by once in a while re-setting the chip, or otherwise re-synchronizing our timing (to a falling edge, for example, by using your trick)?

Thoughts?

SreevatsaAcharya commented 7 years ago

Hello, I am trying to send the value obtained from the load cell to a server using a gprs sim900 module, and i am doing so as follows

char val[20];
char url[160];
float temp;
temp= scale.get_units(); // or scale.get_units(10); AVERAGE OF 10

  dtostrf(temp, 7, 2, val);
  snprintf(url, 74, "AT+HTTPPARA=\"URL\",\"http://www.website.com/test.php?temp=%s\"", val );
  mySerial.println(url);

and sending the variable "temp" in the http url request. i get the value on the serial monitor when i print the variable on the serial monitor but it does not get updated on the server. I just get a blank reading.

Am i missing something? Any solutions?

compugician commented 7 years ago

I'm not sure how this is a question to the HX711 issues forum.

1) The most obvious thing not shown in your code is how you are sending this to the http server. 2) Do you know your server works? If you manually send a value in a URL of an http request does it work? 3) If yes to #2, use the GPRS_TCPConnection example (or equivalent that came with the library for your shield), and manually change the URL there to yours. Notice that if you are using the seeed-studio library then you split the connection into gprs.connect to the server and gprs.send with a get command such as "GET /test.php?temp=123.45" (or put, or whatever your PHP script is expecting). 4) If yes to #3, and indeed you see the value in 'val' when printed out, then check how your code for sending the http request differs from #3.

SreevatsaAcharya commented 7 years ago

@compugician

` float temp; char val[20]; char url[160];

void SendData() { mySerial.println("AT+HTTPINIT"); //init the HTTP request delay(2000); ShowSerialData();

// Serial.print("Reading: ");

// temp=random(1000.12,9999.99); temp= scale.get_units(); Serial.print(scale.get_units(), 1); //scale.get_units() returns a float Serial.print(" Kg"); //You can change this to kg but you'll need to refactor the calibration_factor Serial.println(temp);

delay(3000);

dtostrf(temp, 7, 2, val); snprintf(url, 74, "AT+HTTPPARA=\"URL\",\"http://www.website.com/test.php?temp=%s\"", val ); mySerial.println(url);

delay(3000); ShowSerialData();

mySerial.println("AT+HTTPACTION=0");//submit the request delay(10000); ShowSerialData();

mySerial.println("AT+CIPCLOSE");//close the connection delay(5000); ShowSerialData(); }`

This is the code i am following and i am able to send static data to the server i.e if i define temp=2134 etc in the url. It also works if the variable temp receives the value from a random number generating function as shown. But when i transfer value from the scale.get.units() function it returns blank. I am using a Sim900 rs232 gprs module and found this method to be most suitable to send data. Initial settings are all correct and verified.

I tried the GET method but faced a lot of issues so shifted to this method.

compugician commented 7 years ago

So if you set temp manually it works, but if you use scale.get_units() it does not?

What is printed by 'Serial.println(temp)' in each case?

Also, what random() funtion are you using? AFAIK the standard one does not generate floating point numbers.

Does rounding temp solve result in the data getting to the server appropriately?

SreevatsaAcharya commented 7 years ago

Finally!!! Made it work. The scale.get.units() function reads value from the load cell very quickly so i guess the value wasn't actually getting stored in the variable i defined. Made a few changes , and now it works. Thanks for your help @compugician

lucian0112 commented 6 years ago

@compugician - First of all great job with the library. Is there any chance to include in it the tare function and calibration? I tested your library with 12 hx711 sharing same clock and seems work fine, but I was not able to implement these functions which are actually very important for me....

Thanks

jpk73 commented 6 years ago

check out these examples: https://github.com/sparkfun/HX711-Load-Cell-Amplifier/tree/master/firmware

tk5ep commented 6 years ago

Hi, @lucian0112 Do i understand it correctly that you're using a DOUT pin common to all your 12 HX711 ?

I would like to use 4 HX711 using the minimum number of pins of my pro mini. I don't need any speed, so i will use 40Hz not 80Hz.

Would the original library work without here described problems ?

Thanks,

lucian0112 commented 6 years ago

Hi, Yes you are correct. I used that lib and 12 hx711 with clock pin shared. The problem for me was that I was not able to implement functions in it like (tare, calibration etc...). The lib just read raw values of the chips. Not sure if is relevant but my hx's were modified for 80Hz. Meanwhile I moved on arduino mega and have enough pins to use them on classic wired

Cheers

zstergios commented 6 years ago

Hi there! I have work in past with1 load cell and + HX711 (bodge library)

I want to build a large scale, so I will need 6 load cells. (2 front,2 middle,2 back) I planning to use 3xHX711 chips (1 per 2 cells/row)

My purpose is to get the total weight. I have checked the multi-HX711 library, but what's the logic of combining 3 values? I guess it's SUM of readings divided by 3 (total of amplifiers)? How accurate is this way?

THANK YOU

tk5ep commented 6 years ago

Hi,

How do you connect 2 cells to one HX711 ?

Never thought about your problem, but i don't see any other way to solve it than summing the 3 readings. About accuracy, if you have a common scale, you will never know how much weight is on which cell. You can only suppose it is an equal part of the total weight... so ....

Keep us informed, i might have the same need soon !

zstergios commented 6 years ago

You can connect 4 load cells to one chip. Search for half bridge and full bridge hx711.

The issue is when you have 6 or 3. Need to summarize them probably

lucian0112 commented 6 years ago

Have you connected 4 load cells to one chip? Please tell us how you did it.

zstergios commented 6 years ago

It's simple, just search on google. http://prntscr.com/h6u02q (Source https://www.youtube.com/watch?v=0Lwdzpr_TxM)

Edit: Link fixed

lucian0112 commented 6 years ago

In your link there are 3wire load cells, I was talking about 4 wire load cells like this https://cdn.instructables.com/F6R/MFZR/IU9UQLN9/F6RMFZRIU9UQLN9.MEDIUM.jpg

Also the idea is to read each load cell individually .

zstergios commented 6 years ago

If you read them individually it's hard to have good accuracy & calibration!

I think (NOT SURE), you may have to ignore on cable.

I have only one load here with 4 wires, I will order some more to test it.

@lucian0112 Very intersted http://www.marco-iw.nl/file/1355354080.2319WAfreS/2%20Loadcell%20cabling.pdf

With 4-wire extension cables the load cell output should be connected to pairs of diagonally opposite wires.

Please take some time read it :)

Stuckcesium commented 6 years ago

I'm also interested to plug many HX711 (up to 8) to an arduino pro mini (only 4 analog pin). What do you think with a solution using a multiplexer like a 4051 and the library developed by @compugician ?

lucian0112 commented 6 years ago

You cannot use a multiplexer. If you read hx711 datasheet and read the library you will understand why. Also why are you thinking only on analog pins? It works very well on digital pins also....so for 8 hx you need 16 pins not matter analog or digital...

Stuckcesium commented 6 years ago

Thanks Lucian for you reply, I didn't know the HX711 was working with digital pin... So good news for me. I've have to learn a lot again on arduino and electronic in general...

lucian0112 commented 6 years ago

you are welcome good luck :)

zstergios commented 6 years ago

@lucian0112 have you figured out how to connect 4-wire load cells together?

lucian0112 commented 6 years ago

I did a test and just connected them in parallel and used only one hx but this is not what I want. I need read them individually . Or this was not your question?

zstergios commented 6 years ago

I thought we need the same. 4 load cells (4wire each) connected together and getting 1 reading/weight instead of connecting each of them individually and getting 4 readings/weights.

If you connect them individually: 1) how you will calibrate all loads? 2) how you will get a final weight?

lucian0112 commented 6 years ago

I calibrate individually them and final weight is sum of all cells if you want this. In my case I need to measure 12 individual applied forces so that s why I need them read individually ...

zstergios commented 6 years ago

Nice.....I will try it. Do you think will it have accuracy?

lucian0112 commented 6 years ago

accuracy depends of how good you do the calibration. anyway here can be a long discussion. what are you trying to achieve exactly?

zstergios commented 6 years ago

Large Scale with 6 or 9 load cells. Size 1.3mx 1m

lucian0112 commented 6 years ago

For this size 1.3 x 1m I would use only 4 load cell, one each corner. Choose load cell that support the weight you need to measure. If you want to measure big weight you should proper make the frame but I don t see any reason for use 6 or 9 cells....
do you have a draw of the scale?

zstergios commented 6 years ago

Red are the basic 4, the green are the optional.

1) http://prntscr.com/hahcur Design with 4+2 2) http://prntscr.com/hahdp4 Design with 4+5

I want to measure palette, so because the weight is around 2T, and my fear not to break on middle that's why I have design (2) pict.

The gaps inside the left-right edges are required the clark to able to lift and load the scale https://a.scdn.gr/images/sku_images/014957/14957290/20160520150235_1ad5a025.jpeg

My problem right know is not the amount of load cells, 4 or more, but HOW i can connect them. to able to get the TOTAL weight

I have spent many days but no luck. Most suggest to add HX711 as many cells I will use (individually)

I asked a manufacturer on Alibaba and told be 2 usefull things 1) The total weight is divided by the amount of cells, for 2T I need 500KGx4 Cells, but suggested me to use 1T because the weight will never be balanced on the center. I think it's obnvius 2) Told be that I need Load Cell Junction Box https://www.aliexpress.com/wholesale?catId=0&initiative_id=SB_20171114115757&SearchText=Load+Cell+Junction+Box . Something similar with HX711 but multi-cell supported. The problem is that are expensive and probably I will not able to use the arduino. I tried to searched for shematics if I able to understand how the connections made but I'm not experienced so much.

lucian0112 commented 6 years ago

Do you have skype?

zstergios commented 6 years ago

SkypeID: zstergios Email: zstergios [at] gmail.com Thanks for your interest!

Naesstrom commented 6 years ago

I'm looking to use loadcells in my curing chamber to measure weightloss of my charcuteri (sending it to grafana for example) and would love to see some examples of your setup and how you coded it @lucian0112 to use that many loadcells!

technicalpriyanshu commented 6 years ago

@compugician this works fairly good with 3 load cell, but not with 4. can you suggest changes in case of 4 load cell wiring up together.

compugician commented 6 years ago

On which platform?

There are platform-dependant optimization that need to be made, and I could help as I've gotten it running with more than 4 on several platforms - but didn't have the time to put them neatly into the codebase, so it would be nice if you can, once it works :-)

On Mon, Mar 19, 2018 at 1:42 AM, technicalpriyanshu < notifications@github.com> wrote:

@compugician https://github.com/compugician this works fairly good with 3 load cell, but not with 4. can you suggest changes in case of 4 load cell wiring up together.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/bogde/HX711/issues/35#issuecomment-374107003, or mute the thread https://github.com/notifications/unsubscribe-auth/AEYFiCPMsEE6iCqUGTjQbKRFl7AzIwXiks5tf0VMgaJpZM4ICbpk .

rs810 commented 6 years ago

@compugician How many can you run with an Arduino Uno?