Digital I/O pin operations are quite simple in Windows 10 IoT Core. Windows provides a GPIO controller object. With this object, we can select a pin, set it for input or output, and read or write the logic state of the pin.

To access a pin, we first need an instance of the GpioController object. As the name suggests, the GpioController is where we go to set up GPIO pins. Once we have a reference to the GpioController, we can get a reference to a pin.

The pin reference allows us to set the pin mode to input or output, and to read or write the state of the pin.

Before we can do this, we need to add another using statement, to say that we’ll be using the Windows.Devices.Gpio library.

Now we can add a little function to set up the pin 5 as an output to blink the LED.

After we get the pin reference, we write the pin value to HIGH, and then set the mode to output.

The only thing left to do in BlinkyHeadless is to actually toggle the LED in Timer_Tick. We’ll keep track of the current state of the pin in a variable, and use that to decide whether to turn the pin to HIGH or LOW:

Pi Setup

Of course, if we want to blink a LED, we need to attach a LED to the Pi. Use something like a red LED. Connect the long leg of the LED to GPIO 5 on the Pi. Connect a 180 Ohm resistor to the short leg of the LED, and then connect the other end of the resistor to Ground on the Pi.

Connected this way, the LED will light when we set the GPIO pin HIGH, and it will turn off when we set the GPIO pin LOW.

(Note: This is different from the way Microsoft has the LED arranged in their version of Blinky.  Microsoft Blinky asks you to wire the LED between 3.3V and the GPIO pin.  Wired that way, to turn the LED on, you have to set the GPIO pin to low.  To turn the LED off, you have to set the GPIO pin to high. There are reasons for doing it this way, but it's kind of logically backwards).

This guide was first published on Aug 03, 2016. It was last updated on Aug 03, 2016.

This page (Pin I/O) was last updated on Jul 14, 2016.

Text editor powered by tinymce.