There comes a time in every Arduino programmer’s life when the Arduino IDE just isn’t enough anymore.
Don’t get me wrong; that basic editor with its handy examples and simple build button is great for getting started and quick sketches.
But when your program grows beyond a few hundred lines, you’ll want to start breaking your code into logical parts, across multiple files and easily reuse your work across several projects. That just isn’t what the Arduino IDE was designed for.
The solution? Visual Micro.
We use Visual Micro for developing our commercial projects. It is an add-in for Visual Studio, Microsoft’s development environment for Windows applications.
Visual Micro’s add-in extends Visual Studio to support Arduino development. One of the nicest things about Visual Micro is that it uses the same tools as the Arduino IDE to build your sketch. This means it works with all the Arduino compatible boards currently available, any new boards that are released and any custom board definitions that you’ve created for your own hardware. And, of course, you can use any Arduino libraries, including the MegunoLink Arduino library.
My Favorite Features
As an add-in to Visual Studio, Visual Micro lets you take advantage of a lot handy tools that make writing software easier and faster. Some of my favourite features are:
- Autocomplete: a little like text prediction on your phone, autocomplete provides a popup window with a list of variable and function names in your program as you type code. This saves a lot of time since you don’t have to scroll through the program to see exactly what the variable was called or use Google to find out what functions are available in Arduino libraries.
- Code navigation: lets you jump to the definition of a variable or function just by selecting it and hitting F12. As your program gets larger and spread across multiple files, code navigation lets you quickly move around your project, and even Arduino library files.
- All the errors: did you ever notice each time you fix an error in the Arduino IDE that another one pops up? That’s because they configure the compiler to stop on the first error. Visual Micro shows you all the errors it can find. Sure it is a little daunting to have 100 problems to fix, but far less frustrating than having them revealed one-by-one with no end in sight.
- Intellisense: finds errors before you build. Intellisense runs in the background analyzing your program while you are coding. Any errors it finds are flagged by a squiggly underline, just like a spelling error in a word processor. Errors highlighted as you are writing the code are much faster to fix than the those the compiler finds later on. Visual Micro sometimes finds a few things that aren’t errors, though it is getting better all the time.
- Error navigation: with Visual Micro errors are added to the Error List window. Double-click an error and the editor will jump to the offending line.
- Incremental search: this is my favorite feature in Visual Studio. Hit Ctrl+I, then start typing what you are looking for. The editor will immediately navigate to the closest match, narrowing it down as you type more. You’ll never need a clumsy find dialog box again.
- Hex file output: the hex files you need to program your Arduino board are easy to find in the project directory. You can program your board with Visual Micro’s built-in programmer during development. Then use MegunoLink’s Programming visualizer to program boards with the
.hex
file during production. - Arduino IDE compatible: as long as you stick to a single Project (more on projects below) and use only libraries from the Arduino library folder, your sketch will remain compatible with the Arduino IDE. So you can open the same sketch in Visual Micro or the Arduino IDE. This is really useful for trying out Visual Micro because you can work with either environment to get started.
Solutions and Projects
I think one of the greatest benefits in using Visual Micro for writing Arduino programs, however, is Visual Studio’s project system that is built around Solutions: collections of projects. Visual Micro adds a couple of project templates to the Visual Studio environment including:
- Arduino Project: this project is for your main sketch/program. It implements the main Arduino
void setup()
andvoid loop()
functions and creates the.hex
files that you’ll upload to your board. - Arduino Shared Code Project: creates a project with code that you can share with multiple Arduino Projects. This makes it very easy to re-use code.
Our approach to Arduino development has been to put most of the code into Shared Code Projects. Then reference these from the main Arduino Projects. Quite often, the main project might consist only of a few files with most of the implementation drawn from the libraries. I’ll often create a library of shared code to simplify testing. For example, one project we’ve been working on recently uses a complex state machine. That sits in a shared library that gets referenced from the main application project and smaller test projects that are designed to exercise the state machine. All the code lives in one solution and can be edited together and stored in a Git repository. Editing and testing would be much harder if I had to create these shared projects as traditional Arduino libraries.
Visual Studio
Visual Studio is available in a number of different versions including a free community version. Visual Micro will work with any of them.
For Arduino development, the Professional and Enterprise versions don’t really offer any benefits over the community version for individual developers. In fact, the only difference between the Community and Professional versions is that Code Lens is supported in the Professional version but not the Community version. And it isn’t useful for Arduino coding.
Get Visual Micro
Visual Micro is currently $US65 for a commercial license, with discounts for multiple licenses and educational/personal users. That’s about the same as a couple of Uno boards and a very worthwhile purchase if you want to do any serious Arduino programming. Best of all, it comes with a 90 day free trial. So you can give it a go for yourself.