loading

In this Instructables, I will be showing you how to create your Arduino projects using Visual Studio IDE and how to deploy them with arduino_debug.exe console through command line.

The usage of Visual Studio as IDE for Arduino development is not a difficult goal to achieve, however you definitely need to now C++ or at least the basics and have a bit of patience.

I'm assuming you have Visual Studio IDE and Arduino Studio Portable (.zip file for non admin installation), if not, you can get them below:

Visual Studio IDE

Arduino Studio IDE Portable (.zip

You do not need to install the Arduino Studio IDE, you only have to unzip it somewhere suits you and in one of the last steps we'll use arduino_debug.exe through command line to deploy your code.

Difficult level: Medium

Step 1: Configuring .pde and .ino Extensions

Open Visual Studio, in my case I'm using Visual Studio 2015 Community (Free download), however any other version would work as same. Just make sure you have Visual C++ project installed otherwise you won't be able to see Visual C++ template projects on the New Project window. To install it, visit Visual C++ Download Page (Reboot may be necessary).

After making sure you have Visual C++ installed, let's configure both .pde and .ino extension.

On the top bar, click on Tools > Options to open the Options windows.

In the Options, go to Projects and Solutions > VC++ Project Settings. You will see a window like in the screenshot.

In the section Extensions To Include, add .pde and .ino at the end separating them using a semicolon ( ; ).

After doing it, click on OK to save your changes.

Step 2: Creating Your Project

Once the .pde and .ino configuration is done (Step 1), we will create our first project.

Following below steps, you will be able to create a Empty C++ project.

  • Click in File on the top bar
    1. Click on New;
    2. Click on Project.
  • In the New Project window
    1. Click in Other Languages;
    2. Click on Visual C++;
    3. Click on Empty Project.
  • Underneath the Template projects, you will see tree fields (Name, Location and Solution name).
    1. Click on Name to set a name for your project;
    2. Click on Location to set your project's source code location;
    3. Then click on OK to finish the project creation.
NOTE: All these steps are show in the screenshots.

Once we're done with this initial project creation, lets move to the funniest part.

Step 3: Configuring Your Project With VSPDE.h and VSPDE.cpp

To create your project using Visual Studio, we will need two files, both provided by Arduino and they works as stubs for the Arduino functions.

Arduino provide a plugin for Visual Studio named Visual Micro and it makes easy the whole configuration, they say that a manual configuration would be for advances users but I think even like that, it's very straight forward to anyone.

The two stubs I mentioned before are the VSPDE.h and VSPDE.cpp and they can be download clicking on the links added.

Once you've downloaded them, copy both files to you project folder than follow the steps below (and screenshot) to add it to the Visual C++ project:

  • Right click on your solution;
  • Click on Add;
  • Click on Existing file;
  • Find and select both .cpp and .h files;
  • Click on OK to finish.

Step 4: Creating Your .ino File With a Reference to VSPDE.h

Now we're going to create our first .ino file. fear not, a .ino file is nothing but a .cpp file, the only difference in here is the extension.

As the screenshots, follow the steps below to create your .ino file.

  • Right click on your solution;
  • Add;
  • New Item;

You will see the Add New Item window. There you will:

  • Click on C++ File (.cpp) as second screenshot;
  • In the Name input, you will rename your file with the same name as your solution but replacing .cpp with .ino;
  • Location is keept as it is;
  • Click on OK to complete its creation.

The final result is a new file into your project, as you can see through the Solution Explorer (Third Screenshot), this file will have the Arduino (.ino) icon.

Once you created the .ino file in your project, it's time to code our first program. For that we need to understand a bit more the Arduino's development anatomy.

All the Arduino boards comes preprogrammed with a bootloader, this "preprogrammed code" contains the VSPDE.cpp code, if you check the main() function of VSPDE.cpp, you will see that it calls inside its body some other functions, the two functions I consider most important are the setup() and loop(), the last one being the most important between both because whatever you code, will probably have to run continuously into the loop() function.

Here is a sample of main() code:

int main(int, char**)<br>{
	setup(); // You could use it to any initial configuration, like pins for example
	for (;;)
	{
		if (_kbhit())
		{
			Serial._append((char)_getch());
		}
		loop(); // Your code will run inside loop()
	}
}

Thing is, once you compile and deploy your code to the Arduino (will show it later), your code will be merged within the preprogrammed code in the Arduino, so your loop() or setup() functions will have an effect in the execution of the program. In other words, your code will be executed at runtime. You can understand more about Arduino Uno in here.

Anyways, let's get back to our .ino file, below you'll have a simple code which blinks the pin 13 of our Arduino Uno board.

In the VSPDE.h we will fine some C++ identifiers defined using #define preprocessor, also an abstraction of CSerial with some functions and fields and it is implemented by VSPDE.cpp.
You will find more comments in the code for a better understanding.

#include "VSPDE.h" // preprocessor used to include the vspde.h header file to you .ino file

#pragma region Variables

short pinLed = 13; // pin 13 is a led onboard of your Arduino, it will keep blinking in a second delay in amber color

#pragma endregion

#pragma region Base

void setup() { Init(); // Initial configuration method call }

void loop() { SetDigitalWriteOnLed(pinLed, 3000); // Method to set led 13 to HIGH and LOW (0x1 or 0x0) }

#pragma endregion

#pragma region Methods

// Initial Board Configuration void Init() { Serial.begin(115200);

// OUTPUTs pinMode(pinLed, OUTPUT); }

void SetDigitalWriteOnLed(short ledPinId, int interval) { digitalWrite(ledPinId, HIGH); // Set pin 13 to 0x1 Serial.println("LED ON"); // Debug purpose (I may explain it in another Instructables) delay(interval); // Delays 3000 milliseconds

digitalWrite(ledPinId, LOW); // Set pin 13 to 0x0 Serial.println("LED OFF"); // Debug purpose (I may explain it in another Instructables) delay(interval); // Delays 3000 milliseconds }

#pragma endregion

Just double checking your solution, it will have below structure:

  • ArduinoOn_VS_Test2 (Solution)
    • Debug (Folder)
    • obj (Folder)
    • ArduinoOn_VS_Test2.ino
    • VSPDE.h
    • VSPDE.cpp

I have above view because the option "Show all Files" on the Solution Explorer is selected, otherwise you will see something like below:

  • ArduinoOn_VS_Test2 (Solution)
    • References
    • External Dependencies (Virtual Folder)
    • Header Files (Virtual Folder)
      • VSPDE.h
    • Resource Files (Virtual Folder)
    • Source Files (Virtual Folder)
      • VSPDE.cpp
    • ArduinoOn_VS_Test2.ino

We are almost done here, let's make some small configuration in our solution in how it compiles our code then we're good to deploy it.

Step 5: Deploying Code to Your Arduino Board

Finally we arrived at the end of this Instructables, remember that I mentioned earlier, you would have to download the Arduino Studio IDE, you could either download the .zip file and avoid its installation or if you wish, download the .exe file and install it.

I will assume you downloaded the .zip file so you will have to unzip it somewhere in our drive, let's assume you unziped the .zip file to C:\ drive. Into the .zip file, you'll find a folder using this name convention

arduino-x.x.xx

In my case, my version is arduino-1.6.10, so once you extracted the .zip to C:\ drive, you will have a final path to Arduino folder as this: C:\arduino-1.6.10.

Inside this folder, you will find several sub-folders and one of the most important artifact, the arduino_debug.exe PE (portable executable) file.

Well, I mentioned in the previous step we would need to make a final configuration in our solution before deploy it, so lets to do it.

In our solution, right click on it and goes to Properties options in the navigation menu. The Property Pages windows will open as you can see in the first screenshot.

As you can see, in the left side, the option General, at Configuration Properties category will be selected. In the right hand side, make sure that the solution Configuration Type is marked as Makefile, if not, select Makefile and click on OK to save your changes. So, that was the last configuration!

Now it's time to deploy our code \o/

The deployment is simple, open Command-Prompt (cmd) and navigate to C:\arduino-1.6.10 folder.

cd \
cd C:\arduino-1.6.10

Once you are in the arduino folder, we will use arduino_debug.exe to compile and deploy our code. Type code below to deploy your .ino solution.

arduino_debug.exe C:\my-solution\folder-path\ArduinoOn_VS_Test2.ino --upload

The "C:\my-solution\folder-path" is your solution folders path in our C:\ drive, after it comes your .ino file name, then the argument --upload to upload your .ino.

It's basically the same command Arduino IDE would run when you press UPLOAD button.

As you can you see in the second screenshot, the code has been deployed. In my case, the project was in my E:\ drive ..\sub-folders\.. but it's basically just pointing the path to your .ino file and it will work.

Well, hopefully you guys enjoyed it. See yah next time!

<p>Nicely done, thanks for sharing!</p>
<p>thanks seamster!</p>

About This Instructable

561views

2favorites

More by AlexandreS34:Developing for Arduino with Visual Studio 
Add instructable to: