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):
self.setDirection("out")

Set GPIO pin as input:

def input(self):
self.setDirection("in")

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):
self.setValue(1)

Set GPIO as Low level:

def low(self):
self.setValue(0)

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:

pin.input()

pin.closePin()

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