You should probably do so before asking others for help. I'm confident that it will be illustrative. And, it would show you're willing to take the initiative, do some work, and try to solve your own problems.
I tried the ones there however it kept coming up with the same error which is why I went to other websites where I found virtually the same thing. I'm pretty new to arduino so I'm not familiar with all the errors as it isn't the language I usually code with.
It will be very helpful if you could explain the reason I'm getting this error.
ALL the examples from that library compile error-free for me (selected board = Uno).
The compile error you’re getting is because there is no version of the class HX711 constructor that takes arguments. Yet, you are trying to supply arguments:
HX711 scale(DOUT, CLK);
Why? None of the example programs do that. So, I find it hard to understand how you are getting the same error if you try to compile the examples verbatim.
You can try this setup to check the functioning of your load cell. If you wish, you can use this setup to calibrate your system in terms of calculating gain and offset and then finding the equation for the unknown weight.
The Codes:
/* This program takes 10 samples from LC + HX711B at
1-sec interval and then computes the average.
*/
unsigned long x = 0, y = 0;
unsigned long dataArray[10];
int j = 0;
void setup()
{
Serial.begin(9600);
pinMode(A1, INPUT); //data line //Yellow cable
pinMode(A0, OUTPUT); //SCK line //Orange cable
}
void loop()
{
for (int j = 0; j < 10; j++)
{
digitalWrite(A0, LOW);//SCK is made LL
while (digitalRead(A1) != LOW) //wait until Data Line goes LOW
;
{
for (int i = 0; i < 24; i++) //read 24-bit data from HX711
{
clk(); //generate CLK pulse to get MSB-it at A1-pin
bitWrite(x, 0, digitalRead(A1));
x = x << 1;
}
clk(); //25th pulse
Serial.println(x, HEX);
y = x;
x = 0;
delay(1000);
}
dataArray[j] = y;
}
Serial.println("===averaging process=========");
unsigned long sum = 0;
for (j = 0; j < 10; j++)
{
sum += dataArray[j];
}
Serial.print("Average Count = ");
sum = sum / 10;
Serial.println(sum, HEX);
}
void clk()
{
digitalWrite(A0, HIGH);
digitalWrite(A0, LOW);
}
To fix the can't set com-state for "\.\COM4" error, try restarting your computer. Every so oftern, a COM port will get stuck in some weird state and the restart gets it back to normal so you can use it again.
To regain COM Port, take out USB cable and put back; if not helpful, you can try updating the cable driver this way:
start --> Device Manager --> Ports --> Select Port ---> Update Driver Software... --> follow Menu...
Garima_Mishra123:
Thanks for all your help. One more question how do I access the values from the scale.
Do you want to know the value of an unknown weight in kg (xxx.xxx) and then save it in a variable and show it on the Serial Monitor or LCD Monitor or 7-segment Display unit?
My project as a whole includes this load cell measuring the weight on top of it (which would be tomatoes) and if it goes below a certain weight then I would get a notification saying more need to be bought.
So surely because the weight changes everyday this wouldn't work.
You need to calibrate your load cell first. Calibration refers to teach the load cell that it must measure 500 gm+/2 gm when 500 gm known weight is placed on it. After that you can use the Scale to sale goods in your shop.
Never mind -- how clever we are; we can never break the rules of the Nature. We need to know and understand the rules so that we can use these for out benefits. You have to calibrate the load cell based on two known points -- this is the rule of the Nature!!