Skip to main content

Cloud

IoT Development with Windows 10 and Raspberry Pi – Hello World!

This is my fourth blog post covering Windows 10 IoT Core.
Previous posts:
Part 1: https://blogs.perficient.com/microsoft/2016/01/windows-10-iot-editions-explained/
Part 2: https://blogs.perficient.com/microsoft/2016/01/iot-development-with-windows-10-and-raspberry-pi-what-you-need/
Part 3: https://blogs.perficient.com/microsoft/2016/01/iot-development-with-windows-10-and-raspberry-pi-setting-up/
So, you set up your development environment, assembled, connected and set up Raspberry Pi 2. Now you can create your first IoT application.
First, head to Visual Studio 2015 and create a project from “Blank App (Universal Windows)” (which is found under Window -> Universal). This selection would generate an application with UI (“headed” in Windows IoT terms) so make sure that your IoT board is plugged into display, keyboard and mouse (I plugged mine to 60″ TV!):
IMG_20160108_135816IMG_20160108_140009

There is also a way to create headless (i.e. w/o UI, server applications) in Visual Studio to run on IoT boards. That template is called “Background Application (IoT)” and it’s located under Windows -> Windows IoT Core. We’ll explore this template later.
2016-01-08
After you created the solution for your application, let’s head to MainPage.xaml and add some UI content. This is a Universal application and UI is defined in xaml file. Let’s add a button and a text field inside a grid:
<Grid Background=”{ThemeResource ApplicationPageBackgroundThemeBrush}”>
<StackPanel>
<TextBox x:Name=”txtHello” Margin=”50,50″ Text=”Whaaaat?”></TextBox>
<Button x:Name=”btnHello” Margin=”50″ Click=”btnHello_Click”>Say hello</Button>
</StackPanel>
</Grid>
And then go to MainPage.xaml.cs and add some code to button click even handler:
private void btnHello_Click(object sender, RoutedEventArgs e)
{
txtHello.Text = “Hello!”;
}
This is it. Your “hello world” application is done. And because it’s a Windows Universal application, it would run anywhere, including your development machine. Just press F5 and application would start up.
Try clicking the button and see the result.
2016-01-08 (4)
Now let’s get this app running on Raspberry! In order to do that, go to project properties, Debug tab and make some changes there:

  • Change platform from “x86” to “ARM”
  • Change target device to “Remote Machine”
  • Enter remote machine name (in my case that would be “winpie”)
  • Set authentication mode to “Universal (Unencrypted protocol)”.
Then press F5 and after some time (could be a few minutes for first time deployment) you should see your application running on Raspberry Pi display!
Click on the button on the screen and see a text change.
IMG_20160108_145342IMG_20160108_145352
In my next blog post we’ll be creating something more useful than Hello World sort of application… Stay tuned.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Stan Tarnovskiy

Solutions Architect at Perficient

More from this Author

Follow Us
TwitterLinkedinFacebookYoutubeInstagram