Subfolders in sketch folder?

I have a set of source files it would be nice to stuff into a subfolder in my sketch folder. They are not general purpose enough to be made into a library.

Does the IDE support subfolders in the sketch folder?


-jim lee

Recent versions of the Arduino IDE do support sketch subfolders, but it's restricted to the src subfolder. You can have as many subfolders under src as you like. The Arduino IDE does not open the files in subfolders, it only compiles them, so you won't see those files as tabs in the IDE and you would probably want to use a separate text editor to edit them.

I sometimes use this feature to bundle library dependencies with a sketch that I write for someone else, so that I can send them a complete program as a single package, with no library installation steps required.

src subfolder? is naming a subfolder "src" some sort of key for the IDE? Do I NOT need to put in things like

include "/scr/mycode/someClass.h'


Thanks for the tip. It sounds like exactly what I'm looking for.

-jim lee

jimLee: src subfolder? is naming a subfolder "src" some sort of key for the IDE?

The contents of the src subfolder have special treatment. Originally, the feature applied to all sketch subfolders but this caused breakage for people who had unrelated code stored in subfolders of their sketch, so it was then restricted to a specific folder.

jimLee: Do I NOT need to put in things like

include "/scr/mycode/someClass.h'

You DO need to do that, but don't put a leading slash on the path (because the path is relative to the sketch folder):

#include "src/mycode/someClass.h"


Worked great! To reference back I had to come up with ../../file.h Took a bit and some guessing but once that was sorted everything seems like smooth sailing!

-jim lee

Was that because you had multiple interdependent files in separate folders? That is a problem when I need to bundle multiple libraries that have dependencies, though it’s easy enough to update the #include directives. With normally installed libraries, we’re used to being able to just put the filename in angle brackets in our #include directives and have the Arduino IDE find it. In fact, a common problem you’ll see in libraries is using angle bracket #include syntax for local files. Although technically incorrect, that works fine when the library is installed normally, but not when it’s bundled with a sketch.

Exactly what was going on.

Mine is a GUI that can load one of a multiple set of sketches. Click an icon on the home screen, and it tells the OS, "I want, say.. #3" Then the OS loads the sketch that answers to that number. There is a little bit of cross dependancies because of the different sketch IDs. But then, once I got it working, I found myself buried in sketch source code files.

This works great! Once a sub-sketch is up and running on the system, I can make a folder for its files and tuck them away. I just leave out the files for the current sub-sketch under construction. Along with the OS.

Its pretty cool because it is working, but now my head hurts a little bit.

-jim lee