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:
An Azure Sphere development board that supports the Sample Appliance hardware requirements.
Note: By default, the sample targets the Reference Development Board design, which is implemented by the Seeed Studios MT3620 Development Board. To build the sample for different Azure Sphere hardware, change the value of the TARGET_HARDWARE variable in the
CMakeLists.txt
file. For detailed instructions, see the Hardware Definitions README file.
Setup
- Ensure that your Azure Sphere device is connected to your computer, and your computer is connected to the internet.
- 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.
- Enable application development, if you have not already done so, by entering the azsphere device enable-development command at the command prompt.
- 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
- For an overview of Azure Sphere, see What is Azure Sphere.
- To learn more about Azure Sphere application development, see Overview of Azure Sphere applications.