Introduction: DragonBoard: How to Access GPIOs Using JavaScript

Picture of DragonBoard: How to Access GPIOs Using JavaScript

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

List of Material:

1 - Dragonboard410c

1 - 96Boards sensors board

1- Grove Button

1 - Grove LED

Step 1: Installing NodeJs

First, update the package index.

$ sudo apt-get update

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

$ sudo apt-get install nodejs

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. In the source code to access a GPIO pin, call method for a specific GPIO pin.

For example:

/**
* Get pin 23;

* @returns {Gpio}

*/

GpioProcessor.prototype.getPin23 = function() {

return getPin(36);

};

This method will give access to the GPIO pin 23.

Step 4: Set GPIO Direction

In file Gpio.js there are functions to set GPIO direction.

Set GPIO pin as output:

Gpio.prototype.out = function(pin) {
setDirection(pin, "out");

};

Set GPIO pin as input:

Gpio.prototype.input = function(pin){
setDirection(pin,"in");

};

Call function "getDirection" to get GPIO direction.

Step 5: Read and Write Values on GPIO

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

Set GPIO pin as High level:

Gpio.prototype.high = function(pin) {
setValue(pin, '1');

};

Set GPIO as Low level:

Gpio.prototype.low = function(pin) {
setValue(pin, '0');

};

Call function "getValue" to get GPIO value.

Step 6: Release Access to the GPIO

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

Call function "clearPins()" in GpioProcessor.js to remove access of pin.

GpioProcessor.prototype.clearPins = function() {
for (var i = 0; i < pinList.length; i++) {

unexportPin(pinList[i]);

}

pinList = [];

};

The "unexportPin" function will disable access to the GPIO and remove the corresponding directory.

Step 7: Blink Led After Pressing Button

Picture of Blink Led After Pressing Button

The Main.js 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, type the command:

$ sudo nodejs "Main.js".

Step 8: References

Comments

About This Instructable

706views

12favorites

Bio: Computer Engineering at Inatel
More by ermiston_tavares:DragonBoard: How to Access GPIOs Using PythonDragonBoard: How to Access GPIOs Using JavaScriptDragonBoard: How to Access GPIOs Using C++
Add instructable to: