Requirements:
  1. Raspberry Pi 2/3 with Windows 10 IoT Core Operating System connected to the internet.
  2. Laptop or PC with Windows 10 OS connected to the Internet.
  3. Visual Studio 2015 installed on your laptop or PC.
  4. Bread Board
  5. LED light
  6. Resistor
Follow the below steps:
Step 1:
Click File, then New Project like the following screenshot,
project
Name it Simple Led Blink.
Step 2: Right-click on the selection and add the reference,
add
Select Windows IoT Extension for the UWP and click OK.
Step 3: Open MainPage.xaml and add the following for UI,
  1. <Grid Background="Wheat">
  2. <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
  3. <Ellipse x:Name="LED" Fill="LightGray" Stroke="White" Width="100" Height="100" Margin="10"/>
  4. <TextBlock x:Name="DelayText" Text="500ms" Margin="10" TextAlignment="Center" FontSize="26.667" />
  5. <TextBlock x:Name="GpioStatus" Text="Waiting to initialize GPIO..." Margin="10,50,10,10" TextAlignment="Center" FontSize="26.667" />
  6. </StackPanel>
  7. </Grid>
Step 4: Open the MainPage.xaml.cs add the following in the cs file.
  1. private const int LED_PIN =5;
  2. private GpioPin pin;
  3. private GpioPinValue pinValue;
  4. private DispatcherTimer timer;
  5. private SolidColorBrush redBrush = new SolidColorBrush(Windows.UI.Colors.Red);
  6. private SolidColorBrush grayBrush = new SolidColorBrush(Windows.UI.Colors.LightGray);
  7. public MainPage()
  8. {
  9. InitializeComponent();
  10. timer = new DispatcherTimer();
  11. timer.Interval = TimeSpan.FromMilliseconds(500);
  12. timer.Tick += Timer_Tick;
  13. InitGPIO();
  14. if (pin != null)
  15. {
  16. timer.Start();
  17. }
  18. }
  19. private void InitGPIO()
  20. {
  21. var gpio = GpioController.GetDefault();
  22. // Show an error if there is no GPIO controller
  23. if (gpio == null)
  24. {
  25. pin = null;
  26. GpioStatus.Text = "There is no GPIO controller on this device.";
  27. return;
  28. }
  29. pin = gpio.OpenPin(LED_PIN);
  30. pinValue = GpioPinValue.High;
  31. pin.Write(pinValue);
  32. pin.SetDriveMode(GpioPinDriveMode.Output);
  33. GpioStatus.Text = "GPIO pin initialized correctly.";
  34. }
  35. private void Timer_Tick(object sender, object e)
  36. {
  37. if (pinValue == GpioPinValue.High)
  38. {
  39. pinValue = GpioPinValue.Low;
  40. pin.Write(pinValue);
  41. LED.Fill = redBrush;
  42. }
  43. else
  44. {
  45. pinValue = GpioPinValue.High;
  46. pin.Write(pinValue);
  47. LED.Fill = grayBrush;
  48. }
  49. }
  50. }
In the above code, we are using the GPIO(General-purpose input-output ports) for the interaction of the electronic circuit. We are using GPIO 5 over here,
circuit
Connect the following circuit,
circuit
Once the circuit is connected, build the solution.
Step 5: Now build the solution and select ARM and select Remote Machine,
remote
In the address, column enter the IP address of the network connected with Raspberry Pi device and click ok.
address
team
Step 6:
Now once Remote Machine is selected to build and run the application.
Once the application is built & run operation is completed successfully in the sense you will find the LED blinking according to the timer set.
Read more articles on Internet of Things: