Introduction to GrovePi with Windows IOT: LED Blink Tutorial
This tutorial shows the simplest thing that you can do with the GrovePi: Blink a LED. This is a great first project to learn how to connect hardware to the Raspberry Pi. The blinking LED is the hardware version of the software world’s “Hello World” program. Once mastered, you can move on to more complicated projects like connecting a display to the Raspberry Pi or other sensors.
This example is meant to be your first project with the GrovePi. All the parts used in this project are available in the GrovePi Starter Kit.
Prerequisites
- Raspberry Pi running Windows IoT
- GrovePi Starter Kit
Hardware for This Tutorial
All of the hardware comes with the GrovePi starter kit. Specifically, for the Raspberry Pi LED Tutorial, you’ll need:
- The Raspberry Pi
- GrovePi
- Grove LED
- One Grove Connection wire
Hardware Setup: Connecting the LED to the Raspberry Pi
Software: Running the Program
- Download the GrovePi Windows IoT Drivers and open GrovePi.sln.
- Set "Driver" as your "Startup Project"
- Replace the code found in "SampleDriver.CS" with the code listed below
- Deploy to your device and watch the LED blink. (Refer to this link If you have not previously setup visual studio to deploy to your Raspberry Pi)
SampleDriver.cs :
-
using System.Threading.Tasks;
-
using Windows.ApplicationModel.Background;
-
using GrovePi;
-
using GrovePi.Sensors;
-
namespace Driver
-
{
-
public sealed class SimpleDriver : IBackgroundTask
-
{
-
private readonly IBuildGroveDevices _deviceFactory = DeviceFactory.Build;
-
public void Run(IBackgroundTaskInstance taskInstance)
-
{
-
var led = _deviceFactory.Led(Pin.DigitalPin4);
-
while (true)
-
{
-
led.ChangeState(SensorStatus.On);
Task.Delay(500).Wait();
-
led.ChangeState(SensorStatus.Off);
-
Task.Delay(500).Wait();
-
}
-
}
-
}
-
}
Comments