Breaking program up - Multiple files, headers, etc


My code for the project is getting pretty long in the arduino editor. Is there a good way to split things up a bit using multiple file with headers and all that. I saw the "howto make a library" thing, but I don't want a library, i just want to spilt it up a bit for organization sake.

I guess on a further note, is there a documented way to do everything from the command line using make or something? The arduino editor is great for small projects, but its starting to get on my nerves. I just want to use gvim and make a script to do everything I need. (i'm on OS X) I saw a thread talking about doing this, but it didn't seem to come to any solid conclusions.

You can create multiple tabs (files) in a sketch using the menu accessed by the right-facing arrow in the upper right corner of the IDE.

There’s a makefile and howto here:

When I use the "tabs" way to make new files, do I have to reference them from my original project, or does Arduino editor do that for me? (like #include "otherfile.h")?

If you don't give your new tabs an extension, they will be concatenated together with the main tab to create a single file (and then preprocessed to generate function prototypes), so you don't need #include's. If you add .c, .cpp, or .h tabs to the sketch, you'll want to #include the appropriate headers as normal for a non-Arduino program. The .c and .cpp files will be automatically linked against your main tab, though. Also, note that the main tab is compiled as C++, so if you add .c files / tabs to the sketch, you'll need to wrap the function declarations in an extern "C" {} block (conditional on #ifdef __cplusplus), as you would to use C code from C++ code in any other context.

Thats handy that adding the tabs works as such. I'll probably just do that. If my programs start to get bigger, I might take a look at that arduinocore thing so I can use my own editor.

I have to get used to pretending that I'm coding c++. I'm mostly a c junkie, and I kinda don't like c++.

I have to get used to pretending that I'm coding c++. I'm mostly a c junkie, and I kinda don't like c++.

Interesting comment. Of course you can write all your own stuff using C but most Arduino libraries have a C++ class interface. I am wondering what you don't like about C++? If you are planning on writing programs big enough to need dividing into multiple files, you may find that using C++ classes makes it easier to organize and structure your modules.

I highly recommend a book by Bruce Eckel called 'Thinking in C++', it is a comprehensive study of how C++ makes programming easier and more efficient. The first chapter gets to the heart of C++. It may change your life ;)

You can download an html version of the book for free:

and this page has other books by Bruce Eckel:

I dont' really know why I don't like c++. I had to code in it a while back making a GUI program in QT.

I think that when I'm doing low level stuff, I want to keep it simple like c. And when I'm being high level, I want something more high level like python. Granted, I mostly code in Matlab for my research and schoolwork, which is very high level.

C++ seems like it has so many overly complicated features, that don't really add much for me.

My program shouldn't grow to more than 600lines, which is a bit much for the arduino window, but not enough to get all complicated with C++ classes and stuff.