I2C_Keypad problem

I have been trying to get a I2C_Keypad sketch to compile, but keep getting the same error message.

Arduino: 1.8.3 Hourly Build 2017/07/25 11:12 (Mac OS X), Board: "Arduino/Genuino Uno"

/Users/herbblair/Documents/Arduino/HelloKeypad_I2C/HelloKeypad_I2C.ino:16:24: fatal error: Keypad_I2C.h: No such file or directory
#include <Keypad_I2C.h>
^
compilation terminated.
exit status 1

I have the .h file in the same folder as the sketch, along with the CPP file.

Any help would be appreciated.

Try this:#include "Keypad_I2C.h"

Jacques

I have that in the sketch.

#include <Keypad_I2C.h>
#include <Keypad.h>
#include <Wire.h>
#define I2CADDR 0x27

No, you don't.

Change <Keypad_I2C.h> to "Keypad_I2C.h".

I have the .h file in the same folder as the sketch, along with the CPP file.

That is why I suggested the quotes instead of the brackets.

Why should the header file be within double quotes and not within angle brackets?

Because you

have the .h file in the same folder as the sketch, along with the CPP file.

When other two header files (keypad.h and Wire.h) work well being within angle brackets, the problem is with the keypad_I2C.h file.

Now, is there anything that the OP can do so that all these three header files work in an consistent way being within angle brackets?

The use of angle brackets (<>) causes the compiler to look for the file on the default path for the library directory. Depending upon installation, this path is the Documents/Arduino/libraries directory on a Windows machine.

The use of double quotes ("") around the header file causes the compiler to look in the sketch working directory for the header file. The default sketch directory can be seen in the File --> Preferences menu option. If the file is not found there, it will also search the default library directory.

Thanks with +1 for well clarification of the difference between keeping the header file within double quotes and angle brackets.

jbellavance:
The use of angle brackets (<>) causes the compiler to look for the file on the default path for the library directory. Depending upon installation, this path is the Documents/Arduino/libraries directory on a Windows machine.

The use of double quotes ("") around the header file causes the compiler to look in the sketch working directory for the header file. The default sketch directory can be seen in the File --> Preferences menu option. If the file is not found there, it will also search the default library directory.

Not a very good explanation. Where did you find that?

The use of angle brackets (<>) causes the compiler to look for the file on the default path for the library directory.

Actually there is a whole list of directories that are searched for the file:

  • Sketchbook: {sketchbook folder}/libraries. The sketchbook folder location can be found (or changed) at File > Preferences > Sketchbook location:.
  • IDE: {Arduino IDE install folder}/libraries. This is for the libraries included with the Arduino IDE installation.
  • Core: Libraries bundled with hardware packages. This is dependent on the current selection in Tools > Board. Location will depend on if you're using a hardware core bundled with the IDE, installed via Boards Manager, or manually installed to {sketchbook folder}/hardware.
  • Toolchain: The compiler package also provides library files that can be included (e.g. avr/wdt.h).

Depending upon installation, this path is the Documents/Arduino/libraries directory on a Windows machine.

It might happen to be there but it's much more correct to say the libraries subfolder of the sketchbook folder.

causes the compiler to look in the sketch working directory for the header file.

It searches in the folder containing the file that contains the include statement. That file may or may not be a sketch.

The default sketch directory can be seen in the File --> Preferences menu option.

Which is completely irrelevant and also it's called the sketchbook directory.

Where did you find that?

Found it here from econJack

Thanks for making it cristal clear, Pert.

Jacques

OK, that makes sense for a quick forum reply. I thought it might have been quoted from somewhere in the official documentation, in which case it would be worth improving.

I have executed a small program to monitor temperature using internal sensor of DS3231RTC and to display it using I2C 16x2 LCD. I may include the following two header files in any combinations of double quotes and angle brackets; the program always works.

LiquidCrystal_I2C.h
Wire.h

When I searched my PC, I found the these header files under the directories as indicated.
LiquidCrystal_I2C.h : Could not trace the directory!?
Wire.h : c:\Program Files\Arduino\hardware\arduino\avr\libraries\Wire\src\Wire.h

My question: Is it really important for a programmer to care about the use of double quotes or angle brackets while including the header files? Traditionally, we are accustomed in the use of angle brackets.

If you have those files installed to a standard libraries folder then you can use either syntax because both cause the standard libraries folders to be searched. However, if you know the file is not in the local folder then using the quotes syntax will perhaps slow compilation a bit as an extra folder is unnecessarily searched. Conversely if you use the angle brackets syntax to try to include a file that is not in the standard libraries search path then it won't work (as hblair discovered).

So if you wanted to be safe you could always use the quotes syntax. This would only be problematic in the rare case where there is a local file matching the included file name that you don't want to include, preferring a file of the same name located in the standard search path. For a beginner that might be a reasonable approach but also a beginner will practically never have a local file include so angle brackets will serve them just as well.

For anyone more experienced, I say tke a few minutes to understand the difference and then always use the most correct syntax. Unfortunately it's very common to see angle brackets used for including local files in Arduino libraries. This works fine when the library is installed normally but if you want to bundle the library with a sketch so you can distribute it as a self-contained package you need to fix all the instances of incorrect use of angle brackets. This is a good example of why it's best to just understand which syntax is correct and use it.

GolamMostafa:
LiquidCrystal_I2C.h : Could not trace the directory!?

If you can include it then it must be somewhere on your computer.
To find any library that has example sketches do this:

  • Tools > Examples > open any example from the library you want to find
  • Sketch > Show Sketch Folder - this will open the example folder inside of the library folder.

Another way to find it is to enabling verbose output during compilation in File > Preferences and then examining the contents of the console after a compilation of a sketch that includes the library.

pert:
To find any library that has example sketches do this:

  • Tools > Examples > open any example from the library you want to find

I think you mean File > Examples

Thanks for the correction LesserMole! That was in of my collection of text snippets I use to copy/paste into my forum replies so it's definitely important for me to fix it.

GolamMostafa:
I have executed a small program to monitor temperature using internal sensor of DS3231RTC and to display it using I2C 16x2 LCD. I may include the following two header files in any combinations of double quotes and angle brackets; the program always works.

LiquidCrystal_I2C.h
Wire.h

When I searched my PC, I found the these header files under the directories as indicated.
LiquidCrystal_I2C.h : Could not trace the directory!?
Wire.h : c:\Program Files\Arduino\hardware\arduino\avr\libraries\Wire\src\Wire.h

Did you search complete drives? That library might well be in the documents folder.

GolamMostafa:
My question: Is it really important for a programmer to care about the use of double quotes or angle brackets while including the header files? Traditionally, we are accustomed in the use of angle brackets.

Yes. Imagine you have a project with library A which is conflicting with another library B and your project requires both (usually interrupt conflicts).

You can modify one of those libraries in their original location, but that will affect all your previous projects and all future projects that use the modified version of the library and might result in errors in previously working sketches.

So you make a local copy of the library in your sketch directory, modify it, include using double quotes and you're done; no side effect. As pointed out by pert, you will have to check all files of the modified library as they all need to use double quotes when including the library specific files from the sketch directory.

@pert

Following the guidelines of your Post#14, I have been able to trace the locations of the library files as follows:

1. Library files that are automatically installed when the IDE (1.8.0) is installed are found here:
a. c:\Program Files\Arduino\libraries\Library folders for 19 devices ike: LiquidCrystal and etc.
b. c:\Program Files\Arduino\hardware\arduino\avr\libraries\Library folders for 5 devices ike: SPI, Wire and etc.

2. Library files that are automatically installed when we download them as zip files, and later on include them using the IDE (Add .ZIP Library...).
c:\Users\GM\Documents\Arduino\libraries\Library folders for custom devices like: LiquidCrystal_I2C and etc.

Now, we see that there are three libraries; when you say standard library (Post#14), which library folder (1a, 1b, or 2) are you referring?

BTW: Enabling verbose does not provide the above information (1a, 1b, and 2).

Many many thanks along with karma point.

@sterretje

So you make a local copy of the library in your sketch directory, modify it, include using double quotes and you're done; no side effect.

About 27 years ago, as an Electrical Engineer, I wanted to learn DOS-C Programming and collected a book on C Programming where I encountered the case of the header file (s) being included using both double quotes and angle brackets. The question of the the then time -- what difference do they make -- is definitely better answered in Post#17. Thanks with +.

Did you search complete drives? That library might well be in the documents folder.

Yes! They are under c:\Users\GM\Documents folder; these Library Files are those files which we download as .zip files and later on include them using IDE (Add .ZIP Library...).