Rex St. John
Edge Computing Ecosystems
...with Intel® Edison and Johnny-Five
by @rexstjohn
www.rexstjohn.com | rex.st.john@intel.com
Follow along (with clickable links)
Think: Systems, Not Devices
A few of the many applications
tl;dr Tiny Internet of Things Computer
A microcontroller (sometimes abbreviated µC, uC or MCU) is a small computer on a single integrated circuit containing a processor core, memory, and programmable input/output peripherals.
PWM
GPIO
SPI
I2C Bus
UART
An easy way to plug sensors into our Edison's pins (see pinout)
Node.js is an open source, cross-platform runtime environment for server-side and networking applications. Node.js applications are written in JavaScript, and can be run within the Node.js runtime on OS X, Microsoft Windows, Linux, FreeBSD, NonStop and IBM i.
$ npm install
$ npm install -g bloop
$ npm install bloop
Local, Global installation patterns
Modules are helper libraries you can include in your project, there are thousands of them.
{
"name": "edison-johnny-five",
"description": "A simple Edison blink sketch.",
"version": "0.0.1",
"main": "blink.js",
"engines": {
"node": ">=0.10.0"
},
"dependencies": {
"johnny-five": "latest",
"edison-io": "latest"
}
}
$ mkdir code
$ cd code
$ npm init
$ name: (code) demo
$ version: (1.0.0) 1.0.0
$ description: blink
$ entry point: blink.js
$ test command:
$ git repository:
$ keywords:
$ license: (ISC)
// Blink an LED
var five = require("johnny-five");
var Edison = require("edison-io");
var board = new five.Board({
io: new Edison()
});
board.on("ready", function() {
var led = new five.Led(13);
led.blink(1000);
});
{
"name": "edison-johnny-five",
"description": "A simple Edison blink.",
"version": "0.0.1",
"main": "blink.js",
"engines": {
"node": ">=0.10.0"
},
"dependencies": {
"johnny-five": "0.8.5",
"edison-io": "0.8.3"
}
}
package.json
blink.js
Edit your project using your IDE of choice!
$ cat package.json
$ touch blink.js
$ open blink.js
Johnny-Five is an Open Source, Firmata Protocol based, IoT and Robotics programming framework, developed at Bocoup. Provides a Node.js API on top of LibMRAA to interact with Intel Edison GPIO sensors.
LibMRAA is a C/C++ library with bindings to javascript & python to interface with the IO on Galileo, Edison & other platforms, with a structured and sane API where port names/numbering matches the board that you are on.
var m = require('mraa'); //require mar
//write the mraa version to the console
console.log('MRAA Version: ' + m.getVersion());
//LED hooked up to digital pin 13 (or built in pin on Galileo Gen1 & Gen2)
var myLed = new m.Gpio(13);
myLed.dir(m.DIR_OUT); //set the gpio direction to output
var ledState = true; //Boolean to hold the state of Led
periodicActivity(); //call the periodicActivity function
function periodicActivity()
{
//if ledState is true then write a '1' (high) otherwise write a '0' (low)
myLed.write(ledState?1:0);
ledState = !ledState; //invert the ledState
//call the indicated function after 1 second (1000 milliseconds)
setTimeout(periodicActivity,1000);
}
Could it be even easier?
// Blink an LED
// Pin 13 is the default pin
var five = require("johnny-five");
var Edison = require("edison-io");
var board = new five.Board({
io: new Edison()
});
board.on("ready", function() {
var led = new five.Led(13);
led.blink(1000);
});
Digital Pin: 0 or 1
// Plug the temperature sensor A0
// Seeed Sensor Kit Arduino Shield
// MUST be in the analog pin slots!
var five = require("johnny-five");
var Edison = require("edison-io");
var board = new five.Board({
io: new Edison()
});
board.on("ready", function() {
var temp = new five.Temperature({
pin: "A0",
controller: "GROVE"
});
temp.on("change", function() {
console.log("%d°C", Math.round(temp.celsius));
});
});
Analog Data
We have sample Node.js snippets and a project for every sensor in our sensor kits available at the below link!
Time to get started
By Rex St. John
This is my Edison and Node.js Internet of Things introduction