Late in 2019, I got my hands on an Azure Sphere Starter Kit, which I’ve been intending to use for an IoT project, using some of the on-board sensors for temperature and potentially an external one for humidity…
For those who aren’t familiar with Azure Sphere, it’s Microsoft’s Secure Internet of Things (IoT) solution using certified chips, a custom operating system and a security service. My device is an Avnet Azure Sphere MT3620 Starter Kit and this blog post focuses on getting it up and running with one of the sample applications that Microsoft provides, using Windows 10 (other options include Linux).
Installing Visual Studio Code and the Azure Sphere SDK
Having obtained the kit, the next stop was Microsoft’s Getting Started with Azure Sphere page. I downloaded and installed Visual Studio Code (I don’t really need the whole Visual Studio 2019 application – though I later found that a lot of the advice on the Internet assumes that’s what you’re using…) and then immediately found that there are two versions of the Azure Sphere Software Development Kit (SDK). According to the Microsoft docs, either can be used with Visual Studio Code but I found the setup for the Azure Sphere SDK for Visual Studio failed when it can’t find Visual Studio (not really surprising) and so I used the Azure Sphere SDK for Windows.
Connecting the hardware
I plugged in the Avnet Azure Sphere Starter Kit, using the supplied USB cable, and watched as Windows installed drivers after which a virtual network interface was present and three COM ports appeared in Device Manager.
Setting up my dev environment
Installing Visual Studio Code and the Azure Sphere SDK was only the first part of getting ready to create code for the device. I needed to install the Azure Sphere extension (easily found in the Extensions Marketplace):
The Azure Sphere extension also installs two dependencies:
- CMake Tools
I also need to install CMake (in my case it was version 3.17.1). Not really knowing what I was doing, I followed the defaults but on reflection, I probably should have let CMake add its directory to the system %PATH% variable (I later uninstalled and reinstalled CMake to do this, but could just have added
C:\Program Files\CMake\bin to the Path in the user environment variables).
I missed the point in the Microsoft documentation that said I needed to manually add Ninja to the %PATH% environment variable but I later went back and added the folder that I copied
ninja.exe to (which, for me, was
(The above steps were my second attempt – the first time I installed MinGW-W64 to work around issues when Visual Studio Code couldn’t find a compiler, together with several changes in settings.json. I later removed all of that and managed to compile and deploy a sample application using just the settings above…)
Configuring the Azure Sphere device for use
There are a few steps required to configure the device for use. These are all completed using the Azure Sphere Developer Command Prompt, which was installed earlier, with the SDK.
Creating an Azure Sphere tenant and claiming the device
Each Azure Sphere device must be “claimed” and associated with a “tenant”. I followed the Microsoft documentation to do this…
azsphere login --newuser email@example.com
After completing Multi-Factor Authentication (MFA) and confirming I wanted to allow Azure Sphere to use my account, I was logged in but with a warning that I don’t have access to any Azure Sphere tenants, so I created one:
azsphere tenant create --name "Mark Wilson"
Warning – more research required: I used a Microsoft Account, as per the Microsoft instructions, but am now concerned I should have used an Azure Active Directory (Organisational/Work or School) account (especially as Role Based Access Control is supported from Azure Sphere 19.10 onwards). As a device can only be claimed once and, once claimed, the device is permanently associated with the Azure Sphere tenant, I’m stuck with these settings now…
I then went ahead and claimed the device:
azsphere device claim
Connecting to Wi-Fi and updating the device operating system
I checked the current OS version on the device:
azsphere device show-deployment-status
As can be seen, not only is the OS out of date, but the device is not connected to a network, so I connected to Wi-Fi:
azsphere device wifi show-status
azsphere device wifi add --ssid "SSID" --psk password
azsphere device wifi show-status
Now, with network connectivity in place, the device had a fighting chance of an OS update and according to the Microsoft documentation:
The Azure Sphere device checks for Azure Sphere OS and application updates each time it boots, when it initially connects to the internet, and at 24-hour intervals thereafter. If updates are available, download and installation could take as much as 15-20 minutes and might cause the device to restart.Configure networking and update the device OS
I tried several restarts using
azsphere device restart with no success. In the end, I left the device connected overnight and, by the morning, it had updated to 20.03.
Finally, I enabled application development on the device, ready to download some code and deploy an application:
azure sphere device enable-development
Downloading a sample app
I needed to use git to clone the Azure Sphere Samples Repo, so that meant installing git. Then, from the Terminal in Visual Studio Code, I ran
git clone https://github.com/Azure/azure-sphere-samples.git.
I then opened the
Samples\HelloWorld\HelloWorld_HighLevelApp folder in Visual Studio Code, ready to build and deploy the app.
Building and deploying the app
Having set up my dev environment, set up the device and downloaded some sample code, I followed the instructions in the Visual Studio Code Azure Sphere Extension to run the following in the Command Palette:
Azure Sphere: Configure Settings (selecting High-Level Application) and
I was then able to build and deploy the sample app to my Azure Sphere device, by starting a debug session (
and was rewarded with a blinking LED on the board!
I can also view the application status with
azsphere device app show-status.
The next step is to get the app I really wanted to use working on the device, making use of some of the on-board sensors and then integrating this with some of the Azure services. I’m having trouble compiling that code at the moment, so that blog post may be a while longer…