Introduction: DragonBoard: How to Access GPIOs Using C

About: Computer Engineering at Inatel

The DragonBoard™ 410c is the first development board based on a Qualcomm® Snapdragon™ 400 series processor. It features advanced processing power, Wi-Fi, Bluetooth connectivity, and GPS, all packed into a board the size of a credit card. Based on the 64-bit capable Snapdragon 410E processor, the DragonBoard 410c is designed to support rapid software development, education and prototyping, and is compliant with the 96Boards Consumer Edition specification. All this makes it ideal for enabling embedded computing and Internet of Things (IoT) products, including the next generation of robotics, cameras, medical devices, vending machines, smart buildings, digital signage, casino gaming consoles, and much more.

In this tutorial you will learn how to access the GPIO of the boards using C Language from Linux GPIO.

List of Material:

1 - Dragonboard410c

1 - 96Boards sensors board

1- Grove Button

1 - Grove LED

Step 1: Installing GCC Compiler

First, update the package index.

$ sudo apt-get update

Now, you can install the GCC compiler with the following command:

$ sudo apt-get install build-essential

Step 2: Download Source Code

Download the source code below:

Attachments

Step 3: Dragonboard GPIO Pin Mappings

This picture shows DragonBoard GPIO pins mappings.

Step 4: Enable Access GPIO

It must necessary "export" file to enable access to the GPIO and create the corresponding directory.

Call function "enablePinXX" in "GpioProcessor" file to export specific GPIO pin.

For example:

/**
* Enable access to GPIO23.

*/

void exportPin23() {

exportPin("36");

}

Step 5: Set GPIO Direction.

In file "Gpio.h" have functions to set GPIO direction.

First, you have to set GPIO to be worked. Call function "setPinXX" to set specific pin.

void setPin23() {

setPin("36");

}

Now you can set GPIO direction. Call function "pin_out" to set pin as outuput or "pin_in" to set pin as input.

Step 6: Read and Write Values on GPIO

In file "Gpio.h" have functions to read an write values on GPIO.

First, you have to set GPIO to be worked. Call function "setPinXX" to set specific pin.

void setPin23() {

setPin("36");

}

Now you can write or read on GPIO. Call function "pin_low" to write LOW level ("0") or "pin_high" to write HIGH level("1").

To read value on GPIO, call function "getValue".

Step 7: Release Access to the GPIO Pin

After using GPIO pin, it is necessary release access to the GPIO.

Call function "unexportPinXX" to release access to the specific pin.

For example:

unexportPin27();

Step 8: Blink Led After Pressing Button

The Main.c runs an example that blink led after pressing button during 20 seconds.
In this example we are accessing pin 27 for blink led and pin 29 to read button status.

After 20 seconds, both GPIO's are released.

To run the example, it's necessary complile the c files. $ gcc Main.c -o main

It is necessary give access to the generate file

$ sudo chomod +x main

Run file

$ ./main

Step 9: References