Managing multiple sketches for multiple boards

How would I go about easily managing an Arduino project that has multiple sketches(project/sketch_0/sketch_0.ino; project/sketch_1/sketch_1.ino; ecc.) for multiple boards with a unique configuration .h file in the project root directory?
I've already tried

`
#include "../config.h"

...
`

or

`
#include <../config.h>

...
`

but it doesn't seem to work. Any help?

What do you mean it does not work? is there a compile error message? Is the project root directory different from your Arduino directory?

This is the folders tree:

./
├── config_file.h
└── sketch_0
    └── sketch_0.ino

This is an example code:

#include "../config_file.h"

void setup() {

}

void loop() {

}

This is the error I get:

fatal error: config_file.h: No such file or directory
 #include "config_file.h"
          ^~~~~~~~~~~~~~~
compilation terminated.

exit status 1

Compilation error: config_file.h: No such file or directory```

So it's saying that it can't find your file.

Assuming that a file by that name does actually exist, that must mean that it's looking in the wrong place.

Maybe "../config_file.h" ?

Have you tried adding a folder in your Arduino Sketch folder under Libraries, create a folder there and put your header file in that folder and restart the Arduino IDE.

For example (PC):

Documents/Arduino/Libraries/config_file/config_file.h

My bad, before I had tested it with ../ before, I forgot to include it here

That does work, but I wanted this project to be portable

What do you mean by portable?

1 Like

With portable I mean the ability to pack everything in one folder and easily upload everything to github

If your sharing the project with other people, just create one folder to upload & have two sub folders with the config file & project in separate folders, then put a read me file with instructions of folder location. Otherwise create your own library for your project.

It sounds like your making things more complicated then they need to be, I'm sorry but I don't have anymore suggestions.

Thank you for your time

Hi @tizio7721

The reason this doesn't work is because the sketch code is copied to a temporary build folder after it is converted to C++. The C++ compiler is compiling the code in that temporary build folder, so a relative path to a location outside the sketch folder in an #include directive won't work.

You could package it as a sketchbook:

./
├── libraries/
│   └── config_file/
│       └── config_file.h
├── sketch_0/
│   └── sketch_0.ino
├── sketch_1/
│   └── sketch_1.ino
...

The user would set the Sketchbook location path in their preferences (accessed via File > Preferences in the Arduino IDE) to the root folder of the project. This will cause the IDE to be able to find config_file.h when the sketches contain an #include directive like this:

#include <config_file.h>

I'm doing this right now with an Mega328 PLC board and an ESP32 5" display as an HMI for the PLC. The solution I chose is VS Code with platformIO. I create a workspace with two project, one for each board.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.