The harder I look for answers, the dumper I feel so I thought I’d ask experts. I’ve been playing with load cell projects and want to change units. Problem is I don’t understand statements like “scale.get_units(), 3”. I know what is does, I just don’t know how. Is “scale.get_units” a variable or is “scale” some command for the HX711? If the line is a variable where/how is it declared? I can’t seem to find explanations for terms associated with the HX711 that might answer my questions. I’d be grateful for any help.
It is object-oriented. Somewhere in the beginning of your sketch, you declared an object (variable) called 'scale' and this object has functions associated with it - one of them being get_units(). If you look at the header file you included, you will see the definition of this object as well as all the functions it can access. If you look in your libraries folder for this header file, you will also see a .cpp file which is the actual code that implements those functions.
scale is an object (variable); it's probably declared near the top of your code like below
HX711 scale(A1, A0); // parameter "gain" is ommited; the default value 128 is used by the library
Usually each object has variables and functions (methods). Some of those you can access, some you can't. get_units() is a method that exists for a HX711 object (and that you can access) and will return whatever it is supposed to return (the weight?).
You took that out of context and hence does not mean anything. Part of a print statement, I guess.
The harder I look for answers, the dumper I feel so I thought I'd ask experts. I've been playing with load cell projects and want to change units. Problem is I don't understand statements like "scale.get_units(), 3". I know what is does, I just don't know how. Is "scale.get_units" a variable or is "scale" some command for the HX711? If the line is a variable where/how is it declared? I can't seem to find explanations for terms associated with the HX711 that might answer my questions. I'd be grateful for any help.
So you are looking at this example:
And you are wondering about the line:
The 'scale' part is the HX711 object declared in this part near the top:
#include "HX711.h" //You must have this library in your arduino library folder #define DOUT 3 #define CLK 2 HX711 scale(DOUT, CLK);
The ".get_units()" part is a method call. A method is a function that is part of an object. It's like telling the specific object to do something. If you declared more than one HX711 object they would have other names. This is where you ask the object named 'scale' to return the value in calibrated units.
The goal of the sketch is to calculate the calibration value. You put a known weight on the scale and then adjust the calibration value until the scale reads the right value. If you want to measure in pounds, put a known weight in pounds on the scale and adjust the calibration value until the .get_units() returns the correct number of pounds. Then you can use that calibration value with that sensor to measure pounds.
The "Serial.print(" and ", 3);" parts of the line are to display the floating-point value returned by "scale.get_units()" on Serial Monitor with three decimal places.