...with Intel® Edison and Johnny-Five
by @rexstjohn
www.rexstjohn.com | rex.st.john@intel.com
Follow along (with clickable links)
Please pass it on or bring it back to me when you are done!
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!
Button | Light | Edison | Node.js
Make sure to follow 100% of the steps...
FTDI drivers must be installed!
$ sudo npm install -g bloop
$ bloop c
An easier way to establish a serial connection for Mac users.
Hit "Enter" twice at the blank screen!
$ sudo apt-get install screen
$ sudo screen /deb/ttyUSB0 115200
Hit "Enter" twice at the blank screen!
$ configure_edison --setup
$ ping www.google.com (to test internet)
Default password is "root."
Usually you have to scan for Wi-Fi twice (hit '0') to make it scan again...
sftp://10.0.1.132
$ echo "src mraa-upm http://iotdk.intel.com/repos/1.1/intelgalactic" > /etc/opkg/mraa-upm.conf
$ opkg update
$ opkg install libmraa0
$ opkg upgrade
$ cd /
$ cd node_app_slot
$ npm install
$ node blink.js
Using your serial connection in your Edison code directory....
All Platforms
// 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(4);
led.blink(1000);
});
All Platforms
$ node blink.js
// Activate the touch button
// This code will work for BOTH the capactive button and the "standard" button.
var five = require("johnny-five");
var Edison = require("edison-io");
var board = new five.Board({
io: new Edison()
});
board.on("ready", function() {
var touch = new five.Button(5);
var led = new five.Led(4);
touch.on("press", function() {
console.log("Pressed!");
led.on();
});
touch.on("release", function() {
console.log("Released!");
led.stop().off();
});
touch.on("hold", function() {
console.log("Holding...");
led.blink();
});
});
Congrats! Thanks to @rwaldron for creating Johnny-Five.