Let’s explore the General Purpose Input/Output (GPIO) interface offered by the Windows 10 IoT core.
The GPIO interface is deceptively simple. It consists of a few classes and enumerations. The main classes are:
GpioController class: Provides access to all the pins of the GPIO(s) bus.
GpioPin class: Represents a single pin on the GPIO. It provides functions to read/write pin values and provides an event that can be triggered when a pin value changes.
GpioController class cannot be directly instantiated. Instances are accessed through one of the
static functions on the class:
GetDefault(): Returns the default Gpio controller for the device
GetDefaultAsync(): Returns the default Gpio controller for the device asynchronously
GetControllersAsync(): Returns a list of all the Gpio controllers available for the device asynchronously
The instance functions of the
GpioController are used to manage pins:
PinCount: Returns the number of pins available for this
OpenPin(): Opens a connection to the pin and returns the corresponding
GpioPin. An overload of the function allows you to supply a sharing mode other than exclusive.
TryOpenPin(): Opens a connection to the pin and returns the corresponding
GpioPin. This variant will not throw an exception on error but will return a status making it easier to handle errors.
GpioPin class gives you access to read and manipulate a single pin. Like the
GpioController, you cannot instantiate this class directly. You access it using the
GpioController OpenPin or
GpioPin class provides members query information about the pin:
PinNumber: Returns the pin number for this pin.
SharingMode: Returns the sharing mode for this pin. Modes can be
GpioPin class provides members configure the pin. Drive mode is probably the most important item to configure on a pin. It tells the pin whether it is an input or an output and specifies the way the electronic is organized. There are multiple drive mode available. See GpioPinDriveMode for more information about the available drive modes. I will do a post specific to this later on.
IsDriveModeSupported(): Can the pin support this drive mode
GetDriveMode(): Returns the currently configured drive mode for this pin
SetDriveMode(): Sets the drive mode for this pin
ValueChanged: Event that is triggered when a change of state is detected on the pin. This member allows us to attach an event handler to handle that event.
Sets the interval of time after the
ValueChanged event is triggered during which the changes in the pin will not trigger another
GpioPin class provides members to read and write the value of the pin:
Read(): Returns the current value of the pin
Low. This will work on inputs or output pins.
Write(): Sets the value for the pin
Low. This will only work on output pins.
There are a number of possible ways to use the GPIO. The most common scenarios are:
Pin Reading / Writing
This process consists in setting up your pin(s), manipulating them and disposing of the pin when done.
Reading and Writing GPIO Pins
This process consists in setting up your pin(s), registering an event handler that will be triggered when a pin change is detected and waiting for events to occur, and disposing of the pin(s) when done.
Reading and Writing GPIO Pins
The GPIO interface provided by the Windows 10 IoT library is simple but comprehensive. This information should allow us to come up with a plan on how to write device code.
The only touchy points I can see so far is: Figuring out how to set a valid
DebounceTimeout value. We’ll be in a better position to figure out those details once we start coding against an actual device.
For more information, see the MSDN documentation: