In this article, we will setup Microsoft Visual Studio for cross-platform programming using Arduino board packages and libraries. If you would rather use the Eclipse IDE, check out our other article. The idea is the same: replacing the Arduino IDE with a more convenient and powerful IDE, while leveraging the simplicity and portability of the Arduino framework.
1/ Installing Microsoft Visual Studio
First of all, we need to install Microsoft Visual Studio 2017. The free ‘Community’ edition is all we need, and can be downloaded here.
2/ Installing the Visual Micro plugin
To generate code and upload it to our board, we will use a Visual Studio plugin called Visual Micro. It is an awesome tool, and although the free version lets you do everything we describe in this article, do not hesitate to buy the “Pro” version to keep its development going. To install it from Visual Studio, select “Extensions and Updates” from the “Tools” menu, then select “Online” tab from the side bar and search for “arduino”. Download the plugin called “Arduino IDE for Visual Studio”.
Once it is done, you must close the program so that it can be properly set up in the Visual Studio environment. A VSIX Installer window will pop up and ask you for permission to modify some files. You must allow this action in order to proceed. As soon as the modifications are completed, you should be left with a window telling you that the operations were successful.
Start Microsoft Visual studio and you should see a window asking you to specify the location of Arduino IDE on your computer.
You must ensure that the location of Arduino.exe is the correct one. You can leave the other forms blank. If you haven’t installed the Arduino IDE already, you can click on the “Download/Install Ide” button and it will send you to the official download page.
If the installation went correctly, a new menu called “vMicro” and a new toolbar should show up in Visual Studio.
In the “vMicro” menu, you can select “Visual Micro Explorer” (or click on the magnifying glass icon in the toolbar) to display a window which will allow you to manage libraries, boards, open examples, etc. You will find all the libraries and board packages that you have already installed, and you can install new board packages/libraries as well (see section 4).
3/ Uploading a sketch
The plugin is now fully installed and ready to be used, so we can try to upload a sketch on an Arduino board. There are two ways to create an Arduino sketch with Visual Studio :
First, you can create an empty new project by selecting “New” > “Arduino project” in the “File” menu. Enter a name for your project (we will name it “TTBlink”). The project will be visible on the “Solution Explorer” on the right side of Visual Studio. Open the .ino file (if it is not already) and you can start editing the file.
Otherwise, you can load an example from a library, into a new project. To do that, simply open the Visual Micro Explorer, then go to the “Examples” tab and click on the example you want to load. Choose “Open Copy” in the new window.
To upload a sketch on a board, you have to specify the board and the serial port you will be using. In the vMicro toolbar, make sure that your Arduino version is selected (in the first drop-down list). In the second drop-down list, you must select the board you want to use (Arduino/Genuino Zero (Native USB Port) in our case). You can then select the serial port that will be used to upload (you can check that in the device manager if needed).
In our case the toolbar looks like this :
And finally, you can upload the sketch by clicking on the “Build and upload” button (Play icon) and see the LED blink!
4/ Installing a board package or library from the Visual Micro Explorer
If you are missing a board package or a library that you need to use, you can install it from the Visual Micro Explorer. To do that, simply open the explorer from the menu (or by clicking on its icon). In our example, we will install the board package used for the feather 32u4. Select the correct tab (depending on if you want to install a board package or a library), search for the package (there is a search bar to help with that) and click on the version that you want to install. After the download is complete, you must click on the “Rescan” button located at the top. Similarly, you can uninstall a package that you no longer need by clicking on it.
If you want to install an external library, copy the folder in Arduino’s libraries directory which is commonly located at C:\Users\Username\Documents\Arduino\libraries and it should be detected in the Visual Micro plugin. Visual Micro has a lot more features, so check out the official website for a comprehensive guide.
5/ Next step
In our next article we will set up Visual Studio for GDB debugging.