Sunday, October 23, 2016

Deploy UWP Windows app into Raspberry Pi 2 device running Windows 10 IoT Core

In a previous post, I discussed building a Windows 10 UWP app that uses EF Core and SQLite. In this post I will show you how to deploy the same application to the Raspberry Pi 2 device running Windows 10 IoT Core. These are the pre-requisites you need to fulfill before continuing with this tutorial:
  • Needless to say, you need to own a Raspberry PI, version 2 or 3, device
  • Your development computer needs to be running the Windows 10 operating system
  • Install Visual Studio 2015. The community edition is more than adequate.
  • A monitor is needed with HDMI input in order to view the UI on the Raspberry Pi device.
  • An Ethernet cable is necessary to connect your development computer to the Raspberry Pi device
  • An HDMI cable to connect the Raspberry Pi device to your monitor.
  • One microSD card that will contain the Windows 10 IoT Core operating system on the Raspberry PI. microSD cards need to be at least 8 GB in size. Slower and older cards are inconsistent when flashing and may fail to work. Class 4 SD cards are not supported and at a minimum Class 10 SD cards should be used.
    View the list of recommended cards.
  • A mouse with a USB connector
  • A keyboard with a USB connector

Installing Windows 10 IoT on your Raspberry Pi device

Once you have all the above in place we are ready to go. The first step is to install Windows 10 IoT Core on the microSD Card.

1) Insert the microSD card into the adapter on your computer.

2) Go to https://developer.microsoft.com/en-us/windows/iot

3) Click on the “Get started now” button.

image

4) Click on the device you have. In my case, I clicked on “Raspberry Pi 2”.

image

5) In step 2, click on “Install onto my blank microSD card”.

image

6) In step 3 click on “Windows 10 IoT Core”.

image

7) Click on Next.

image

8) Since you already have Windows 10 installed on your computer, on the “Get the tools” page, skip straight to step 2 then click on “Download Dashboard”. This will download a setup.exe file onto your computer . Run the setup.exe application to install an application named “Windows 10 IoT dashboard” on your connected microSD card.

image

9) Insert the microSD card into the adapter that is attached to your computer.

10) Start the “Windows 10 IoT dashboard” application on your computer.

image

11) Connect the mouse and keyboard to the Raspberry Pi.

12) Click "Set up a new device".

13) Select “Raspberry Pi” from the dropdown.

14) Enter device name, password and Wi-Fi network to connect to.

15) Download and install Windows 10 IoT Core onto your microSD card.

16) Power OFF your Raspberry Pi device.

17) Remove the microSD  card that is attached to your computer and insert it into the Raspberry Pi device.

18) Connect an HDMI cable between your Raspberry Pi device and monitor.

19) Connect an Ethernet network cable between the Raspberry Pi and your computer.

20) Power ON your Raspberry Pi device. You should see the Windows 10 operating system start screen on the Raspberry Pi device.

image

21) Back in the “Windows 10 IoT dashboard” application on your desktop computer, click on “My Devices”. Your device should get detected and you should see the name, model, and IP address:

image

22) To see that your Raspberry Pi device is indeed connected with your computer, click on your device.

image

23) On your device’s page, click on “Open Windows Device Portal in browser”. You may be asked to enter the administrator password that you previously entered.

image

Feel free to navigate around using the various links to get familiar with what is on your Raspberry Pi Windows 10 IoT device.

Deploy UWP .NET Core app onto your Raspberry Pi device

If you have done my building a Windows 10 UWP app that uses EF Core and SQLite tutorial, then you can deploy that application to your Raspberry Pi. Otherwise, you can create a UWP application from scratch and deploy that instead. For the purpose of this exercise, we will go ahead and create a brand new vanilla UWP app.
  • File >> New >> Project
  • Templates >> Visual C# >> Windows >> Universal
  • Choose the “Blank App (Universal Windows)” template
  • Give the application name IoTDemo then click OK
image
  • Choose minimum version to be same as target version then click OK.
  • Edit MainPage.xaml and add the following code between the opening and closing <Grid> tags:
<TextBlock Text="Hello UWP on Windows 10 IoT core" Margin="200,200,0,0"/>
  • Compile the application then hit Ctrl + F5 to run it on your local machine. You will see the following window appear on your screen:
image
  • Close the above window by clicking on the X in the top-right corner.
  • Choose the ARM processor in Visual Studio
image
  • Select “Remote Machine” for target device.
image
  • The following dialog will appear:
image
  • Go back into the “Windows 10 IoT dashboard” application on your desktop.
  • Click on “My devices” on the left side. Right-click on your Raspberry Pi device and select “Copy IP address”.
image
  • Paste the IP address in the Address field on the Visual Studio “Remote Connections” dialog.
  • For “Authentication Mode” leave it as “Universal (Unencrypted Protocol).
  • Click on the Select button.
  • Click on “Remote Machine” to deploy and run the application on the Raspberry Pi device.
image
  • You may see a warning message like the one below. If you do see such a message and the deployment does not error out, then you are good.
image
  • If all goes well, you should see the UWP app running on your Raspberry PI device:
20161023_180941
20161023_182117

The fact that you can put modern apps on a small and inexpensive networked device like the Raspberry PI opens up a lot of opportunities. I sincerely hope this demo makes you come up with some bright ideas that translate into production ready apps.

No comments:

Post a Comment