-
Notifications
You must be signed in to change notification settings - Fork 2
GPIO Hardware Control: BLINK
This document explains the procedure for controlling GPIO pins (Writing and Reading) using the galile-io library.
This exercise is based on a more extent explanation of Node.JS by Nicolas Vailliet here:
This WIKI page is a living document that may be changed at any moment without prior notice.
All procedures and instructions shared in this GIT Hub Account are given to you "as-is" without any implicit or explicit warranty of success.
To the extent permitted by law, I accept no liability or responsibility for any damage or loss you may get into while following this procedure.
As of the time this post was written, I am affiliated to Intel Corporation as a regular employee based in Costa Rica, working as an Applications Developer.
All content in this page is provided voluntarily and personally independently of Intel.
You need:
- Perform the Boot from SD Card procedure (Optional)
- Perform the Connecting through LAN procedure
- You can use Connecting through LAN procedure
- example for May 20, 12:57pm:
date 2005125714
This will make node.js run better; especially when running the npm (nodejs package manager)
- Using the puTTY terminal, create a folder to store your code. i.e.: /home/root/gpioexamples
cd /home/root
mkdir gpio_examples
- Access the folder you just created
cd /home/root/gpio_examples
- Install galileo-io npm package
npm install galileo-io
This will install galileo-io package in your current project (folder) under node-packages folder.
- Using vi text editor create a new JS file named "blink.js"
logMessage("Script Begins!");
var Galileo = require("galileo-io");
var board = new Galileo();
var pin = 9;
var byte = 0;
/*
* Contains the logic for when the Galileo Board is Ready
* @returns {undefined}
*/
function galileoReadyHandler(){
logMessage("galileoReadyHandler() Begins!");
this.pinMode(pin, this.MODES.OUTPUT);
logMessage("Pin was just set as OUTPUT");
setInterval(intervalHandler, 500);
logMessage("Interval was just set to 500ms");
}
/*
* Writes to the designated blink pin toggling between 0 and 1. This function is to be called by an Interval (timer) handler.
* @returns {undefined}
*/
function intervalHandler(){
logMessage("intervalHandler() Begins!");
board.digitalWrite(pin, (byte ^= 1));
logMessage("digitalWrite() just happened!");
}
/***
* Logs messages into the console including a milliseconds timestamp
* @param {type} message
* @returns {undefined}
*/
function logMessage(message){
var d = new Date().getTime();
console.log(d + " - " + message);
}
/***
* This line sets up the Ready event of the Galileo Board to be handled by galileoReadyHandler function.
* @param {type} param1
* @param {type} param2
*/
board.on("ready", galileoReadyHandler);
- Connect an LED to the Galileo Board as follows
- run the file in node.js by executing
node blink.js
- The system will blink a signal in pin 9. It will also show different debug information in the console.