DragonBoard: How to Access GPIOs and Analog Pins

by GabrielA173 in Circuits > Electronics

1600 Views, 3 Favorites, 0 Comments

DragonBoard: How to Access GPIOs and Analog Pins

front.png

Sample to show how to access and use the GPIOs and Analog pins

Install Dependencies

To access the pins from the dragonboard, we're going to use the MRAA library to keep this really easy, but to use this, we need to setup a fill things before start.

MRAA library needs to setup some environment variables on the DragonBoard.

NODE_PATH="/usr/local/lib/node_modules"
PYTHONPATH="/usr/local/lib/python2.7/site-packages"
JAVA_HOME="/usr/lib/jvm/default-java"
export NODE_PATH
export PYTHONPATH
export JAVA_HOME

Install NodeJs:

  • apt-get install git gcc g++ python2.7 build-essential
  • cd ~/Documents
  • git clone git@github:nodejs/node.git
  • cd node
  • ./configure
  • make
  • sudo make install

Install MRAA Dependency

After setup the environment variables we need to install the direct MRAA dependency. This library needs SWIG with minimum version 3.0.5 and to install it, you just need to follow this steps:

  • git clone https://github.com/swig/swig.git
  • cd swig
  • ./autogen.sh (it creates the configure script)
  • ./configure
  • make
  • sudo make install

Install MRAA Library

To install the MRAA we have two options to do it, first and the easiest way is install using npm:

  • npm install mraa -g

and the other way is building the source code from Github

Access GPIOs and Analog Pins

dragon_board_groove.jpg

Now, after we install all dependencies that we need, we're able to access the pins.

for example, we're going to write 0 or 1 in some GPIO.

Here I have a simple led connected on port 27 in my DragonBoard:

var m = require('mraa');
var myDigitalPin = new m.Gpio(27); //setup acess to pin 27 from dragonboard
myDigitalPin.dir(m.DIR_OUT);
myDigitalPin.write(1); // 1 to enable and 0 to disable

In this sample, I'm using the MRAA to be able access the GPIOs without any problem.

I'm setting my variable to connect into the pin 27 using "new m.Gpio(27)", then I need to set the direction from my variable, in this case I'm using this variable just to write in this port. After set the variable to write, we just need to set the pin with zero or one.

And to read values from analog pins, we can use the follow sample:

var mraa = require('mraa'); //require mraa
console.log('MRAA Version: ' + mraa.getVersion()); //write the mraa version to the console

var analogPin0 = new mraa.Aio(0); //setup access analog input Analog pin #0 (A0)
var analogValue = analogPin0.read(); //read the value of the analog pin
console.log(analogValue); //write the value of the analog pin to the console