Go Down

Topic: I2C_Keypad problem (Read 872 times) previous topic - next topic

hblair

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.

jbellavance

Try this:
Code: [Select]
#include "Keypad_I2C.h"

Jacques
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

hblair

I have that in the sketch.

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


oqibidipo

No, you don't.

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

jbellavance

Quote
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.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

GolamMostafa

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

jbellavance

#6
Feb 15, 2018, 05:04 pm Last Edit: Feb 15, 2018, 05:05 pm by jbellavance
Because you
Quote
have the .h file in the same folder as the sketch, along with the CPP file.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

GolamMostafa

#7
Feb 15, 2018, 05:30 pm Last Edit: Feb 15, 2018, 05:36 pm by GolamMostafa
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?

jbellavance

Quote
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.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

GolamMostafa

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

pert

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?

Quote
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).


Quote
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.

Quote
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.

Quote
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.

jbellavance

#11
Feb 15, 2018, 10:45 pm Last Edit: Feb 15, 2018, 10:45 pm by jbellavance
Quote
Where did you find that?
Found it here from econJack

Thanks for making it cristal clear, Pert.

Jacques
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

pert

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.

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

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.

pert

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.

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.

Go Up