Table of contents
Raspberry Pi Windows IoT Development (Part 1)
Raspberry Pi Windows IoT Development (Part 2) USB Camera
Raspberry Pi Windows IoT Development (Part 3) Flashing LED
Raspberry Pi Windows IoT Development (IV) UART Interface
Raspberry Pi Windows IoT Development (V) SPI Interface
Raspberry Pi Windows IoT Development (Part 3) Flashing LED
First of all, you need to prepare the following materials:
A Raspberry Pi development board 3B, as well as power supply, network cable, monitor, mouse and other main equipment;
Experimental project materials:
A 1K ohm resistor, an LED light, and two Dupont wires.
I'm just doing a simple experiment, there's no need to get a "breadboard"
Then go to the website to download the information.
https://docs.microsoft.com/en-us/samples/microsoft/windows-iotcore-samples/hello-blinky/
Start connecting according to the expansion port. The power supply in the project is 3.3V power supply, and the board can also be 5V. I chose 3.3V.
The output pin selected is "GPIO 5" as output.
Open the project with VS2019.
Configure the remote host.
You can start to try running it. After the program starts, you can see the LED light flashing continuously, which is synchronized with the red bright spot on the screen.
In fact, this project is not difficult, it just proves that Windows can also be used for control. I remember that the company used PC104 to develop the project. The main consideration at that time was that the computing power of Intel CPU was relatively strong. Because the instruments in the system require relatively complex calculations. It seems that using a board like Raspberry Pi is also possible. And the price is also incomparable to PC104. Let's analyze the code below:
public sealed partial class MainPage : Page
{
private const int LED_PIN = 5;
private GpioPin pin;
private GpioPinValue pinValue;
private DispatcherTimer timer;
private SolidColorBrush redBrush = new SolidColorBrush(Windows.UI.Colors.Red);
private SolidColorBrush grayBrush = new SolidColorBrush(Windows.UI.Colors.LightGray);
public MainPage()
{
InitializeComponent();
timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromMilliseconds(500);
timer.Tick += Timer_Tick;
InitGPIO();
if (pin != null)
{
timer.Start();
}
}
private void InitGPIO()
{
var gpio = GpioController.GetDefault();
// Show an error if there is no GPIO controller
if (gpio == null)
{
pin = null;
GpioStatus.Text = "There is no GPIO controller on this device.";
return;
}
pin = gpio.OpenPin(LED_PIN);
pinValue = GpioPinValue.High;
pin.Write(pinValue);
pin.SetDriveMode(GpioPinDriveMode.Output);
GpioStatus.Text = "GPIO pin initialized correctly.";
}
private void Timer_Tick(object sender, object e)
{
if (pinValue == GpioPinValue.High)
{
pinValue = GpioPinValue.Low;
pin.Write(pinValue);
LED.Fill = redBrush;
}
else
{
pinValue = GpioPinValue.High;
pin.Write(pinValue);
LED.Fill = grayBrush;
}
}
Step 1: Initialize the device
var gpio = GpioController.GetDefault();
This function is used to initialize the driver. Then we check whether it is successful. Some devices may not have GPIO drivers, especially some Intel motherboards.
pin = gpio.OpenPin(LED_PIN);
pinValue = GpioPinValue.High;
pin.Write(pinValue);
pin.SetDriveMode(GpioPinDriveMode.Output);
Turn on GPIO5, set the default output, and define GPIO as output.
Use the pin.Write(pinValue); function to set the pin level.
pinValue = GpioPinValue.High;
pin.Write(pinValue);
Many good programs can be made by using the rich graphical interface of Windows.
This content is originally created by bigbat, a netizen of EEWORLD forum. If you want to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source