DragonBoard: How to Access GPIOs Using Python

Introduction: DragonBoard: How to Access GPIOs Using Python

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 Python Language from Linux GPIO.

List of Material:

1 - Dragonboard410c

1 - 96Boards sensors board

1- Grove Button

1 - Grove LED

Step 1: Installing the Python

First, update the package index.

$ sudo apt-get update

Now, you can install the Python 2.7 with the following command:

$ sudo apt-get install python2.7

Step 2: Download Source Code

Download the source code below:

Step 3: Dragonboard GPIO Pin Mappings

This picture shows DragonBoard GPIO pins mappings. In the source code to access a GPIO pin, call function for a specific GPIO pin.

For example:

def getPin23(self):
return self.getPin(36)

This method will give access to the GPIO pin 23.

Step 4: Set GPIO Direction.

In file GPIOLibray.py there are functions to set GPIO direction.

Set GPIO pin as output:

def out(self):

Set GPIO pin as input:

def input(self):

To get GPIO direction, call function "getDirection()"

Step 5: Read and Write Values on GPIO

In the GPIOLibray.py there are function to read and write values on GPIO pin.

Set GPIO pin as High level:

def high(self):

Set GPIO as Low level:

def low(self):

To read value from GPIO, call function getValue();

Step 6: Release Access to the GPIO

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

Call function cleanup() in GPIOLibrary.py to remove access of pin.

def cleanup(self):
for pin in self.GPIOList:



self.GPIOList = []

The "closePin()" function will disable access to the GPIO and remove the corresponding directory.

Step 7: Blink Led After Pressing Button

The blink_led.py 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, type the command:

$ sudo python blink_led.py

Step 8: References

Be the First to Share


    • CNC and 3D Printing Contest

      CNC and 3D Printing Contest
    • Puzzles Challenge

      Puzzles Challenge
    • Lamps Challenge

      Lamps Challenge



    3 years ago

    One more problem that I am facing is that if I am not able to do GP.cleanup() in a script, the next time that I run that script I am unable to access that pin. This is pretty straight forward as I didn't give up that pin. However, there should be a way to give up previously owned GPIOs through another script. I tried doing just the GP.cleanup() using another script but it did not work either. After checking the source I realized that only cleans the GPIO which were used in that particular script when that function was called. Is there a way to clear previously owned pins by maybe including another line in the source? Thanks


    3 years ago

    The next thing I wanted was to define an interrupt pin and invoke a function whenever an interrupt occurs on that pin. How can I include that in your present script?


    Question 3 years ago on Introduction

    Hi. I tried your scripts but it started throwing error the moment I tried to execute. I'm new to linux and python so I might be a big time noob here. First it said that the export and other files in the gpio folder does not have the permissions. Then after giving the permission it is saying that resource is busy. Any help or set of steps that need to be done before executing this?


    Answer 3 years ago

    I solved this by just using another GPIO pin. It works.