Visual Studio Guide
I prefer to use the Visual Studio environment to write and test code for the Arduino. For most users, the Visual Studio Plugin might be the easiest solution. However, for advanced users the following steps outline what is necessary to accomplish this.
Note that this requires two files to be added that are stub’s for the normal Arduino functions. The stubs provided here use defines for the Arduino Mega and create a simple console application that will map console input/output to the Arduino serial input/output.
For those of you who have more time at hand, it would be nice to write a windows stub which will also allow to see / control the I/O pins.
If you need support for other boards you need to edit the VSPDE.h file.
Also the VSPDE.cpp file does not implement all the Arduino functions, so if you need more, please feel free to update the code.
Main objective for me was to be able to edit and compile, and in a limited way run and debug code using Visual Studio. This will do just that (and nothing more)!
Step 1: Ensure .pde files are seen as C++ files
Open regedit and under \HKEY_CLASSES_ROOT create a new key called “.pde” and change the default value to “cppfile”.
Repeat this step for ".ino" extension.
Step 2: Configure Visual Studio
Versions of Visual Studio other than Visual C++ 2010 Express:
- Under tools \ options \ Projects and Solutions\VC++ Project settings add ‘*.pde’ to ‘C/C++ File Extensions’ and ‘.pde’ to the ‘Extensions to Include’
- Also register the ".ino" extension while in here
- Under tools\options\Text Editor\File Extension add PDE and map it to the C++ editor
- Close Visual Studio to effect the changes
Visual C++ 2010 Express:
- (As above.) Open Visual C++ 2010 Express and go to the options in Tools\Options\Text Editor\File Extension - add pde and map it to the C++ editor. Do the same for ino.
- (As above.) In the Options dialog, go to Projects and Solutions\VC++ Project settings, and add .pde and .ino to ‘Extensions to Include’.
- (As above). Close Visual C++ 2010 Express.
- There is no longer a ‘C/C++ File Extensions’ section in Tools \ Options. To modify these mappings, you must add two files to the folder ‘C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Platforms\Win32’ (create this folder if it isn't there already).
- Put the following into a file called ‘new-c++-file-extensions.xml’:
<?xml version="1.0" encoding="utf-8"?>
<FileExtension Name=".pde" ContentType="CppCode"/>
<FileExtension Name=".ino" ContentType="CppCode"/>
- Put the following into a file called ‘new-c++-file-extensions.targets’:
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyPageSchema Include="$(MSBuildThisFileDirectory)new-c++-file-extensions.xml" />
- In addition, you will need to add these two files to every other folder in ‘C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Platforms’.
- This change is detailed in the article: http://msdn.microsoft.com/en-us/library/3e889s84.aspx in the section THE BETTER WAY TO THE SAME THING: CUSTOM .TARGETS AND .XML FILES near the bottom of that page. Important note: that article gives the wrong folders for the files, the correct ones are the ones given here.
Step 3: Create a Visual Studio project
- Start by creating a new (empty) sketch using the Arduino editor
- Next create a Visual C++ ‘Empty Project’ for the sketch in the same folder
- In the solution, right click and select Add, Existing item to add the .PDE file(s)
- Select the .PDE files, right click and in the file properties set the file type to ‘C/C++ Code’
- Add the VSPDE.h and VSPDE.cpp files
- In Studio 2010, make sure the VSPDE.cpp/.h are saved as US-ASCII and not UTF-8 or Unicode. Otherwise Arduino 1.0 will fail compilation due to the BOM marker. IN VC++ 2010 Express, this is done as follows. Open the file, then Save As. In the Save As dialog, click on the down-arrow on the right of Save and select Save With Encoding, agree that you want to overwrite the file, and select ‘US-ASCII - Codepage 20127’ for the encoding.
- Add an #include statement for the VSPDE.h file in the .pde files.
- You can now edit, compile and run the program as a console application (without I/O support!)
Step 4: Configure Arduino
Under File\Preferences set the ‘Use external editor’ checkmark.
Now you can use Visual studio to edit and when done just Alt-Tab to the Arduino application and press the upload button to compile the latest code and upload it to the board. The Arduino program will automatically monitor for file changes so you do not need to refresh anything!