Can I have and run 2 .ino files in same folder for 2 (client/server) Arduinos?

Hi,
I am working on a project which has 2 Arduino's talking to one another using SPI.
There is a lot of shared code between the two, and I have broken that out into separate .cpp/.h files, and am not ready yet to turn the shared code into libraries as it is still in a state of flux.

I was hoping to have 2 .ino files and all the .cpp/.h files in the same folder, and load each .ino into a separate instance of the Arduino IDE and run them in parallel, but this doesn't work as it tries to compile both .ino for the build.

The only way I have got it to work is to put the code into separate folders and anytime I make a change to the shared files, copy them into the other folder, not good at all... :frowning:

Is there a better way to do this?
Thanks

The problem is that the folder is the sketch, not the .ino file. Because many Arduino sketches only consist of a single .ino file, the .ino file is often thought of as the sketch.

The only solution I can think of is to use the preprocessor to switch between the two programs:

#define CLIENT  //comment this out before compiling for server

#if defined(CLIENT)
// client-specific code here
#else  // defined(CLIENT)
// server-specific code here
#endif  // defined(CLIENT)

Since all the .ino files of the sketch are concatenated into a single file before compilation, you only need to be sure that #define CLIENT macro will be defined above the code that relies on it, regardless of which .ino file that code is in.

Hi @pert
Thanks for the tip. I'll give that a go :slight_smile:

You're welcome. I'm glad if I was able to be of assistance.
Regards, Per

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