How to add an Arduino library using Visual Studio

by Visual Micro 27. October 2011 05:46
January 2015 - New documentation that explains how to add an Arduino library to a sketch can be found here
June 2015 - The Micro Explorer can be also be used to install libraries using the Library Manager and also to insert libraries into the current open project

Add an arduino Library using the project menu
The 2nd entry on the Project menu allows libraries to be added
 
When adding libraries the #includes are automatically added to the master .pde source.
You must click "Save" before the intellisense will detect the new libraries.
 
Optionally toggle the library sources in/out of the visual studio project using "Project>Show all Arduino files".
Including the actual library sources codes does not break the compiler but allows the libraries to be explored using the Visual Studio object browser

How to configure Arduino syntax "color coding" in Visual Studio

by Visual Micro 9. October 2011 06:41

these instructions are not required for Atmel Studio versions, Atmel syntax color configuration is automatic during install of visual micro. If you are using Atmel Studio and color syntax or intellisense is not working then run the install again, click uninstall then click install again

1. Open the Visual Studio Tools>Options

2. Navigate to Text Editor>File Extensions

3. Add the INO and PDE extensions setting the Editor to "Microsoft Visual C++" for each

4. Click OK and re-open any open sketch code files

This is what you should see once you have made the changes

 

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

Arduino Visual Studio Examples and Images

by Visual Micro 5. October 2011 14:42

The Visual Studio>Tools>Serial Ports menu will automatically enable and disable when arduino boards or xbees are 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

 

The Visual Studio "project" menu contains a number of arduino commands related to the active project, some of which are shown below

 "Show all arduino files" is for advanced users who would like the arduino core and "selected libraries" source codes included in the Visual Studio solution

The Visual Studio Project menu contains a number of Arduino commands related to the active Project

 Visual Studio has serial tool windows for arduino or any other project

 Visual Studio has serial tool windows for arduino or any other project

Arduino for Visual Studio Basic Setup

by Visual Micro 4. October 2011 06:29

April 2014: Please see our new documentation for a better install and first time user guide

existing user? recent fixes and additions

After installing Visual Micro you will be prompted to enter the location of an Ide, such as the Arduino 1.5.x Ide. This is all there is to setting up Visual Micro.

The Ide location(s) can be re-configured at anytime by clicking "tools>options>visual micro" or by clicking "<Configuration Manager>" in the tool bar applications list. Ide re-start is not required when changing these locations. 

There is also a large number of optional configuration properties described in the wiki.

First Time User Guide

  • Install the arduino software from arduino.cc
  • Close all Ide's!!
  • Install the Visual Micro software
  • Run the Visual or Atmel Studio ide, you will be prompted to enter the location of the arduino ide
  • tip: in the arduino location prompt there is a link to download Arduino if it is not already installed
  • Register .ino (and .pde) files for color coding by following this article (not required for Atmel Studio versions)
  • Got a problem with the install? Please join the forum we want to help. Thanks

How to set the Arduino ide location

With so many Arduino Ide variations it makes more sense to allow for multiple Ide apps to be support in a single Visual Studio or Atmel Studio instance. The "Application Manager" provides a simple tool to specify the locations of the various Arduino Ide's that are installed on your computer.

tip: The 1.0.x application can also be used for arduino versions older than 1.0

One way to set ide application locations is by using the "Application Ide Locations" property under "tools>options>visual micro" shown below

How to configure the arduino (or other) ide location

Another options is to use the <Configuration Manager> accessed via the Applications toolbar list 

How to configure the arduino (or other) ide location via the toolbar

The remainer of this document explains a few basics and how to test your install, create or open and then compile and upload...

When testing a new installation of the Arduino IDE for Visual Studio, to avoid confusion, the Arduino/Sketch commands (such as file>new>sketch project) should be used in preference to standard visual studio commands.

If you are new to both Arduino and to Visual Studio then you MUST use the Arduino commands because you won't know the Arduino rules. You will see that the Arduino commands have an Arduino icon next to them.

The following are a few ways to test your Arduino for Visual Studio installation (similar to getting started guide)

Method A - Create new arduino sketch (automatic mode)
 
Open visual studio. From the "File>New" menu select "Arduino project". When prompted, enter the name of a new arduino sketch such as "MyFirstSketch". Click OK
 
You should see a new arduino project is created containing an arduino sketch called MyFirstSketch.pde
 
Add your own arduino code to the void loop() {}
 
Select an arduino board from the list and click "Build Solution" from the "Project" menu


You should see a successful arduino compile in the "Sketch Build" output window


Tip: The same functionality is available from the Visual Studio "Standard" tool bar and also the "Solution Explorer" context menu


Method B - Open an existing sketch (automatic mode)

In visual studio select "File>Open" then click "Arduino Project". You will be presented with an "Open File" window which will display your arduino sketch folder. Select a sketch and click OK.

A project will be automatically created for the sketch and the arduino source codes automatically added to the project.

Add your own arduino code to the void loop() {}

Select an arduino board from the drop down list of boards and click "Build" solution from the "Project" menu

You should see a successful arduino compile in the "Sketch Build" output window

Method C - Open an existing sketch (semi automatic mode)

In Visual studio selected "File>Open>File". Navigate to an arduino sketch folder and select a .pde file. Click OK

You will be asked if you would like to Open or Create a project for the arduino sketch. Click OK.

Add your own arduino code to the void loop() {}

Select an arduino board from the drop down list of boards and click "Build" solution from the "Project" menu

You should see a successful arduino compile in the "Sketch Build" output window

Method D - Creation of a new arduino project (manual mode)

In Visual Studio create a new empty C++ project called "MySketch3" in a folder called "MySketch3"

Add a new text file to the project and call it "MySketch3.pde"

Add your own arduino code to the void loop() {}

Select an arduino board from the boards list

Select an arduino board from the drop down list of boards and click "Build" solution from the "Project" menu

You should see a successful arduino compile in the "Sketch Build" output window


This product is not "associated to" or "endorsed by" Arduino. The design of the sketch compiler and uploader is directly based on the arduino source code

Compilation errors after removing an Arduino file from a Visual Studio project

by Visual Micro 3. October 2011 13:32

Removing a file from a Visual Studio project does not remove the file from the Arduino sketch. You have to follow the Arduino rules when working with Arduino projects in Visual Studio.

The Visual Studio Arduino compiler entirely mimics the Arduino development system which doesn't know about Visual Studio projects. The Arduino system uses all of the source code files in a folder.

So you must move or delete your unwanted Arduino source files.

Note

After removing files from a Visual Studio Arduino project, if you close and re-open the project, you will notice that the files you removed re-appear. This is because the Arduino for Visual Studio application validates Arduino projects when they are opened (applying the Arduino rules). The intention is to ensure compatibility with the Arduino development tool allowing you optionally compile sketches in either product.

Arduino Code Object and Class Browser

by Visual Micro 2. May 2010 14:17

The visual studio object browser simplifies browsing of arduino/wiring libraries, custom libraries and your own code.

 

Navigating the Navigator. ArduPilot in Visual Studio 2010

by Visual Micro 2. May 2010 13:31

Editing any of the ardupilot versions using visual studio 2010 really shows off the quality of the ardupilot code. I love people who comment their code. Very neat!

And look how easy arduino project "navigation" is in Visual Studio, you can "Go To" the right place in the code.

I didn't know where the stabilize() function was but visual studio "Go To Definition" took me right to the attitude.pde. The intellisense in visual studio works best with well stuctured programs such as ArduPilot!

You need Visual Micro to make this work easily in 2010. It is free and quite new so the help system is a little confusing. Feel free to grab a copy.

The ardupilot code can't yet be compiled in visual studio due to the complex interaction between the multiple .pde files. However, Visual Micro adds a menu item to visual studio called "Open project in Arduino".which allows you to easily jump into the Arduino IDE to compile your mods. The next release of Visual Micro will allow compile and upload from within visual studio

How to select an arduino serial port

by Visual Micro 11. April 2010 14:20

The serial monitor is not included in the initial version of visual micro. Therefore the serial port need only be selected to upload to an arduino board using visual studio. An arduino serial port is select using the tool bar drop down menu as show below. When the project is next opened the addin will reselect the same port.

The serial ports menu is dynamic, the menu will detect changes to the connected serial port list of the computer (even whilst the menu is dropped down). The list is in order of device connection. These features are especially useful for device identification when working with multiple boards and ports

Example 1 from older software version

 

Example 2

 

Uploading will invalidate your arduino warranty, we accept no liablity should any problem arise from using this tool to upload to arduino

 

 

Using the arduino boards menu in visual studio

by Visual Micro 11. April 2010 13:59

The visual studio tool bar provides a way to select which arduino circuit board each project will use

When a board is selected, all of the items in the "_core" filter are removed and replaced by the files from the newly selected boards arduino core

If the _core filter does not exist then it is created. In the example below, the board is about to switch from "atmega168" to "arduino mega"

In the current visual micro version the include and source files are automatically separated into "inc" and "src" filters (see below)

 

 

"One Click" add new source and header file(s)

by Visual Micro 11. April 2010 13:57

In the lestest product version the following functionality has been moved to the standard visual studio menus such as File>New or right mouse click project "New"

The "New" menu contains two very useful options enabling new files to be quickly added to an arduino visual studio project . This is a useful features if you often need to add a new .c and .h files to your projects.

note: To add files to your arduino projects in visual studio you can always use the standard visual studio "add file" or "add existing file" options.

Workflow Objective

Create a new .c file named MySubFile.c to the project (if it does not already exist) folder and link it to the project "Source Files" filter

Create a new .h file named MySubFile.h to the project folder (if it does not already exist) and link it to the project "Header Files" filter

Insert an #Include for MySubFile.h to the currently active source file (or .pde)

Open the new files for editing

How To

1. Choose to add .c/.h or .cpp/.h

2. Provide a name for the new files

3. Visual Micro does the rest!

Build an arduino avr-gcc program using visual studio (advanced)

by Visual Micro 11. April 2010 12:00

2011 new release upgrades this functionality providing 100% compatible arduino compile at the click of a button. An arduino boards list makes switching boards very easy

The initial release of the visual micro addin for visual studio is designed for arduino however it should be possible to use the system to program normal avr devices using visual studio. This is entirely untested but at the very leat this software will provide all the information and tools you need to adapt an avr solution.

Ignoring the arduino boards and library system you will find everything you need to adapt your own Visual Studio avr solution. AVR Intellisense, compilation, upload and much more

Automate arduino development using visual studio

by Visual Micro 11. April 2010 08:16

You may add any of the visual micro arduino commands to the visual studio tool bars and menus. You may also reference the commands in your visual studio macros. Serial ports, libraries, boards are also available as commands.

Example

The "Arduino Mega" will appear as a visual studio command (Tools, Customise), COM23 (if it exists) will also appear as a command, the SoftwareSerial library will also appear as a command.

Therefore you could add there new tool bar buttons for each providing a "one click" option to select options you use regularly. or you can create a workflow (macro) that automatically selects the "mega" board, sets COM23 and includes the software serial library into the current project.

Example: Customise Visual Studio Arduino Commands

 

Unsupported Upload Note

The compiler outputs .hex files into the <project>\_vsaddin\_build folder. The addin projects can be run from the visual studio command line. This makes it possible to design windows applications using visual stuidio that upload different arduino sketches based upon conditional factors. If you use the arduino visual studio compiler or the arduino uploader then please beaware that no liability is accepted by us and that you will break your arduino warranty

Enable arduino Intellisense in visual studio

by Visual Micro 11. April 2010 07:40

2015 - This document is for VS2008 and is obsolete

2nd may please see archive for visual studio 2010 intellisense ardupilot overview

 

The visual micro addin provides intellisense using visual studio for all arduino core, library and your own project files

If you add or link your own files to a visual micro project and the intellisense doesn't detect them. Just click compile on the tool bar (or rebuild the vs project)

Click CTRL+J in your code to see a master list of properties. See example...

When switching board, when adding an arduino library or when you add or link multiple existing files to a project you will see the background progress for the intellisense update

If your arduino intellisense stops working (somestimes happens with visual studio) then shutdown visual studio and delete the .ncb file of the project (it's in the projects folder). Important - Only delete the .ncb!

 

Add an arduino code library to a project

by Visual Micro 10. April 2010 16:56

Add (Include) an arduino Library using the project menu

 
The 2nd entry on the Project menu allows libraries to be added
 
When adding libraries the #includes are automatically added to the master .pde source.
You must click "Save" before the intellisense will detect the new libraries.
 
Optionally toggle the library sources in/out of the visual studio project using "Project>Show all Arduino files".
Including the actual library sources codes does not break the compiler but allows the libraries to be explored using the Visual Studio object browser