Including a file ABOVE the directory the .ino file resides in


I store my Arduino code on Dropbox. This is wonderful as I can access and edit from anywhere at anytime I'm in front of a computer. To get things to compile, I just download the appropriate libraries and installed them in the Arduino/libraries sub-directory on the host computer.

Currently, I am working on a hexapod robot and a remote controller to operate it. I store all of the code in a directory on Dropbox called Hexapod. In this directory, I have two subdirectories: Robot and Remote. Thus, the directory structure is something like:

 1 - Dropbox/Mike/
 2 - Dropbox/Mike/Hexapod
 3 - Dropbox/Mike/Hexapod/Robot
 4 - Dropbox/Mike/Hexapod/Remote/RemoteMainCode.INO 
 5 - Dropbox/Mike/Hexapod/Robot/RobotMainCode.INO 
 6 - Dropbox/Mike/Hexapod/Remote/RemoteMainCode.INO

For my current implementation, I need to share a list of common #defines for the radio link hardware that I am using in the code for both the Hexapod and the Remote; thus, I duplicate #defines in the two different .INO files.

Today, if I make a change in the RobotMainCode.INO file in the Robot sub-directory, I also need to make the same change in the RemoteMainCode.INO in the Remote sub-directory. When I remember, I spend time duplicating code. When I forget, I lose time troubleshooting...

This got me wondering: I'd like to point to a SINGLE common file and somehow point to it.

For example, I'd like to put a common file (e.g. "RFcodes.h") in the "Dropbox/Mike/Hexapod/Robot" sub-directory and somehow point to it from both INO files using #include. I'm imagining this is possible with something like:

 #include "RFcodes.h"


  #include "../RFcodes.h"

Has anyone done anything like this...?

Thanks in advance for any pointers,

You would need to specify the full path to the file. For example:

#include "C:\Users\Mike\Documents\Dropbox\RFcodes.h"

The problem with that is it makes your code not portable.

The reason you can’t do this:

#include "../RFcodes.h"

is that the sketch is copied to a temporary folder before compiling and so the relative folder location is changed.

An alternative is to put your RFcodes.h file in a library:

{sketchbook folder}

You can find the location of the sketchbook folder at File > Preferences > Sketchbook location.

Then you can do this:

#include <RFcodes.h>

OK! The direct file path ".../.../dropbox/.../... varies by computer and operating system so I didn't think there was going to be an easy way to do this.

As I have to edit a file anyway, I guess making and updating a library file is the next best thing to the file living a directory "up" in Dropbox. Perhaps in some future release...

Thank you for the advice and the fast reply!