Blinky Sample

The classic LED blinking app (we'll guide you through the necessary wiring on your MinnowBoard Max).

Blinky Sample

We’ll create a simple Blinky app and connect a LED to your MinnowBoard Max (or MBM for short).

Load the project in Visual Studio

You can find this sample in the Samples\Blinky folder. Choose either the C++ version or C# version.

Make sure you set the ‘Remote Debugging’ setting to point to your MBM. Go back to the basic ‘Hello World’ sample if you need guidance.

Connect the LED to your MBM

You’ll need a few components:

Electrical Components

Connect one end of the LED to GPIO_S5[0] (pin 21 on the JP1 expansion header) on the MBM, the other end to the resistor, and the resistor to the 3.3 Volts power supply from the MBM.

Here is the schematics:

LED schematics

And here is the JP1 connector on the MBM:

MBM GPIO S5-0

When everything is set up, you should be able to press F5 from Visual Studio: The Blinky app will deploy and start on the MBM, and you should see the LED blink in sync with the simulation on the screen.

Blinky in Action

Congratulations! You controlled one of the GPIO pins of the MBM!

Let’s look at the code

The code for this sample is pretty simple. We use a timer, and each time the ‘Tick’ event is called, we flip the state of the LED.

Timer code

Here is how you set up the timer in C#:

public MainPage()
{
    // ...
    
    this.timer = new DispatcherTimer();
    this.timer.Interval = TimeSpan.FromMilliseconds(500);
    this.timer.Tick += Timer_Tick;
    this.timer.Start();
    
    // ...
}
    
private void Timer_Tick(object sender, object e)
{
    FlipLED();
}

Initialize the GPIO pin

To drive the GPIO pin, first we need to initialize it. Here is the C# code (notice how we leverage the new WinRT classes in the Windows.Devices.Gpio namespace):

using Windows.Devices.Gpio;
    
private async void InitGPIO()
{
    try
    {
        var deviceId = GpioController.GetDeviceSelector("GPIO_S5");
        var deviceInfos = await DeviceInformation.FindAllAsync(deviceId, null);
        var controller = await GpioController.FromIdAsync(deviceInfos[0].Id);
        GpioPinInfo pinInfo;
        controller.Pins.TryGetValue(0, out pinInfo);
        pinInfo.TryOpenOutput(GpioPinValue.High, GpioSharingMode.Exclusive, out this.outPin);
        GpioStatus.Text = "GPIO pin initialized correctly.";
    }
    catch (Exception)
    {
        GpioStatus.Text = "There were problems initializing the GPIO pin.";
    }
}

Let’s break this down a little:

Modify the state of the GPIO pin

Once we have access to the GpioOutputPin instance, it’s trivial to change the state of the pin to turn the LED on or off.

To turn the LED on, simply set the value of the pin to GpioPinValue.Low:

this.outPin.Value = GpioPinValue.Low;

and of course, set it to GpioPinValue.High to turn the LED off:

this.outPin.Value = GpioPinValue.High;

Remember that we connected the other end of the LED to the 3.3 Volts power supply, so we need to drive the pin to low to have current flow into the LED.

Questions/Suggestions

As always, for questions and feedback, contact us.