Hi,
I'm wondering, how is the IDE handling the include path for *.h files?
e.g. I create a new sketch (from a downloaded source). This sketch includes an include statement for an *.h file.
Where has the header file to be located so that the IDE can find it during compiling?
My locations are:
project folder for sketches: /mnt/nas_data/source/Arduino_WS/projects/...
when hovering over the include statement it shows the following path: /tmp/arduino-language-server2774629306/build/sketch (the include file is located in that folder)
However, the file <i2cScanner.h> contains a statement #if defined(ARDUINO) && ARDUINO >= 100 #include "arduino.h" #else #include "WProgram.h" #endif
During compiling I'm getting the error:
In file included from /mnt/nas_data/source_code/Arduino_ws/projects/i2c_scanner1.0/i2c_scanner1.0.ino:1:0:
/mnt/nas_data/source_code/Arduino_ws/projects/i2c_scanner1.0/I2CScanner.h:5:11: fatal error: arduino.h: No such file or directory #include "arduino.h"
^~~~~~~~~~~
compilation terminated.
exit status 1
With other words: If I'm using my "home made" include file, where has this file to be located during compiling.
I did in my career a lot code development, but I never experienced such an ambiguity about a setup when compiling code like with Arduino.
Perhaps someone knows the answer to my problem.
Thank you
It's capital-A; and since you're not on Windows, that matters.
#include <Arduino.h>
And you should use < > since it is one of "their" headers, not one of "your" headers. (What actually happens is more complicated, but that's the convention.)
If you want to know about the paths, or my suggestion does not fix the issue, we can discuss further.
If you downloaded a 3rd party library (one not included in the library manager) then when you Sketch/Include Library/Add zip library, it will get placed in the proper place. If it's a header you created, it just goes in the same sketch folder you are working on.
I want to compile the i2CScanner sketch.
I added the I2C library through the library manager.
Surprisingly three libraries appearing in the library manager.
a) I2CScanner by Luis Llamas,
b) I2C_Scanner by Rob Tillaart, and
c) I2C_Scanner by Gunce Akkoyun.
What a confusion. Why is it allowed to include three similar named libraries in the lib manager?
I used (up to this point) the library by Luis llama. And that's where I have the problems.
I noticed that in the I2CScanner.h file is an additional (conditional) include of Arduino.h.
I thought that's by default enabled in the Arduino IDE.
I'm stuck at this point and will continue testing tomorrow.
Thanks
Naming is hard. When publishing a library, you give it the obvious name, so people can find it; and then you have "by" and your name -- already assigned -- and give it a go. If it's early and good, then no one else will create another library with the same name, because yours already covers the use case. But maybe yours is not that good; you don't have a monopoly on that name. Or maybe someone wants to create a specific variant, and so they include the variant in the name so it is easier to find.
Of the three, the one by
Luis only has one release, six years ago
Rob is fairly recent, with several releases. The latest version is only 0.3.0, but maybe they are being modest. The release comments actually say stuff, unlike...
Gunce is version 1.0.4, which means some maybe some rough edges have been tweaked after release: a good thing. But the release comments are quite terse, which makes sense when looking at the diffs: not much really changed. There has been more real activity since then, but not released.
All three have at least one example, none of which is called just "i2CScanner". So that's your sketch?
No, as I said before, it's for "arduino.h". You can get away with the wrong case on Windows and Mac, which default to file systems that are not case-sensitive. Not so on Linux, which I would guess you're using since you have /mnt. In any case, C++ is definitely case sensitive, so you might as well be particular about it. Another demerit for the library by Luis.
Arduino.h is automatically and invisibly included in your .ino. But for an .h or .cpp, you would do it manually. It will be found when spelled and capitalized correctly, unless your install is broken.
More specific to the folder path: if you install a library correctly, you would not copy its header(s) into your sketch. Coincidentally, all three use a slightly different name for their header. So in your .ino
// ONE of the three -- whichever you have installed of course
#include <I2CScanner.h> // Luis
#include <I2C_SCANNER.h> // Rob
#include <I2C_Scanner.h> // Gunce
With a fresh mind set I tried it again.
This time I approached it from a different angle (and it worked).
Arduino IDE: I added the library (from RobT) through the library manager.
After that the examples from the library were available in the 'example' section of the library.
I compiled and uploaded an example (ssd_1306_128x32_i2c) from the Adafruit SSD1306 library and it worked fine.
However, I didn't get any results from all the aforementioned (I2C) libraries.
VSCode-PlatformIO: Here I also approached it the wrong way. Instead of creating a new project through PlatfromIO with the inclusion of the proper libraries, I started creating a project from scratch, that in turn missed the proper libraries. After I corrected that, compiling and uploading was working fine.
Some testing continues.
Thanks for responding to this thread.