After using a GNUMake script based on work by Martin Atelier for building a couple of large Arduino programs, I decided to have a go at using MSBuild, the native tool for Microsoft Visual Studio 2012. Martin’s script has been fantastic, but GNUMake can be a little belligerent on Windows. So here is the first alpha version of a tool to use Visual Studio’s native build tool for creating Arduino programs.
If you want to give it a go, you will need:
- Microsoft Visual Studio 2012. You can use any of the professional version or Visual Studio Express 2012 for Windows Desktop (free). Microsoft is preparing a 2013 release, but we haven’t tested with that yet. You may need to download the 2012 version directly by now.
- The Arduino software. We use Visual Studio 2012 for editing and running the build process, but call on the same tools used by the Arduino software so programs are 100% compatible.
- MegunoLink Pro. You’ll install the build tool with MegunoLink Pro, and it is also handy for uploading the compiled programs to your Arduino
That’s it. Install all of the programs (if you don’t already have them). Then, to install the build-tool with MegunoLink Pro, click on the gear icon on the toolbar and select “Setup Arduino Build Tool for Visual Studio 2012”. Select the path to your Arduino software installation (the folder that contains Arduino.exe) then click “Install Latest Version”. The build tool currently doesn’t get updated automatically yet when a new version of MegunoLink Pro is installed, so you’ll need to do this each time.
When you hit the “Install Latest Version” button, MegunoLink Pro copies scripts to build Arduino programs into the Visual Studio build system (they go into the \MSBuild\Microsoft.Cpp\v4.0\V110\Platforms\BLSArduino\ folder; it doesn’t overwrite any Visual Studio tools). It also copies a project template into your templates folder. And that’s the next step.
Hello Arduino: building your first Arduino program with Visual Studio
New Arduino projects are created in much the same way as you’d create a C++ project in Visual Studio. Select File→New→Project, then select “Arduino Program” from the list of templates under “Visual C++”. You’ll get a new project with a single source file: Program.cpp. In it you’ll find the familiar Arduino setup() and loop() functions along with a classic greeting.
Select “Build Solution” from the Visual Studio “Build” menu to create a hex file, which you will find in the project’s bin\Debug folder. Upload the hex file to an Arduino Uno, and bask in the satisfying glow of a blinking LED.
Selecting the Arduino Target, and other project properties
By default, a new project targets the Uno; to create programs for other Arduino boards, edit the project properties. Select ” Properties…” from the bottom of the Visual Studio Project menu and expand the Configuration Properties→Arduino tree.
On the Compiler page, you can override the path to the Arduino software folder and select the Arduino version number. We’ve tested with 1.0.4 and 1.0.5 so far.
On the Device Settings page, you can select the Arduino board you have. We currently support the most common ones including the Mega, Nano, Mini and Pro Mini. If you are feeling adventurous (and knowledgeable on the Arduino build system) you can override the clock frequency, CPU and variant with the Custom device option.
On the Libraries page, you can select the libraries from the Arduino\libraries folder that you’d like to be built with your project. When you include a library header file in your project, you need to specify the library folder for Visual Studio’s intellisense to work correctly. So to include the Arduino EEPROM library, use:
Well, that’s the easy part done. Now you just have to write the Arduino program, launch a Kickstarter campaign and unleash your creation on the world. Have fun :-).
Please do post feedback in the comments below, or use our contact form. If you tell us about any problems you encounter, we’ll try to find solutions. If you find solutions to problems, please tell us about them too!
Q – What do I do when I get a w5100.h compile error?
A – Go to the project properties page, select the Arduino tab and remove “ethernet” from the libraries list. If you actually need the ethernet library please manually copy the .cpp and .h files in to your project.