[Solved] Error: 'Hx711' does not name a type

I am trying to measure thrust forces using a beam type sensor, a HX711 module, and a Freaduino UNO board. It is like the project here:

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

I was unable to find that particular weight sensor module and am using this one:

http://www.nyplatform.com/index.php?route=product/product&path=114_143&product_id=746

I downloaded and installed the library from the link there, it is installed in folder /libraries/Hx711 that contains files Hx711.cpp, Hx711.h, and a samples folder with folders named LiquidCrystalScale and Serial Scale containing files LiquidCrystalScale.ino and SerialScale.ino files.

I copied the sample code from that page and pasted it into a new sketch in the IDE. When I try to upload the sketch I get the error ‘Hx711’ does not name a type and the statement “Hx711 scale(A2, A3);” is highlighted in yellow.

Can anyone explain this problem to me?

The code is below.

Jack

/*
 * description:
 * The sample code for digital weight scale of hx711. The weight will be printed in the serial.
 * library host on https://github.com/aguegu/ardulibs/tree/3cdb78f3727d9682f7fd22156604fc1e4edd75d1/hx711
 * connection:   
   Hx711.DOUT - pin #A2
   Hx711.SCK  - pin #A3
*/
 
#include <Hx711.h>
Hx711 scale(A2, A3);
 
void setup() {
  Serial.begin(9600);
}
 
void loop() {
  Serial.print(scale.getGram(), 1);
  Serial.println(" g");
  delay(200);
}

Check that the name of the class inside the included file is actually Hx711, which is the class you are trying to create an instance of. It might be HX711 or something. Case matters.

Otherwise, it is not finding the h file, for some reason. Check you put it in the correct place. Check that you restarted the arduino IDE after you put the h file there.

How did you install the library ? Did you unzip it to your Libraries folder ? Did you need to change the folder name to get rid of any characters that are not allowed in the folder name like “-” ? Did you verify that there were not TWO folders named “Hx711” ?
(One inside the other)

I copied the sample code from that page and pasted it into a new sketch in the IDE. When I try to upload the sketch I get the error ‘Hx711’ does not name a type and the statement “Hx711 scale(A2, A3);” is highlighted in yellow.

What page ?
I can’t find any sample code .

raschemmel:
How did you install the library ? Did you unzip it to your Libraries folder ? Did you need to change the folder name to get rid of any characters that are not allowed in the folder name like “-” ? Did you verify that there were not TWO folders named “Hx711” ?
(One inside the other)

I copied the sample code from that page and pasted it into a new sketch in the IDE. When I try to upload the sketch I get the error ‘Hx711’ does not name a type and the statement “Hx711 scale(A2, A3);” is highlighted in yellow.

What page ?
I can’t find any sample code .

On this page: http://www.dfrobot.com/wiki/index.php/Weight_Sensor_Module_V1

Scroll down and there is some sample code and the link to the library file is there too.

I am assuming that copying from listing like that and pasting the code into and out of text files and the IDE using Notepad is OK.

Here is the code again:

/*
 * description:
 * The sample code for digital weight scale of hx711. The weight will be printed in the serial.
 * library host on https://github.com/aguegu/ardulibs/tree/3cdb78f3727d9682f7fd22156604fc1e4edd75d1/hx711
 * connection:   
   Hx711.DOUT - pin #A2
   Hx711.SCK  - pin #A3
*/
 
 
#include <Hx711.h>
Hx711 scale(A2, A3);
 
void setup() {
  Serial.begin(9600);
}
 
void loop() {
  Serial.print(scale.getGram(), 1);
  Serial.println(" g");
  delay(200);
}

Jack

michinyon:
Check that the name of the class inside the included file is actually Hx711, which is the class you are trying to create an instance of. It might be HX711 or something. Case matters.

Otherwise, it is not finding the h file, for some reason. Check you put it in the correct place. Check that you restarted the arduino IDE after you put the h file there.

The link for the library (on that dfrobot page above the code) downloads it to the file "Arduino sample code.zip", when that is unzipped it extracts to a folder under the libraries folder (which I choose as the target for extraction) where the IDE install is. It extracts to subfolder libraries/HX711 sample code and that folder is then renamed to Hx711 to match the names of the Hx711.c and Hx711.cpp files the folder contains.

I've checked case in the files and it is all in agreement with "Hx711" for folders and files.

Jack

Added note: My apologies! I was wrong about having the path sorted out right. I think I found the error, that being a path with an extra folder enroute to the Hx711 folder.

I'll give that another go later and follow up here,

Thanks again,

Jack

it extracts to a folder under the libraries folder

but which libraries folder ?
The one in the folder where your sketches are filed (correct) or the one under Program Files\Arduino (incorrect) ?

raschemmel:
How did you install the library ? Did you unzip it to your Libraries folder ? Did you need to change the folder name to get rid of any characters that are not allowed in the folder name like "-" ? Did you verify that there were not TWO folders named "Hx711" ?
(One inside the other)

As described in the post above. The zip file extracted to libraries/HX711 sample code, it extracted to two subfolders

/libraries/HX711 sample code/Hx711 (files = Hx711.cpp, Hx711.h)
/libraries/HX711 sample code/examples (with subfolders LiquidCrystalScale and SerialScale, each of which contain a *.ino file with the same name as the subfolder)

Oh oh! I just spotted my mistake I think, I have an extra subfolder in that path:

/libraries/HX711 sample code/Hx711/ (files = Hx711.cpp, Hx711.c)

Should be:

/libraries/Hx711 (files = Hx711.cpp, Hx711.h)

I copied the sample code from that page and pasted it into a new sketch in the IDE. When I try to upload the sketch I get the error 'Hx711' does not name a type and the statement "Hx711 scale(A2, A3);" is highlighted in yellow.

What page ?
I can't find any sample code .
[/quote]

I think you forced me to find my mistake. Thank you for that! And the page with the sample code is the dfrobot page:

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

I'm away from the computer that has the IDE install, it is down in my 52F/11C basement, I'll go down there later and straighten out that path and try again. We are at 16F/-9C here in Maine today, my 72 year old head is getting off to a slow start, and I'll probably soon get another 6" or so of snow that will have relocated from where it falls...

Thanks for the help and your patience guys!

Jack

Sorry, but I still can't tell which libraries folder that you have installed it in.

UKHeliBob:
Sorry, but I still can't tell which libraries folder that you have installed it in.

There is a libraries folder in the folder where the IDE is installed (off the root of the g: drive on my system) and that is where I have been storing libraries. I'm just trying to keep them all in the same place...

At any rate, the error has gone away and the problem is solved. It was, as I had suspected, that I had extra folder in the path to the library. When I moved the Hx711 folder so as to put it under the libraries folder the error went away and the problem was solved.

So again, thanks to all for the help!

Jack