Building Arduino Programs with Microsoft Visual Studio


Building Arudino programs with Visual Studio
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.

Installation

If you want to give it a go, you will need:

  1. 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.
  2. 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.
  3. 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.

Install the Visual Studio build tool for Arduino Programs

Install each of the pre-requisites, select the path to the Arduino software on your system and click “Install Latest Version” to setup the Arduino build tool for Visual Studio

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.

Creating an Arduino project with Visual Studio

Select New→Project from the Visual Studio PROJECT menu; choose “Arduino Program”

An Arduino project in Visual Studio

The main program lives in “Program.cpp”.

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.

Build output

The successful build output after selecting Build→Build Solution

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:

Arduino project properties in Visual Studio

Choose Properties from the bottom of the Project menu to configure the Arduino platform and libraries.

Last steps…

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!

FAQ

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.

Posted in Articles, Tutorials
6 comments on “Building Arduino Programs with Microsoft Visual Studio
  1. Dor says:

    I worked with VS.NET in the past to create .exe files with a simple interface. Using Meguno Link and Visual Studio 2012, is it possible to make a .exe file to control an Arduino?
    Thanks in advance,
    Dor

    • Phil Rowe says:

      Hi Dor, at this stage there is no way to create a separate exe file for your interface. We like the idea and it’s probably something we will pursue in the future.

      Cheers
      Phil

  2. Greg says:

    Guess this doesn’t work with Visual Studio 2013?

    • Phil Rowe says:

      Hi Greg, we have not had a chance to test it but usually they do not change much so it could work. Are you able to try it for us and report back?

      Cheers
      Phil

    • Greg Johnson says:

      The install is rejected immediately with Visual Studio 2012 is not installed. I run Visual Studio 2013 both at home and Work in my professional career of being a software engineer with over 30 years experience on the Windows Platform. Probably the installer has a limitation on the version of Visual Studio. Visual Micro installs into VS 2013 just fine. I have a personal project going with my son on a. Arduino, and seed like Meguno would be nice as the environment to develop in, but ran into this hiccup. Thanks for the response, let’s know if I can help. Greg Johnson

    • Phil Rowe says:

      Thanks for the info. I’ll let Paul (our main developer) know that it didn’t work. Hopefully it can be fixed without too much trouble.

      Cheers
      Phil

2 Pings/Trackbacks for "Building Arduino Programs with Microsoft Visual Studio"
  1. […] Building Arduino Programs with Microsoft Visual Studio […]

  2. […] Building Arduino Programs with Microsoft Visual Studio […]

Leave a Reply