mort8088 Just another WordPress site

Raspberry Pi – GPIO & C# (1/9) – Hello World

To start off with we'll create a simple "Hello World" program. This is termed a Headed application because it uses screen IO like a desktop application.

Create a new C# project

  1. Start Visual Studio 2015.
  2. Create a new project (File > New > Project...).NewProject
  3. In the New Project dialog, navigate to Universal as shown below (in the left pane in the dialog: Templates | Visual C# | Windows | Universal).NewProject-dlg
  4. Select the template Blank App (Windows Universal).

Add a reference to the Windows IoT extension SDK

The IoT extension SDK is not added to the projects by default, you’ll need to add a reference so that namespaces like Windows.Devices.Gpio will be available in the project. To do this,

  1. right-click on the References entry under the project.
  2. Select “Add Reference”AddReference
  3. Navigate the dialog to Universal Windows > Extensions > Windows IoT Extensions for the UWP and check the boxAddReference-dlg
  4. click OK.

Add content to MainPage.xaml

  1. From Solution Explorer, open the ‘MainPage.xaml’ file.
  2. Locate the <Grid> tag in the XAML section of the designer, and add the following markup.
    • MainPage.xaml:
  3. Double click on the Button in the design surface.
    Visual Studio will add a Click property to the Button XAML tag and generate the "ClickMe_Click" method in ‘MainPage.xaml.cs’.

    • MainPage.xaml:
  4. Add a the following code to this method.
    • MainPage.xaml.cs:

Build and test the app locally

Make sure the app builds correctly by pressing F6, This can take a long time on the first go. Since this is a Universal Windows Platform (UWP) application, you can test the app on your Visual Studio machine as well. Press F5 and the app will run on your PC. Close the app after you’re done validating it.RunningHelloWorld

Deploy the app to your Raspberry Pi

  1. Select ARM in the Visual Studio toolbar architecture dropdown.SelectARM
  2. In the Visual Studio toolbar, click on the Local Machine dropdown and select Remote Machine.SelectRemoteMachine
  3. Visual Studio will present the ‘Remote Connections’ dialog.
  4. Put the IP address or name of your Windows IoT Core device and select "Universal (Unencrypted Protocol)" for Authentication Mode. If however your Pi has been Auto Detected it will appear listed on this dialog click to select it.RemoteConnections-dlg
  5. Then click ‘Select’.
  6. You can verify and/or modify the values of the configured device by navigating to the project properties (select ‘Properties’ in the Solution Explorer) and choose the ‘Debug’ tab on the left.DebugCheck
  7. Press F5
    There will be a short delay and then your Hello World App will appear on the Screen use the mouse to click the button and watch the text change.HelloWorldRunningPi
  8. To stop the app, press on the ‘Stop Debugging’ button in Visual Studio.

Congratulations! You just deployed your first UWP application to a device running Windows IoT Core, Next Up we'll add some Hardware 😉

I know it doesn't seem like much to start with, but now you know how to get a new project up and running. Which is good for when you start making your own amazing inventions.

Raspberry Pi - GPIO & C# Tutorial Index

  • Introduction
  • 1 - Hello World
  • 2 - LED On & Off
  • 3 - LED Blink (Coming Soon)
  • 4 - Push Button (Coming Soon)
  • 5 - User Inputs (Coming Soon)
  • 6 - SOS Buzzer (Coming Soon)
  • 7 - Temperature Sensor (Coming Soon)
  • 8 - Light Dependent Resistor (Coming Soon)
  • 9 - Passive Infrared Sensor (Coming Soon)
All C# Code is available for Download Here

I am in no way affiliated with or sponsored by ModMyPi.com or RaspberryPiIVBeginners