Arduino - Learning by Example using Visual Studio and APM

by Visual Micro 24. August 2012 13:02

Selecting an Arduino development tool that provides code assistance is a big help for new arduino users and also to users who are new to a particular arduino program. Features that can be very useful are:- help, examples, code completion, error correction and intellisense.

Help and Examples

Arduino provides a number of examples to help us understand the basics of micro-controller development. Many arduino libraries, created by the community, are also provided with examples.

The "File" menu in the Arduino IDE provides access to all of these examples. In the Arduino IDE we click an example to open it as a new sketch project. In the Arduino IDE, that editing and saving the example will be replaced with modified code. In Visual Studio we get to choose if we would like to create a copy of an example or use the original. We also get a few others options described later on in this page.

Examples are a useful facility and are often overlooked by new users. Examples help us understand the core components of any arduino project. By understanding the core components such as sensors and servos we are able to then create or understand larger Arduino programs.

A good "example" being the ArduPilotMega (APM) drone project. This project has resulted in a few massive but highly crafted arduino programs such as ArduPilot and ArduCopter. The APM hardware involves sensors such as 3 axis:- giro, accelerometer, compass and a gps. The hardware can also drive servos or electronic speed controllers (esc) for rc cars, planes, copters and boards. The heart of the APM circuit board is a standard Arduino micro-processor with some additional sensors ++.

Micro explorer showing apm examples and error correction

At this point I should add that there are other drone projects that use a variety of other arduino based solutions, I am not recomending which is the best I am simply using APM as an example. A reason for using APM as an example is that the project is so incredibly well written, it is an enourmous project that has been re-worked almost to perfection (from an arduino programming point of view!). The code is well formatted, the program is very flexible and can optionally include a large number of different types of sensors (and options). 

A great benfit for new APM users are the examples provided by the community. Every variation of every sensor supported by programs written for APM is available as an example. This makes it possible to write small simple experimental programs or use the examples as they are. These small programs are a great wayt to understand how each sensor, servo, motor, esc, etc. works.

The Visual Studio Arduino plugin provides the micro explorer tool  (shown above) includes these examples but also other reference and tutorials.  The explorer allows arduino examples to be opened, new arduino projects to created from examples and/or to simply open individual example sources for inspection (or copy/paste).

The explorer provides the same refererence examples that are available in the arduino ide with the addition of advanced references for the AVR microcontroller and gcc compiler. The latter being useful for more advanced users. A custom google search facility fixed to, arduino wiki, arduino forum and provides a "www search" without leaving the Visual Studio development tool.

Arduino Code Completion and Intellisense

In the picture below you can see the micro explorer tool providing a drill down into the APM/Arduino example sources. The image also includes source code with an inteltional error to demonstrate Arduino code completion and error correction in Visual Studio.

Pressing the '.' (full stop) automatically displays a list of available members of the object called g in the ArduPilot project. Pressing F12 will goto the definition of an item. SHIFT+F12 will find all references to the currently selected code. All these functions and more are on right click menus and the menus at the top of visual studio.

How to explorer an arduino project using Visual Studio intellisense


For Arduino development, if you do not have a copy of Microsoft Visual Studio then grab a copy of Atmel Studio which is based on Visual Studio 2010 and is free

The Visual Micro plugin for Visual Studio can be downloaded for free from


Arduino Visual Studio User Interface Images

by Visual Micro 7. October 2011 15:25

The Visual Studio Tools menu will automatically enable and disable when an arduino board or xbee is connected. We can override arduino programmer settings from within visual studio

Arduino Visual Studio Tools Menu

The Visual Studio "Tools" menu example below is taken from a machine that did not have a connected serial port.

Various arduino command are added to visual studio in all relevent positions such as the Standard Tool Bar shown below

Arduino Visual Studio Create New Arduino Project Using the Visual Studio Standard Tool Bar

The Visual Studio Tools menu allows an arduino board to be selected for a visual studio project as does the boards list on the tool bar

Arduino intellisense in Visual Studio is fully available and automatically built from any arduino sketch

Arduino Visual Studio Intellisense for the Selected Arduino Board

Multiple sketch projects in a single solution are fully supported. F5 will compile and upload the Visual Studio "Start Up" project. Board and Serial port can be selected for each sketch project.

Arduino Visual Studio Multiple Sketch Projects in a Single Visual Studio Solution

Ultra fast intelligent visual studio arduino compiler

Arduino visual studio ultra fast arduino compiler


Unlimited serial viewers in Visual Studio auto pause and re-start during upload to an arduino board. All arduino and user conditional compiler directives are fully visible as you code

Unlimited serial viewers in Visual Studio auto pause and re-start during upload to an arduino board. All arduino and user conditional compiler directives are fully visible as you code