I am trying to calibrate HX711 but something wrong...

Hi,

I am trying this code:

#include "HX711.h"

HX711 scale(A1, A0);

float calibration_factor = -7050; //-7050 worked for my 440lb max scale setup

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();
  scale.tare();  //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: ");
  Serial.print(scale.get_units(), 1);
  Serial.print(" kg"); //Change this to kg 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;
  }
}

On serial monitor prints all text etc, but when I want to try increase or decrease value it does not work. Nothing happen. Maybe Compound Operators does not work properly? :stuck_out_tongue:

Thanks!!!

Site where I took the code: Load Cell Amplifier HX711 Breakout Hookup Guide - learn.sparkfun.com

That's their example code, though, isn't it? I suspect they tested it... Then again, it is sparkfun - I wouldn't put it past them to post non-working example code...

What does it do wrong? Is it not getting the results or what?

I can assure you that the boolean operators work just as they are supposed to.

Can you expand on what doesn't work? Does the whole program freeze? Or does it just not increment or decrement that variable? Are you sure you are sending what you think you are? Maybe printing temp would provide a clue.

I write "a" in serial input and press send button, but nothing happen. Basically code working except increase and decrease. Thanks.

Einars:
I write "a" in serial input and press send button, but nothing happen. Basically code working except increase and decrease. Thanks.

Have you tried printing temp to make sure it is receiving what you think?

'A' and 'a' are not the same. Also, try '+' and '-' as the code suggests.

The same. Does not work. :frowning:

Hi,
Have you got your monitor speed at 9600 baud?

Tom... :slight_smile:

Delta_G:
Have you tried printing temp to make sure it is receiving what you think?