IDE can't find header file that is in Library dir.

I'm new to Arduino and I'm running thru some tutorials. This one has two #includes and it finds one but not the other.

It's the Untrasonic tutorial.

#include <LiquidCrystal.h>
#include <NewPing.h>

LiquidCrystal is found (but I can't find it with a DOS dir /s search)
NewPing.h is not found (I found it with a DOS dir /s search)

So I moved it to the same dir as the other code and that changed nothing. I noticed it was actually loaded in a tab of the ide, but isn't being seen.

I'm running Win7 and I click on an .ino file, it loads up the IDE (1.8.9). So this had been working for some 10+ tutorials, no problems, now I have a new include and it chokes.

I don't know if it and ENV var that needs to be set or what.

Q. can someone tell me in step by step terms how to set the IDE so that it will see the libarary dir where the header files are?

Also, I don't see the other header file, is that in some package inside of some file format, maybe a sketch project file?

Thanks.

The normal place for your libraries is in a subfolder "libraries' of your sketchbook. By default that is "C:\users[user]\Documents\Arduino\libraries". They only exception are the libraries that come with the IDE (or downloaded boards). LiquidCrystal is a library that is shipped with the IDE.

After you place new files in the "libraries" folder you need to restart the IDE. If you add a library via the library manager you don't need to restart.

KarlJay:
#include <NewPing.h>

NewPing.h is not found (I found it with a DOS dir /s search)

So I moved it to the same dir as the other code and that changed nothing. I noticed it was actually loaded in a tab of the ide, but isn't being seen.

You could try this, it worked for me (with some other library):

#include "NewPing.h"

Also: check if there are files "NewPing.cpp" and "keywords.txt" in the map where "NewPing.h" was, you must move (or copy) them too.

Yeah, you can place them in your project. But why wouldn't you install it the right way?

KarlJay:
So I moved it to the same dir as the other code and that changed nothing. I noticed it was actually loaded in a tab of the ide, but isn't being seen.

When you use this syntax with #include directives:

#include <LiquidCrystal.h>

The Arduino IDE searches the library folders for the file.

When you use this syntax with #include directives:

#include "LiquidCrystal.h"

The Arduino IDE searches the current folder for the file, then if it's not found there the library folders as well. So for header files in your sketch folder you need to use the double quotes syntax. However, please don't dump library files in your sketch folder simply as a workaround for not understanding how to install a library the right way. Learning how to install libraries is an essential skill for every Arduino user.

There is a guide to installing Arduino libraries here:
https://www.arduino.cc/en/Guide/Libraries

However, please don't dump library files in your sketch folder [..]

Right, of course. But I was creating a library from scratch, and it's a whole lot easier that way. It will be moved to the correct locaction when it's finished and tested.

I don't see how that's easier... ::slight_smile: Except it opening with your sketch in the IDE.

Windows won't let me edit any file in C:\Program Files (x86)\Arduino\libraries , so I just have to do it this way.

Like I said, you should NEVER place a library there :wink: That's reserved for the libraries that ship with the IDE. Your library and downloaded libraries should go in the libraries folder of your Sketchbook. By default located in C:\Users[user]\Documents\Arduino\libraries. And files there are fine to edit :slight_smile:

Oops, I forgot about C:\Users[user]\Documents\Arduino\libraries.

Except it opening with your sketch in the IDE.

Which still is a big advantage. Anyway, thanks for your explanation.

Yeah, although I like Notepad++ more. But I asked because I was suspecting misuse of the IDE library folder :wink:

Erik_Baas:
But I was creating a library from scratch, and it's a whole lot easier that way.

Oh, I didn't realize because you mentioned the file names used in some common existing libraries. Way cool that you're writing your own library! That's super useful whether you want to share code with the world, or just between multiple of your own projects.

Erik_Baas:
Which still is a big advantage.

I use the Arduino IDE to write my Arduino libraries in this way also. Although I like Notepad++ for writing code for non-Arduino projects, I end up using the Arduino IDE to compile and upload the sketch for testing during library development so I find it more convenient to use it for writing the library as well.

Ok, so I found the libraries on the C drive and copied the two files (.cpp .h) from the E drive (where I installed the Arduino mega kit stuff.

I close all IDE's and double click to load a new one. It still has the same error.

I have the c:\users\KarlJay\Documents\Arduino\libraries sub and it has those files in it (it was empty before).

When you say "reset" the IDE, you mean close all the IDE's and then open a new one, right?

I type SET to see the vars and didn't see anything Arduino related.

I also didn't see any other files in that dir, the liquidcrystal wasn't there.

I'd like to do this the right way, but I was trying any way I can make it work when I was dumping it into the same dir as the project. BTW, that didn't work either.

I'm guessing that the IDE needs to be configured somehow.

Is there some setup process in the IDE that I missed?

Remember, I'm old to programming, but new to all the Arduino stuff.

BTW, this Arduino stuff is pretty damn cool. Can't wait to get some custom projects going.

I used Sketch->Include Library->Manage Libraries from the menu in the IDE.

Searched for the header file name, found it and installed it.

It's not working.

So I guess I have to install each one of these. No problem, just didn't know how, now I do.

Thanks for the help and quick replies, look forward to more learning.

Clear typo on the last post, don't know how to edit it.

I meant to say NOW instead of NOT in the line It's not working.

It's not working should read it's NOW working.

:smiley:

KarlJay:
I have the c:\users\KarlJay\Documents\Arduino\libraries sub and it has those files in it (it was empty before).

The library files need to be in their own folder. For example, let's say you have a library named KarlJayLib. The correct folder structure would look like this:

c:\users\KarlJay\Documents\Arduino
|_libraries
|_KarlJayLib
|_KarlJayLib.cpp
|_KarlJayLib.h

That is the Arduino Library format 1.0. You can also use the Arduino Library 1.5 format if you prefer:

c:\users\KarlJay\Documents\Arduino
|_libraries
|_KarlJayLib
|_library.properties
|_src
|_KarlJayLib.cpp
|_KarlJayLib.h

Note that the library.properties file is required when using the 1.5 format. The specification for library.properties is here:

KarlJay:
When you say "reset" the IDE, you mean close all the IDE's and then open a new one, right?

Correct. If you're using any recent version of the Arduino IDE, restarting it after manually installing a library is not absolutely necessary. The library's example sketches will not show up in the File > Examples menu, the library will not show up under the Sketch > Include Library menu, and keyword highlighting will not work until after you restart the Arduino IDE, but you will be able to use the library itself without restarting.

Since you're using the Arduino IDE to write your library, you might be interested to know how it's possible to do this with libraries that are installed normally under your c:\users\KarlJay\Documents\Arduino\libraries folder:

  • Add a dummy .ino file to the folder containing the library files you want to edit with the Arduino IDE. The .ino filename must match the folder name. This allows the Arduino IDE to open the library source files as if they were a sketch. This file will not actually be compiled as part of the library. I use it as a place to store my "to do" list. You could also use it for a test sketch for the library, in this way you can actually compile the library right from the same IDE window where you are editing it instead of having a sketch open in a separate IDE window.
  • Add a file named .development to the root of the library folder. This is necessary because otherwise the Arduino IDE treats the contents of the library as read-only (to prevent people from accidentally modifying example sketches).
  • If it doesn't have one already, add a file named library.properties in the root of the library folder. This is required for the .development feature to work.

Having the library installed in c:\users\KarlJay\Documents\Arduino\libraries allows you to use it as a normal library. This means you can use the angle brackets syntax in your #include directives and you can use the library from multiple sketches. Your It will also allow you to catch problems with your library.properties and keywords.txt files

Update for anyone that might read this and still get stuck.

What I stated before worked, but then didn't work when I got to the DHT.h include.

For that, I went in the libraries dir and made a DHT subdir and copied the DHT.cpp and DHT.h into there.

I did this because I noticed that the library manager was making subdirs for me, so I just did it myself. I guess the lib manager saw when I copied the files (cpp/h) into the lib sub, but it didn't see the DHT ones, so I just did it myself on a hunch and it worked.

Hope this will save someone some time in the future.