[Solved] Using "setScale" Function

I am trying to use a UNO R3 board and a HX711 weight sensor module, along with a beam type load sensor, to measure varying forces from propellers in testing RC airplane motors.

I have a LCD Keyboard shield on the UNO board and the code seems to be working.

When the program runs the weight is reported to the LCD and Serial Monitor. I am seeing a weight of 0.0 g now when I power up or reset. The displayed value refreshes about every 4 seconds, and the value displayed will vary occasionally to -0.0 g.

When I place a 10g scale calibration weight on the beam load sensor the displayed value goes to 2.0g on the next refresh and it will occasionally vary down to 1.9 g

The article here indicates I need to calibrate the scale.:

http://www.dfrobot.com/wiki/index.php/Weight_Sensor_Module_V1

It specifically says “For calibrate the sensor for fixing the feedback floating from different sensor, need to set the Scale using the function named “setScale”. Default status: void setScale(float scale = 1992.f)”

I am new to Arduino and programming, I have the O’Reilly Arduino Cookbook and have searched that and this forum for help with the setScale function but can’t seem to figure out how to use it.

The code I am using now is as follows:

/*
 * description:
 * Code from dleroi post  
 * connections:   
   Hx711.DOUT - pin #A2
   Hx711.SCK  - pin #A3
   HX711 A- - blue wire
   HX711 A+ - white wire
   load sensor load arrow points up
*/

#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

#include <Hx711.h>
Hx711 scale(A2, A3);

void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
}

void loop() {
lcd.setCursor(0, 0);
lcd.print(scale.getGram(), 1);
Serial.print(scale.getGram(), 1);
lcd.print(" g");
lcd.print(" ");
Serial.println(" g");
delay(200);
}

Any help with be appreciated, and any suggestions or help as to where I could have found the answer will be helpful too.

Jack

test setup.jpg

What do you need to know? You know what kind of argument the function takes (float), and how to call it.

I need to know what I need to do with that setScale function?

Do I type it into the sketch file? If so, I tried that and it generated errors on verifying. I pretty much would like to see exactly what it should read like and where it would go along with with the punctuation or formatting symbols that needed to precede or follow it.

Jack

Do I type it into the sketch file?

Typing it in a letter to your boyfriend (or girlfriend) is pointless. Yes, it goes in the sketch.

If so, I tried that and it generated errors on verifying.

Ah, well, my crystal ball sees why. Unfortunately, we aren't exactly on speaking terms right now. Seems I pissed it off somehow. Can't imagine what I did to upset it.

I pretty much would like to see exactly what it should read like and where it would go along with with the punctuation or formatting symbols that needed to precede or follow it.

scale.setScale(calValue);

Where calValue is a float, and contains some reasonable value for calibration of YOUR scale.

PaulS:

Do I type it into the sketch file?

Typing it in a letter to your boyfriend (or girlfriend) is pointless. Yes, it goes in the sketch.

Actually it is not in the sketch, it is in the *.h file in the library. I found that info finally here:

http://www.dfrobot.com.cn/images/upload/File/20131205193420m0ym4y.pdf

It is on page 4 and it says:

".Zero adjustment- Open the Hx711 library folder , and find the file Hx711.h, open it. Locate the statement void setScale(float scale = 1992.f); You only need to adjust the number 1992 to find the appropriate value for weight scale. Save the h file, and upload the above code again..."

If so, I tried that and it generated errors on verifying.

Ah, well, my crystal ball sees why. Unfortunately, we aren't exactly on speaking terms right now. Seems I pissed it off somehow. Can't imagine what I did to upset it.[/quote]

It is probably withholding that so as to maintain it's superior knowledge position in your life. If it told you too much you wouldn't need it any more... :)

I pretty much would like to see exactly what it should read like and where it would go along with with the punctuation or formatting symbols that needed to precede or follow it.

scale.setScale(calValue);

Where calValue is a float, and contains some reasonable value for calibration of YOUR scale.

I managed to find the *.h file and played with the value in the void setScale(float scale = 1992.f); statement and it worked as described to changed the readings. So my question is answered.

Thanks for the help.

Jack

Hi Jack, it is not necessary to change the value in the lib file. You can simply call this function in your Arduino sketch:. You have to do it in the setup section:

#include <Hx711.h>
Hx711 scale(A2, A3);

void setup() {
  scale.setScale(2450);
}