‘Hello, blinky!’ using Lightning.Providers

This sample demonstrates how to communicate with GPIO using the Micorosot.IoT.Lightning.Providers.I2cProvider

It’s based on the Blinky UI sample and shares the same setup steps. The main difference is setting the Lightning provider as the default controllers provider.

Using Lightning Provider

The original code of the Blinky sample used the default GPIO provider for obtaining the GPIO controller:

// Original Blinky UI sample code

using Windows.Devices.Gpio;

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.";

    pin = gpio.OpenPin(LED_PIN);
    pinValue = GpioPinValue.High;

    GpioStatus.Text = "GPIO pin initialized correctly.";


To enable the use of the Lightning provider, the GPIO controller initialization code needs to be modified to set the Lightning provider as the default provider.
In the initialization code below, if the Lightning driver is enabled on the target device, the Lightning provider will be used. Otherwise, the app falls back to using the default provider.

using Microsoft.IoT.Lightning.Providers;
using Windows.Devices.Gpio;

private async void InitGPIO()
    // Set the Lightning Provider as the default if Lightning driver is enabled on the target device
    if (LightningProvider.IsLightningEnabled)
        LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();

    // Remaining initialization code works the same regardless of the current default provider

        gpioController = await GpioController.GetDefaultAsync(); /* Get the default GPIO controller on the system */
        if (gpioController == null)
            // ...

Building and deploying the sample

  1. Enable Lightning on your Raspberry Pi2 or MBM device using the the steps outlined in the Lightning Setup Guide.

  2. Ensure the correct version of the Windows SDK is installed on your development machine. The required Windows SDK can be installed from here.

  3. Clone the source for the Blinky sample for Lightning from Github to a local folder.

  4. To setup the LED connectons, refer to the original Blinky sample.

  5. Load the solution in Visual Studio.

  6. Select “Blinky (Univeral Windows)” as the startup project.

  7. Build the app.

  8. Deploy and run the app on your device. You can use the Deploying an App with Visual Studio for guidance.

Blinky Output

Was this page helpful?
Additional feedback?
Thank you! We appreciate your feedback.
Follow us