Where to locate .h files in ide 2

HI,

I have a sketch and a header file. The sketch is located at :

C:\Users\Paul\Documents\Arduino\ControlBox

could someone inform me where I need to place the header file in order for it to be found when compiling?

Currently it is at :

C:\Users\Paul\Documents\Arduino\Libraries

but this generates tje following compile error:

C:\Users\Paul\Documents\Arduino\ControlBox\ControlBox.ino:32:10: fatal error: linkedList.h: No such file or directory
 #include "linkedList.h"
          ^~~~~~~~~~~~~~
compilation terminated.

exit status 1

Compilation error: linkedList.h: No such file or directory

Perhaps in preferences it might be useful to include an option for library files location?

thanks.

Libraries that you want to be accessible to all sketches should go in folders under C:\Users\Paul\Documents\Arduino\libraries\

It is normal for each library to be in a folder with the same name as the .h file but that is not strictly necessary. Such libraries can be #included in a sketch using a command such as

#include <libraryName.h>

If you want the library to be used by a particular sketch then put the library files in the same folder as the sketch and #include it like this

#include "libraryName.h"

If the library is not found in the sketch directory when this form of include is used then the compiler will search the normal library paths to find it

Note that board specific libraries that are installed when a board is installed are not placed in the normal libraries folder of the sketchbook

thanks for reply, I'll give that a try. :slight_smile:

Ok that worked, is it possble to open my .h file in the IDE 2 ? I found in the left panel as below, but when i click, the file does not open

image

If you put the library files in the same folder as your sketch then they will appear as tabs in the IDE sketch edit window

My OS is Windows, and for editing .h and .cpp files in their normal locations I usually use Notepad++

Ah right. I've come from Platformio (no working code upload solution for AVR4809) and the files are listed in the left pane as with arduino IDE 2, but they open when clicked. No worries, I use notepad++ too.
thanks.

If you right click on a variable or function in your sketch that is defined in any library or .h file and click "go to definition" it will open a new tab for that file
.

For Example: If you right click on "pinMode" it will open the wiring_digital.c file where it is defined

Brilliant - same as in Vscode/ Platformio, that's really useful to know. I'm sure I'll find out more as I go along - thanks :slight_smile:

I just tried the right click on a function name, but it doesn't work. I have my functions forward declared. e.g.

int getCurrentAzimuth();

but if I right click (or F12), I just get an error message :

'no definition found for getCurrentAzimuth'

The function getCurrentAzimuth() is defined (as with all others) after the loop() code

The code compiles.

do I need an extension perhaps?

I'm using IDE 2.1.0
cli 0.32.2

thanks.

as a simple test, I just created this

void setup() {
  // put your setup code here, to run once:
testpk();
}

void loop() {
  // put your main code here, to run repeatedly:

}
void testpk()
{

}

but right click on testpk() gives the same result - no definiton

thanks for any thoughts on this.

Hi @Paulskirk53. Which board do you have selected from the Tools > Board menu in Arduino IDE?

it's the ATmega4809

OK, this is the cause of the error. Unfortunately the clangd C++ language server that provides the "code aware" features like "Go to Definition" in Arduino IDE does not have support for this specific microcontroller:

Support has actually been added to clangd recently, so the only remaining task is for the Arduino IDE developers to update the version of clangd used by Arduino IDE to the one that contains that advancement (Arduino IDE is currently using a slightly outdated version of clangd). So at least we know that sometime in the not too distant feature you will be able to use these features with the ATmega4809, but at this time it won't be available. With the exception of megaAVR 0-series parts like the ATmega4809, I think you'll find the support for the many microcontrollers used by the Arduino community is pretty comprehensive so if you use other boards you'll probably find these features work in the IDE.

ah, right, thanks for this. I changed the board to a mega2560 (as a test) and as you say the features work fine.

Hope the Arduino IDE update happens soon :slight_smile: :slight_smile:

thanks for help.

You are welcome. I'm glad it is at least working for you with the supported boards.

Regards,
Per

Thanks, I now have a different problem with code upload. In IDE 1.8.13 a blinkled sketch uploads fine, but when I try in IDE 2, I get an error message 'a programmer is required to upload'

I've checked the tools menu settings and they are the same as the ones used in IDE 1.8.13 - key selections from the tools menu are:

Board ATmega4809
COM24 (arduino uno)
Programmer JTAG2UPDI

any help much appreciated.

I would think that these two contradict each other.

The JTAG2UPDI firmware sits on the Uno board, so when you select a port in tools> port, the Port (COM24 in my case) is described as 'COM24 (arduino uno)'.

As I mentioned, the settings work fine to upload code to the AVR 4809 in Arduino IDE 1.8.13, but I'd like to have the benefits of IDE 2 if possible.

I've probably missed something somwehere in the IDE 2 / JTAG2UPDI install / setup perhaps?

You are selecting "Sketch->Upload Using Programmer" from the menu? Clicking the "Upload" button does not automatically use the programmer in IDE 2.

Thanks for the reply.

Works in IDE 2 whereas in 1.8.13, as you say, the upload button automatically uses the programmer - so that's a difference to watch out for :slight_smile: :slight_smile: