Azure Sphere – GPIO

This sample application demonstrates how to use a general-purpose input/output (GPIO) with Azure Sphere in a high-level application.

A GPIO is used to read the state of button A and to change the blink rate of LED 1 in response to a button press. The sample allows three possible blink rates for the LED.

The sample uses the following Azure Sphere libraries.

Library Purpose
eventloop Invokes handlers for timer events.
gpio Accesses button A and LED 1 on the device.
log Displays messages in the Device Output window during debugging.

Contents

File/folder Description
app_manifest.json Application manifest file, which describes the resources.
CMakeLists.txt CMake configuration file, which Contains the project information and is required for all builds.
CMakePresets.json CMake presets file, which contains the information to configure the CMake project.
launch.vs.json JSON file that tells Visual Studio how to deploy and debug the application.
LICENSE.txt The license for this sample application.
main.c Main C source code file.
README.md This README file.
.vscode Folder containing the JSON files that configure Visual Studio Code for deploying and debugging the application.
HardwareDefinitions Folder containing the hardware definition files for various Azure Sphere boards.

Prerequisites

The sample requires the following hardware:

Setup

  1. Ensure that your Azure Sphere device is connected to your computer, and your computer is connected to the internet.
  2. Even if you've performed this setup previously, ensure that you have Azure Sphere SDK version 23.05 or above. At the command prompt, run azsphere show-version to check. Upgrade the Azure Sphere SDK for Windows or Linux as needed.
  3. Enable application development, if you have not already done so, by entering the azsphere device enable-development command at the command prompt.
  4. Clone the Azure Sphere samples repository and find the GPIO_HighLevelApp sample in the GPIO folder or download the zip file from the Microsoft samples browser.

Build and run the sample

To build and run this sample, follow the instructions in Build a sample application.

Test the sample

The output messages are displayed in the Device Output window during debugging.

LED1 on the MT3620 begins blinking red. Press button A on the MT3620 repeatedly to cycle through the three possible LED blink rates.

Next steps