Introduction: DragonBoard: How to Access GPIOs Using Java

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

List of Material:

1 - Dragonboard410c

1 - 96Boards sensors board

1- Grove Button

1 - Grove LED

Step 1: Installing the Default JDK

First, update the package index.

$ sudo apt-get update

Now, you can install the JDK with the following command:

$ sudo apt-get install default-jdk

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 method for a specific GPIO pin. For example:

public Gpio getPin23() {

return getPin(36);

}

This method will give access to the GPIO pin 23.

Step 4: Set GPIO Direction.

In file Gpio.java there are methods to set GPIO direction.

Set GPIO pin as output:

public void out() {

setDirection("out");

}

Set GPIO pin as input

public void in() {

setDirection("in");

}

Step 5: Read and Write Values on GPIO Pin

In the Gpio.java there are methods to read and write values on GPIO pin.

Set GPIO pin as High level.

public void high() {

setValue(Gpio.HIGH);

}

Set GPIO as Low level

public void low() {

setValue(Gpio.LOW);

}

Step 6: Release Access to the GPIO Pin

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

Call method closePins() in GpioProcessor.java to remove access of pin.

public void closePins() {

for (Integer pin : pins) {

unexportPin(pin); }

pins.clear();

}

the "unexport" method will disable access to the GPIO and remove the corresponding directory.

Step 7: Blink Led After Pressing Button

The Main.java 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 generate jar file. To run jar file, type the command:

$ sudo java -jar "jarfile.jar".

Step 8: References