Pretty image
If you’re going to do serious Arduino development, you may want to work in an environment more like your day job. Here Maik shows how to set up your own IDE.

Crafting your own IDE is eminently doable but there are some hidden gotchas to avoid. Here is one a case study on how you might go about it, along with some general advice for those aiming to set up a serious work environment for Arduino development.

Case Study: Using Vim for Arduino Development

A popular editor among software developers is Vim, and for Vim users a Makefile is nearly all that’s needed to start professional Arduino development. Vim comes with a built-in make command that invokes the Makefile in the current directory and parses its output.

Vim creates a list of all warnings and errors in the compiler output and after make returns it automatically jumps to the position of the first problem. This is called QuickFix mode and you can learn more about it by reading Vim’s documentation (:h quickfix) or Matthieu Weber’s excellent article.

Unfortunately, compiling the Arduino libraries produces a lot of warnings in QuickFix mode. Fortunately, you can safely ignore them. To make these warnings go away, you can add a pattern to Vim’s errorformat variable. The best way to do this is with an autocommand that is invoked automatically whenever you open a new Arduino file. So add the following to your ~/.vimrc file (you have to adjust the path to the IDE’s installation directory accordingly):

 autocmd Filetype arduino set
  errorformat^=\%-G%.%#/path/to/Arduino/IDE/%.%#

This will ignore all warnings and errors that are produced when compiling one of the Arduino’s system libraries. But how does Vim know that a certain file is an Arduino file? Arduino files often have the extension pde, but they can be h or cpp files as well. So the best way to tell Vim that a file belongs to an Arduino project is to put this information into the file itself using a mode line.

Mode lines are special comments containing Vim directives. They must be the first or last lines of a file. You enable the modelines feature by adding the command set modelines to your ~/.vimrc file (be careful: some people think that the mode lines feature is a potential security risk!). Then add the following comment to the end of all your project’s files:

 // vim:ft=arduino

Now Vim will treat all your files as Arduino files and the only thing missing is proper syntax coloring. Fortunately, Johannes Hoff has created a Vim syntax file already. You only have to copy it to your ~/.vim/syntax directory.

Of course, you can add as many helpful commands as you like, but at this point you have turned Vim into a full-blown Arduino IDE.

More IDE Alternatives

Every advanced text editor supports Makefiles, so with the techniques you’ve learned in this article you can easily turn GNU Emacs, for example, into a perfect Arduino IDE.

For some editors, like Textmate, you can even get ready-made plugins. These plugins usually emulate the original IDE’s features; that is, they add a special Arduino menu where you can choose your board’s type and your serial port.

This certainly sounds useful, but unfortunately most plugins do not work very well in practice. Their biggest problem is that they are often tied to certain versions of the Arduino environment. So if you need a feature of the most recent version, for example, you’re stuck. The same is true for new hardware releases. If the plugin is not updated for a new Arduino board, you cannot use it.

Maintenance problems get even worse with “real” IDEs such as Apple’s Xcode. Creating templates for such products often is a major undertaking, so you can only find a few attempts on the Internet and at the moment none of them works with the most recent versions of Arduino and Xcode.

All in all I strongly suggest that you use the most minimalistic approach; that is, use a Makefile and integrate it into your favorite text editor. This way you have at least a chance to respond to changes in the Arduino environment.

Maik Schmidt is the author of Arduino: A Quick-Start Guide. He has worked as a software developer for more than fifteen years, creating solutions for large enterprises. He frequently writes book reviews and articles and is also the author of Enterprise Recipes with Ruby and Rails and Enterprise Integration with Ruby.

Send the author your feedback or discuss the article in the magazine forum.