Multiple files project

Once we get familiar with Arduino’s IDE, we wrote many lines of code which tend to create huge pde files. And there we touch the limits of this IDE and look for various options. Firstly, it would be great to use a better editor with plenty of these fancy features which make the programmer’s life happier.
All you have to do is to select File | Preference menu and check the Use External Editor box. The code appears now in grayed background and you can no longer change it from Arduino’s editor.
Then you start your favourite external editor and open the file. Do the changes in the external editor and save the changes in the same file (no save as, otherwise, Arduino’s IDE will not know!).
In Arduino’s IDE, run Compile and Upload as usual.

Note: Compile errors are highlighted as usual in Arduino’s IDE.

Which editor could we use? I personally found very interesting to us the Notepad++ editor (available from here). It contains nice features for editing code. It also allows you to customize the editor for specific mnemonics, so that your specific Arduino functions and key words will appear in the proper colour. It is possible to use Micro$oft Visual Studio in its Express Edition too, and it’s free.

Ok, now you have used a fancier code editor and you have generated ten times more lines of code, and, let say the world, it tends to be messy. Before building libraries, what else can we do?

Use the multiple files features from Arduino’s IDE! Let’s learn by doing.

We decide to create a “BigProject”. Open a new sketch using the File | New menu. Fill in the mandatory functions setup and loop and save the sketch as the BigProject using the File | Save as… menu. So that we have now a BigProject directory containing a BigProject.pde file. This sketch shall contain the high level routines and functions. But we need specific features like LCD display and Buttons routines and functions.
Click on the horizontal arrow at the top right of Arduino’s IDE and select New Tab. Enter the name for the new tab. Arduino will automatically create a .pde file which will use the tab prefix.
Enter the code in the new sketches, save and compile as usual. Arduino will gather all code for building one application.

Note: The Save function saves all opened sketches in Arduino’s IDE

Leave a Reply

You must be logged in to post a comment.