Introduction: DragonBoard: How to Access GPIOs Using C

Picture of DragonBoard: How to Access GPIOs Using C

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:

Step 3: Dragonboard GPIO Pin Mappings

Picture of 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

Picture of 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

Comments

snoop911 (author)2017-07-26

Any idea how much power the DragonBoard alone draws? I assume it's powered off a 5v usb supply, so probably less than 500ma, but it would be interesting to see if it can be used for low power / battery applications!

Hi,

Dragonboard power is +6.5V up to +18V. The ideal power is +12V. About electrical current, it depends which components you will append. Normally, the power supply (WM24P6-12-A-QL) used in the Dragonboard 410c provides 2 (two) amperes.