Hi guys! First post around here, however a “long” follower of the forum since my journey with arduino’s started
So, by now I’m using a 20kg load cell and hx711 amplifier.
I’m using the hx711 library and calibration runned perfectly and I can read values up to 3 decimals with the following code:
#include <HX711.h>
#define DOUT 3 #define CLK 2
HX711 scale(DOUT, CLK);
float calibration_factor = -96650;
void setup() {
Serial.begin(9600);
Serial.println(“Press T to tare”);
scale.set_scale(-96650); //Calibration Factor
scale.tare(); //Reset the scale to 0
}
int w = scale.get_units();
But when I run the command like that I just get a value with 2 decimal instead of 3.
That line gave you a number in w with decimals? That a really neat trick. Can you show us how you did that and include the code and the output? Maybe instead of making stuff up that you think you did, let’s get really precise with this. That’s how code works. Let’s talk about what REALLY happened, not some approximation of what you think you did.
Next, you need to learn the difference between a number, which is an abstract concept and doesn’t have any fixed number of decimal places, and the representation of a number, which is concrete and what you write down and does have some fixed number of decimals. Next you need to look at how a float is stored, it doesn’t have ANY decimals. It is stored as a whole number part and a fraction part. The decimals are put there when you print it out because humans are really crappy at understanding fractions in binary. It doesn’t have some number of decimal places stored with it. The number of decimal places thing only matters when you print it.