0

I'm trying to use an HX711 load cell amplifier with my NodeMCU 0.9. I've found this library on Github and, following this guide, I tried to use it.

Unfortunately I keep getting this error:

sketch/HX711.cpp:2:19: fatal error: HX711.h: No such file or directory
 #include <HX711.h>

I suppose that there's some problem with C++ but I don't understand what is.

Here's the initial code:

#include <ESP8266WiFi.h>
#include "HX711.h"

Here's the folder structure:

Samples
  |-- nodemcu_test
        |--nodemcu_test.ino
        |--HX711.cpp
        |--HX711.h

Original question

2

You want to import a library not an example.

Arduino Folder
    |-- libraries
        |--HX711
            |--HX711.cpp
            |--HX711.h

ex:

C:\Program Files (x86)\arduino-1.8.5-windows\arduino-1.8.5\libraries\HX711

Put the files in a folder called HX711 to have everything nice and tidy.

I use the standalone version of arduino ide, if you have it installed I suspect the folder would be under

My Documents\Arduino\libraries\

According to the documentation.

You should put the nodemcu_test.ino in your sketchbook folder as I would generally avoid putting non-library files in the libraries folder. If you do want to keep the examples for a specific library close to the library create a subfolder:

Arduino Folder
    |-- libraries
        |--HX711
            |-- examples
                |--nodemcu_test.ino
            |--HX711.cpp
            |--HX711.h

As Juraj pointed out, this has the additional advantage of them being accessable in the examples menu.

If you want the libraries close to your sketch you are actually working on, follow the guide and put the library files in your sketchbook folder for your project. I would not advise for the following reasons:

I read that in newer IDEs 1.8.X you would need to put the files in a /src/subfolder. For me it did work without that, but the main caveat remained:

#include <HX711.h>

means to look in the library folder as mentioned above.

If you want to put the files somewhere else, you have to use

#include "HX711.h"

and specify the path (or in this example it was located where my .ino was). But now I also need to change

#include <HX711.h>

to

#include "HX711.h"

in the HX711.cpp file. What a hassle!

So my takeaway message would be: Stick with Arduino\libraries\.

  • @idkfa, fix and refine the paragraph about examples and you have my upvote – Juraj Mar 17 '18 at 11:10
  • @Juraj I extended the paragraph and even learned something on the way. Thanks for explaining why you didn't vote! – idkfa Mar 17 '18 at 11:43
  • @idkfa Sorry, I would upvote if I could, by now you deserve the best answer :) – Timmy Mar 17 '18 at 11:49
  • 1
    the examples from the example folder of a library are offered in the Examples menu in the IDE – Juraj Mar 17 '18 at 12:06
  • "you would need to put the files in a /src/subfolder". You only need to do that if you want to put the library in a subfolder of the sketch folder. This can be convenient if you don't want library files cluttering up your sketch but you always have the option of just putting all the files in the sketch's root folder. – per1234 Mar 17 '18 at 12:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.