Microsoft VS Code is a programmer's development environment designed to run on all the major desktop operating systems. However, VS Code has also evolved into a cross-compilation environment. One can write and compile code on a Windows PC, Linux, or a Mac and then upload the code to a different hardware platform, such as a RISC-V device, to name just one.
Indeed, Platform IO is a set of VS Code extensions that eases code development for a wide range of processor chips and hardware development boards. Platform IO is growing in popularity among manufacturers of cutting-edge chips and development boards, not to mention among developers and engineers specializing in the Internet of Things (IoT).
As we shall see, some IoT development boards can use VS Code without requiring the full power of Platform IO. Often, we will be able to accomplish what we need with the more straightforward Arduino interface.
The Azure IoT Device Workbench
We will look at setting up VS Code for a subset of the broad IoT enterprise, in this case, developing IoT devices that will report data to and be managed by Microsoft Azure. A toolset that was once spread across many small VS Code extensions has now been integrated into a single extension called Azure IoT Tools. The point-and-click installation could not be easier.
We start the installation by clicking the extension icon in the left-edge menu. We then type "Azure IoT" into the filter box. The resulting list is extensive and includes offerings from third-party vendors. Azure IoT Tools is at the top of the list, and despite the length of the list, this one extension includes virtually everything we need.
You can see the long list of Azure IoT Device Workbench commands by opening the command palette through the View | Command Palette menu or simply clicking F1. You can, if you like, provision an Azure IoT hub from VS Code rather than use the Azure portal.
Installing The Arduino IDE
To develop code for, say, an Arduino Uno microcontroller requires compilers, code libraries, linkers, debuggers and a host of other utilities collectively known as the toolchain. Whenever we begin to work with a new hardware platform, the first task, and often a difficult one, is installing and configuring the appropriate toolchain. We will choose, for our example, the Microsoft AZ3166 microcontroller board since it is one of the easiest to work with if you are getting started with Azure IoT.
The simplicity of the Arduino Integrated Development Environment (IDE) led to great popularity for the Arduino microcontroller boards among electronic engineers and avid hobbyists. This popularity encouraged manufacturers of alternative microcontrollers to make their products accessible via the Arduino IDE as well. As a result, the Arduino IDE is no longer just for Arduino microcontrollers. The MS AZ3166 is an example of one such microcontroller. It has valuable sensors built-in; developers and engineers can have their IoT device up and running in an hour.
But how can we enjoy the simplicity of the Arduino development environment while also taking advantage of the professional power of VS Code? If you said "another VS Code extension," you've guessed it. We can install the Arduino IDE on our system without using it directly. The IDE installation will install the tools we need to compile and link a microcontroller program. Once we have installed the Arduino IDE, we can download the Arduino extension into VS Code. VS Code now becomes a development environment for any device programmed with the Arduino IDE.
The Arduino Extension for VS Code
In addition to the compilers and linkers, the Arduino IDE also provides utilities to install toolchains for various hardware development boards, above and beyond the traditional Arduino. After installing the VS Code Arduino extension, these same utilities are now accessible in VS Code. We will examine how the requisite AZ3166 tools are installed into VS Code using the Arduino extension.
Once we have installed the Arduino Extension, we are, in principle, ready to work with any development board that provides Arduino IDE support. However, some additional steps will need to be completed for any particular board.
Install the Necessary Drivers
You must identify and install the device drivers to manage the communication between VS Code and your development board via a USB port. The required drivers will depend on the development board you hope to work with and your operating system. If you wish to develop for the Microsoft AZ3166 board, download the STSW-LINK009 driver from ST.com.
As with the Arduino IDE, you must provide a URL in the Preferences | Settings that will tell other tools, like the Board Manager, where to find and download necessary tools. There is one crucial difference, however. The Arduino IDE maintains preference settings just for itself. On the other hand, VS Code must maintain settings for virtually any extension you wish to run.
We, therefore, must entire the Arduino preference settings as one set among potentially many in VS Code's settings.json file. This is accessed through the menu system File | Preferences | Settings. To open the settings.json file, we must click one more button, which is not immediately apparent.
We then paste the necessary information between the parentheses. If there is already settings information for other extensions, you must not break the JSON structure when you paste the text.
"arduino.path": "C:\\Program Files (x86)\\Arduino", "arduino.additionalUrls": "https://raw.githubusercontent.com/VSChina/azureiotdevkit_tools/master/package_azureboard_index.json"
The Arduino. Path specification will be different for Mac and Linux. In addition, it might be different on Windows if you did not install the Arduino IDE as administrator.
The Board Manager
Once the Arduino preferences have been set, we can load the information specific to our development board. Once again, the process is similar for any board, but we use the AZ3166 board as our example.
Clicking F1 or <ctrl><shift>P raises the VS Code command palette. Starting to type "Arduino" brings commands starting with "Arduino:" to the top of the list. We choose Arduino: Board Manager. Once the Board Manager window has appeared, we can start typing in the filter box. Typing "az" should be sufficient.
When we found the "MXChip - Microsoft Azure IoT Developer Kit by Microsoft Developer," we noted the latest version (2.0.0 as of this writing) and installed the AZ3166 developer board tools.
The tools are now set up, and the fun of developing an IoT device can begin!
Get connected with Cloud Networking courses so you can provide essential skills for ongoing business benefits.
This piece was originally posted on April 14, 2021, and has been refreshed with updated styling.