bogde / HX711

An Arduino library to interface the Avia Semiconductor HX711 24-Bit Analog-to-Digital Converter (ADC) for Weight Scales.
MIT License
896 stars 538 forks source link

Correct reading on Setup but not on Loop #187

Open meiralon opened 4 years ago

meiralon commented 4 years ago

Hello

I am running a code on multiple sensors. and at the setup in the Arduino I run :

scale.set_scale(); scale.tare(); //Reset the scale to 0 scale.set_scale(calibration_factor); Serial.print(scale.get_units(), 1);

and at the loop in the arduino I run only : Serial.print(scale.get_units(), 1);

but I get different result ,like there is some kind of bias. the scale is measuring but with offset.

thank you Meir

scorbesero commented 4 years ago

I have had success using the following in my setup:

scale.begin(DOUT, CLK);
scale.set_scale(calibration_factor); //This value was obtained by using the SparkFun_HX711_Calibration sketch
scale.tare(); //add stabilizing time to tare
float measured_weight = 0.0; //measured weight

For the loop, try something like this:

measured_weight = abs(scale.get_units(5)); //takes the average of five readings, adjust to your preference
Serial.print(measured_weight, 1);
meiralon commented 4 years ago

Hello Steven

it seems in my code as if at the loop the value is different. at the setup the value is correct , zero for the start. and then at the loop it turns to a different value.

Thanks

bogde commented 3 years ago

Did you find a solution? Otherwise, can you post the rest of your code and give more details about your setup?

meiralon commented 3 years ago

Hello Bogde Thank you for your message. i didn't solve this issue, but i added a shift in the loop in order to overcome it. see explanation as followed. i will be happy for your expanation regarding this issue.

The code at the Arduino Setup is as followed:

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

Serial.print("Sensor "); Serial.println(i+1); Serial.print(":"); delay(5); Serial.print(scale.get_units(), 1); Serial.print(" kg"); Serial.println();

I read 0 Kg. at the Arduino loop i get different reading, when i run:

Serial.print(scale.get_units(), 1);

in order to correct it i use set_offset :

scale.set_offset(zero_factor);

and this brings it to zero.

Thank you Meir

meiralon commented 3 years ago

Hello bogde

Do you have an idea why it is happening ?

Thank you

Meir

bogde commented 3 years ago

why dont you follow the example and use:

scale.set_scale(calibration_factor);
scale.tare();   

is there any reason why you're using set_scale without a parameter?

meiralon commented 3 years ago

Hell Steven

This is what run, but it seems when it turns into the void loop, the offset information is lost. what do you think ?

Meir

bogde commented 3 years ago

i think you should stick to the example code until you figure it out

theres no reason to call set_offset manually, since i see you're already trying to use tare, which basically sets the offset for you

take a look at src/HX711.cpp to see how tare works

meiralon commented 3 years ago

Hi Steven

Is it possible to change the clock speed (PD_SCK) or the high time of the pulse? I Have seen at data sheet of the HX711 , it can be changed. Thank you Meir