Pages: 1 [2]   Go Down
Author Topic: HX711 24 bit ADC with four load cells  (Read 3031 times)
0 Members and 1 Guest are viewing this topic.
The Netherlands
Offline Offline
Sr. Member
****
Karma: 4
Posts: 330
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Use the HX711  lib on Github made by Bogde.
Only use one loadcell and get it working.
Then add second load cell.

simple code with calibration inside the sketch not the .h file from the lib.

Code:
// Arduino with load cell
#include <HX711.h>

// HX711.DOUT - pin #A1
// HX711.PD_SCK - pin #A0

HX711 scale(A1, A0); // 24 bit load cell amplifier

long ForceValue = 0;

// Put two known loads on the sensor and take readings. Put those values
// here.
float aReading = 192.0; // put the value of the lowest rate here. 192 is a sample value
float aLoad = 500; // your lowest load value for example 500 grams or use no laod and take that value as lowest.
float bReading = 344.0; put the value of the highest rate here. 344 is a sample value.
float bLoad = 1000; // your highest load value for example 1000 grams

long time = 0;
int interval = 500; // Take a reading every 500 ms

void setup() {
  Serial.begin(9600);
}

void loop() {
  
  ForceValue = scale.read(); //
  float newReading = ForceValue;
  
  // Calculate load based on A and B readings above
  float load = ((bLoad - aLoad)/(bReading - aReading)) * (newReading - aReading) + aLoad;
  
  // millis returns the number of milliseconds since the board started the current program
  if(millis() > time + interval) {
    Serial.print("Reading: ");
    Serial.print(newReading,1); // 1 decimal place
    Serial.print("  Load: ");
    Serial.println(load,1);  // 1 decimal place, println adds a carriage return
    time = millis();
  }
}

« Last Edit: June 25, 2014, 12:52:48 pm by backbone » Logged

Never to old to learn and I learn every day

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Use the HX711 lib on Github.
Only use one loadcell and get it working.
Then add second load cell.

simple code with calibration inside the sketch not the lib.

Code:
// Arduino with load cell
#include <HX711.h>

// HX711.DOUT - pin #A1
// HX711.PD_SCK - pin #A0

HX711 scale(A1, A0); // 24 bit load cell amplifier

long ForceValue = 0;

// Put two known loads on the sensor and take readings. Put those values
// here.
float aReading = 192.0; // put the value of the lowest rate here. 192 is a sample value
float aLoad = 500; // your lowest load value for example 500 grams or use no laod and take that value as lowest.
float bReading = 344.0; put the value of the highest rate here. 344 is a sample value.
float bLoad = 1000; // your highest load value for example 1000 grams

long time = 0;
int interval = 500; // Take a reading every 500 ms

void setup() {
  Serial.begin(9600);
}

void loop() {
 
  ForceValue = scale.read(); //
  float newReading = ForceValue;
 
  // Calculate load based on A and B readings above
  float load = ((bLoad - aLoad)/(bReading - aReading)) * (newReading - aReading) + aLoad;
 
  // millis returns the number of milliseconds since the board started the current program
  if(millis() > time + interval) {
    Serial.print("Reading: ");
    Serial.print(newReading,1); // 1 decimal place
    Serial.print("  Load: ");
    Serial.println(load,1);  // 1 decimal place, println adds a carriage return
    time = millis();
  }
}



thanks! I will try this smiley
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This may not be the correct place to ask, but is it necessary to connect the hx11 to analog pins?  It seems like they are digital, so could I connect them to digital pins instead?  I also have a project I am working on where I will need to read 4 load cells, and I was going to just use 4 hx711 chips.
Logged

Narvik, Norway
Offline Offline
God Member
*****
Karma: 23
Posts: 979
electronics engineer, teacher.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

..you arswered that yourself..  All arduinos pins can be used
Logged

Ny

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

..you arswered that yourself..  All arduinos pins can be used

Thank you, I was just confused because every code example I could find had them on analog pins.  I should have one soon, and I'll try it on various pins.
Logged

Narvik, Norway
Offline Offline
God Member
*****
Karma: 23
Posts: 979
electronics engineer, teacher.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 Looks like the Hx... is dual channel.  (handles two loadcells)
Logged

Ny

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yes it says it is dual channel, but how can we interface 2 loadcells? Has anyone tried it?
Logged

The Netherlands
Offline Offline
Sr. Member
****
Karma: 4
Posts: 330
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Do not know if this works but according to the .h file the call for gain also set the channel.
Do not have the time to check.
Let me know or change the code so it works.

5-7-2014
I tested myself but it is not working!!!!!!!!!!!!!!!!

Code:
#include <HX711.h> // Github Bogde files!

// HX711.DOUT - pin #A1
// HX711.PD_SCK - pin #A0

HX711 scale(A1, A0); // 24 bit load cell amplifier

long ForceValueChannel_A = 0;
long ForceValueChannel_B = 0;
long emptyRead = 0;

/*
According to the .h file the call to get the A or B channel value is just set the gain after a scale.read call.
*/

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  set_gain(128); // takes effect after a scale.read
  emptyRead = scale.read();
  ForceValueChannel_A = (scale.read()/100);
  set_gain(32); // takes effect after a scale.read
  emptyRead = scale.read();
  ForceValueChannel_B = (scale.read()/100);
  
  Serial.println(ForceValueChannel_A);
  Serial.println(ForceValueChannel_B);
}  
« Last Edit: July 05, 2014, 03:45:52 pm by backbone » Logged

Never to old to learn and I learn every day

Narvik, Norway
Offline Offline
God Member
*****
Karma: 23
Posts: 979
electronics engineer, teacher.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I dismaneteled a bathroom scale (0..130 kg) .. Loadcelle were paralelled diagonally.  Tried this to make a scale with arduino,, Positive within a pound prcition.
Logged

Ny

The Netherlands
Offline Offline
Sr. Member
****
Karma: 4
Posts: 330
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Lib designer says in an earlier question from a user.

read the datasheet to see what i mean about the clock pin. you need to pulse it 24 times to get one reading (24 bits).

 
 // set the gain factor; takes effect only after a call to read()
 // channel A can be set for a 128 or 64 gain; channel B has a fixed 32 gain
 // depending on the parameter, the channel is also set to either A or B
 void set_gain(byte gain = 128);
  so use
  set_gain(32);
  to select the second channel, then read it. you can't read both channels at the same time. read the datasheet. then, use:
  set_gain(128); // or just set_gain();
  to select the first channel, and read it.
---------------------

set_gain(32) is throwing up and error set_gain was not declared.
So how difficult is it to read two channels????  :-)
Logged

Never to old to learn and I learn every day

The Netherlands
Offline Offline
Sr. Member
****
Karma: 4
Posts: 330
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

HX711 rework for higher sample rate.

For those who have the cheap green HX711 board and need the 80 Sps instead of the standard 10 Sps.
Take a sharp needle pin and put it under the PIN 15. Take a soldering iron with a fine thin tip and warm up the PIN 15.
As soon as the solder is melting little pressure on the needle pin can lift the PIN 15 from the board.
Then solder a thin wire from the PIN 15 to a VCC connection on the board.

This will give you 8 times more readings per second.

Enjoy


* hx711 lift pin 15.JPG (82.02 KB, 761x597 - viewed 17 times.)
Logged

Never to old to learn and I learn every day

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

To use the channel B load cell, just change this line
HX711 scale (A1, A0); to --> HX711 scale (A1, A0, 32);

// put gain 64 or 128 to channel A, 32 for channel B
//You can not use both channels at the same time
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi! What do you mean by "cannot use two channel at the same time"?

I plan on getting two readings from the two load cells in each loop.. smiley

Logged

The Netherlands
Offline Offline
Sr. Member
****
Karma: 4
Posts: 330
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

To use the channel B load cell, just change this line
HX711 scale (A1, A0); to --> HX711 scale (A1, A0, 32);

// put gain 64 or 128 to channel A, 32 for channel B
//You can not use both channels at the same time

So all the HX711 libs around do not support reading two loadcells in one loop?
So why technical speaking has this HX711 two channels if you cant read them in one loop and you have to change the call to the lib. which you cant do in a void loop.
Or should there come a LOOP code without the use of a lib?

Questions questions :-)

Paco
Logged

Never to old to learn and I learn every day

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi! What do you mean by "cannot use two channel at the same time"?

I plan on getting two readings from the two load cells in each loop.. smiley



I think the solution here is connect each scale on ( Tx, Rx ), separate  from the other one
Logged

Pages: 1 [2]   Go Up
Jump to: