[Arduino] Edit and compile with Visual Studio

I prefer to use the Visual Studio 2008 environment to write and test code for the Arduino. 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”.


Step 2: Configure Visual Studio

  1. Under tools \ options \ Projects and Solutions\VC++ Project settings add ‘*.pde’ to ‘C/C++ File Extensions’ and ‘.pde’ to the ‘Extensions to Include’
  2. Under tools\options\Text Editor\File Extension add PDE and map it to the C++ editor
  3. Close Visual Studio to effect the changes

Step 3: Create a Visual Studio project

  1. Start by creating a new (empty) sketch using the Arduino editor
  2. Next create a Visual C++ ‘Empty Project’ for the sketch in the same folder
  3. In the solution, right click and select Add, Existing item to add the .PDE file(s)
  4. Select the .PDE files, right click and in the file properties set the file type to ‘C/C++ Code’
  5. Add the VSPDE.h and VSPDE.cpp files
  6. Add an #include statement for the VSPDE.h file in the .pde files.
  7. 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!

Rif: www.arduino.cc


Alberto Pasca

Software engineer @ Pirelli & C. S.p.A. with a strong passion for mobile  development, security, and connected things.