IoT and Windows are Better than ever with the new IoT Core for Raspberry Pi.
In this workshop we’ll have deploy Universal Windows Platform Code to a Raspberry Pi and begin communicating with the cloud and cloud services in the form of an Azure IoT Hub.
The steps include:
1. Gathering the materials
2. Preparing the Raspberry Pi
3. Installing our software
4. Connecting our LED and PushButton
5. Connecting to our raspberry pi
6. Deploying our push button app
7. Connecting our app to IoT Hub
8. Connecting our app to weather data
1. Gathering the materials
For this workshop you’ll need about $55 worth of hardware, but all the software is free.
1 Raspberry Pi 3 (It has built in Wifi!)
1 Micro USB to USB Cable
4 Female/Male Jumper Wires
1 Push Button Switch
1 200 ohm resistor for said led
1 Monitor with HDMI out
Windows 10 Machine version 10.0.10240 or better.
Visual Studio 2015 Update 2
The Windows 10 IoT Core Dashboard
2. Preparing Our Pi
The windows developer site has very clear instructions for setting up your device with the proper operating system so lets hop over there.
If you follow these instructions all the way to Step 4 of 4 you’re ready for step 5 on our workshop. So skip ahead if you followed along there.
I’m working with a raspberry pi three so my selection screen looks like this:
3. Install the dashboard and Flash the OS
Next we’ll download the dashboard as prompted by the site
Then we’ll download the ISO of the raspberry pi image we want to use, then click through installer.
Once installed we can use the IoT Dashboard to flash the image onto our SD card in the form of a .ffu
Then we’ll connect the device to the network by selecting configure device.
Really though the instructions are super clear RIGHT HERE
4. Install/Update Visual Studio
We need Visual studio Update 2 to build our IoT Application, so make sure you’re up to date!
Or go here to install it: https://www.visualstudio.com/vs-2015-product-editions
Seriously though, they did an awesome job with the documentation.
If you followed along to their step 4 you’re ready for our step 5.
5. Connecting our LED and PushButton
Now that we have our pi configured and Visual Studio up to date, let’s plug in our neat hardware!
Here’s an overview of the pin layout for the raspberry pi 3:
And the wiring diagram for the led + push button looks like this:
Sweet, lets light it up!
6. Connecting to our raspberry pi
We need our raspberry pi’s IP address before we try to deploy our code.
Power it up with a micro USB cord and connect it to a monitor with HDMI and see the landing page for your machine.
With the Windows IOT Core Come a super helpful web portal that allows you to configure your machine through a browser.
Navigate to that IP:
https://192.168.1.145:8080/ is the IP address of my machine when I tried this
You’ll be prompted with a login panel.
The default user name is:
The default password is:
Here’s what you should see in the portal:
From here you can configure the name/password, get network info like the MAC address under Networking, and even test out some samples.
Sweet! This is one of my favorite Window IoT Features.
7. Deploying our push button app
The pi is setup, our computer is updated with the newest build tools, now its time to deploy some code!
Go here and clone this repo to a dev directory:
And setup visual studio debugging by right clicking on PushButton project like this:
Then under debug set the remote machine ip to the ip you collect from the IoT Dashboard or from the raspberry pi itself by plugging in a monitor.
You will then need to rebuild your solution, and restore nuget packages.
Poke around for a minute, put a break point in the buttonPin_ValueChanged method and step around to see what’s going on with the push button.
8. Connecting our app to IoT Hub
Next we’re going to turn on the IoT Hub Connection.
Go into the azure portal and create a new IoT Hub like this:
Then create a new device called MyDevice in the IoT Hub.
More information about the IoT Hub can be found RIGHT HERE.
Then we’ll want to add our connecting strings to the app at the very bottom of MainPage.xaml.cs
static string iotHubUri = "YOURHUB.azure-devices.net";
static string deviceKey = "TOKENasQOPUesD1BmSOMETHINGCOMPLICATED";
static string deviceId = "MyDevice"; // your device name
Next we’ll uncomment this line of code on line 78:
To see what’s happening in the event hub there is a small console application that we’ll run alongside to see what’s making into the cloud.
You can find that code here:
Open that in visual studio and replace the connection string with the one provided in the Azure Portal.
string connectionString = "HostName=YOURHUBNAME.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=YOURSECRETOKENqf"
Sweet, now run both those apps at the same time, push the button, and see the glory that is Internet of things.
9. Connecting our app to weather data
Now that we’ve got it talking to the cloud, lets listen to what the clouds have to say!
We’re going to use forecast.io to provide weather data to our app, then use Speech. Synthesis to read it out over a the audio jack.
Navigate to forecast.io and signup register an account, then copy the complicated token highlighted here:
And replace what you see at line 168:
private const string FORECAST_URL = "https://api.forecast.io/forecast/YOURSECRETOKEN/";
Then if you want to be more specific about where you’re getting weather data replace the string on line 76.
var words = await GetWeatherString("37.8267,-122.423")
Make sure that the code in lines 72 through 81 are uncommented.
Deploy the app, press the button, and listen to the weather like never before!
It’s all very simple code and ready to be spun into lots of fun projects.
Here’s a list of all the ones that me and my friends could thing of:
Tap into the band app cloud
Send a random act of kindness
Tap into yammer
Time to finish breast feeding start and stop button
Random stats button
Gives you weather, or distance walked
Morse code each other
Send bro to someone random – twilio
Launch a middle
Listener recognition and ignore
Competitive button clicking
Best reflexes tester
Hope you had fun getting started with Windows IoT!
This workshop wouldn’t be possible without the help provided by the community. Here are some of the helpful posts that help me learn:
Windows 10 IoT Core Speech Recognition
Windows 10 IoT Core Speech Synthesis
All The ms-iot samples
Feel free to ask me questions in the comments or on twitter @timmyreilly