Go Down

Topic: HX711 Load Cell with Weight Already on Scale (Read 949 times) previous topic - next topic

vvarrior

I have four load cells connected in a quarter bridge to HX711 circuit. I would like to measure a weight in grams and I have used this code to get weight:

Code: [Select]


/*
 Example using the SparkFun HX711 breakout board with a scale
 By: Nathan Seidle
 SparkFun Electronics
 Date: November 19th, 2014
 License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
 
 This is the calibration sketch. Use it to determine the calibration_factor that the main example uses. It also
 outputs the zero_factor useful for projects that have a permanent mass on the scale in between power cycles.
 
 Setup your scale and start the sketch WITHOUT a weight on the scale
 Once readings are displayed place the weight on the scale
 Press +/- or a/z to adjust the calibration_factor until the output readings match the known weight
 Use this calibration_factor on the example sketch
 
 This example assumes pounds (lbs). If you prefer kilograms, change the Serial.print(" lbs"); line to kg. The
 calibration factor will be significantly different but it will be linearly related to lbs (1 lbs = 0.453592 kg).
 
 Your calibration factor may be very positive or very negative. It all depends on the setup of your scale system
 and the direction the sensors deflect from zero state

 This example code uses bogde's excellent library: https://github.com/bogde/HX711
 bogde's library is released under a GNU GENERAL PUBLIC LICENSE

 Arduino pin 2 -> HX711 CLK
 3 -> DOUT
 5V -> VCC
 GND -> GND
 
 Most any pin on the Arduino Uno will be compatible with DOUT/CLK.
 
 The HX711 board can be powered from 2.7V to 5V so the Arduino 5V power should be fine.
 
*/

#include "HX711.h"

#define DOUT  3
#define CLK  2

HX711 scale(DOUT, CLK);

float calibration_factor = -21.1; //=1000g
float output;
int readIndex;
float total=0;
float average=0;
float average_last=0;
const int cycles=20;
float readings[cycles];

void setup() {
  Serial.begin(9600);
  Serial.println("HX711 calibration sketch");
  Serial.println("Remove all weight from scale");
  Serial.println("After readings begin, place known weight on scale");
  Serial.println("Press + or a to increase calibration factor");
  Serial.println("Press - or z to decrease calibration factor");

  scale.set_scale(calibration_factor);
  scale.tare(1200); //Reset the scale to 0

  long zero_factor = scale.read_average(); //Get a baseline reading
  Serial.print("Zero factor: "); //This can be used to remove the need to tare the scale. Useful in permanent scale projects.
  Serial.println(zero_factor);
}

void loop() {

  scale.set_scale(calibration_factor); //Adjust to this calibration factor

  Serial.print("Reading: ");
  output=scale.get_units(), 2;
  Serial.print(output);


//Smoothing the results
  // subtract the last reading:
  total = total - readings[readIndex];
  // read from the scale
  readings[readIndex] = scale.get_units(), 2;
  // add the reading to the total:
  total = total + readings[readIndex];
  // advance to the next position in the array:
  readIndex = readIndex + 1;

  // if we're at the end of the array...
  if (readIndex >= cycles) {
    // ...wrap around to the beginning:
    readIndex = 0;
  }
  // calculate the average:
  average = total / cycles;

  average=scale.get_units(), 2;


//Zero drift compensation
  if((average_last>average+0.03 || average_last<average-0.03)){
      //Minimum Load defines Zero-Band
      if (average<0.06){average=0;}
      Serial.print("\tFilter: ");
      Serial.print(average);
      average_last=average;
  }
  else{
    Serial.print("\tFilter: ");
    Serial.print(average_last);
  }
  Serial.print(" g"); //Change this to g and re-adjust the calibration factor if you follow SI units like a sane person
  Serial.print(" calibration_factor: ");
  Serial.print(calibration_factor);
  Serial.println();

  if(Serial.available())
  {
    char temp = Serial.read();
    if(temp == '+' || temp == 'a')
      calibration_factor += 10;
    else if(temp == '-' || temp == 'z')
      calibration_factor -= 10;
  }
}


All works fine when I upload and monitor when there is no weight on the load sensors. Then I add the weight and the proper weight is displayed.

I need the weight to stay on the scale. As you can see I've added the weights to tare and set_scale but the weight returned on monitor is not the entire weight. The tare weight (1200) I added is the weight of the scale without any additional weight after calibration.

Can anyone shed some light?

sebascarra

I have the exact same issue, and no solution so far. These guys seem to be made for home and kitchen scales. We would have to take a look at the low level, un-amplified signals.

robbideloose

Took me a while to find this as well.
If you are using the bodge library, you should use scale.set_offset()

Offset value can be found using calibration code from sparkfun: https://learn.sparkfun.com/tutorials/load-cell-amplifier-hx711-breakout-hookup-guide

Code: [Select]

/*
 Example using the SparkFun HX711 breakout board with a scale
 By: Nathan Seidle
 SparkFun Electronics
 Date: November 19th, 2014
 License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).

 This example demonstrates basic scale output. See the calibration sketch to get the calibration_factor for your
 specific load cell setup.

 This example code uses bogde's excellent library: https://github.com/bogde/HX711
 bogde's library is released under a GNU GENERAL PUBLIC LICENSE

 The HX711 does one thing well: read load cells. The breakout board is compatible with any wheat-stone bridge
 based load cell which should allow a user to measure everything from a few grams to tens of tons.
 Arduino pin 2 -> HX711 CLK
 3 -> DAT
 5V -> VCC
 GND -> GND

 The HX711 board can be powered from 2.7V to 5V so the Arduino 5V power should be fine.

*/

#include "HX711.h"

#define calibration_factor -7050.0 //This value is obtained using the SparkFun_HX711_Calibration sketch

#define DOUT  3
#define CLK  2

HX711 scale(DOUT, CLK);

void setup() {
  Serial.begin(9600);
  Serial.println("HX711 scale demo");

  scale.set_scale(calibration_factor); //This value is obtained by using the SparkFun_HX711_Calibration sketch
  scale.tare(); //Assuming there is no weight on the scale at start up, reset the scale to 0

  Serial.println("Readings:");
}

void loop() {
  Serial.print("Reading: ");
  Serial.print(scale.get_units(), 1); //scale.get_units() returns a float
  Serial.print(" lbs"); //You can change this to kg but you'll need to refactor the calibration_factor
  Serial.println();
}



The zero value is the one you want to use as an argument to scale.set_offset() function. you may have to insert a delay before the first println to make sure you do not miss it

also check out https://github.com/bogde/HX711/issues/32



sebascarra

robbideloose, I think you did not understand our question. The PERCEIVED (I have to highlight that word) effect is that, if you turn on the load cell, no matter what its reading will be zero. Let's say you apply a force to it (a weight or otherwise some force) and hold it, then remove the power from the HX711 (power down your system completely). Turn the HX711 back on and get a reading from the cell. It will read about zero. Release the weight, and the reading should be "-X". So how can you tell X was there without releasing the force?

Now I must mention why that is NOT TRUE. If you mount the cell poorly, or play around with it bending it with your fingers, the cell will not function correctly and, in my case, that's the behavior I perceived. However, I have now mounted it on two steel pads, with tight screws and a proper mount. Upon turning the ADC off and back on, the measurement PERSISTS. The measurement is not relative, it IS absolute, and these cells work wonderfully but only if mounted properly.

I'm open to any other questions, robbideloose I hope you now understand what the original poster and I meant.

Go Up