Internet All The Things!

 

...with Intel® Edison and Johnny-Five

by @rexstjohn

Rex St. John

 

 

www.rexstjohn.com | rex.st.john@intel.com

Follow along (with clickable links)

Things we will learn

  • Internet of Things
  • Microcontrollers
  • Node.js
  • Intel Edison
  • LibMRAA
  • Johnny-Five

Things

  • Devices with embedded computers
  • Often without displays
  • Reading physical sensors
  • Limited power, memory, compute

 

Internet

  • Communicating globally
  • Interface to existing infrastructure
  • Autonomous operation modes
  • Coordinated operation modes

 

Think: Systems, Not Devices

Industrial

  • Factory equipment monitoring
  • HVAC system monitoring/control
  • Lighting systems
  • Security
  • Maintenance (wearable)
  • Point of Sale
  • Inventory tracking
  • Precision agriculture
  • Energy consumption management

Consumer

  • Health monitoring (wearable)
  • Information access (wearable)
  • Home security
  • Delivery management
  • Automotive monitoring
  • Family status monitoring (wearable)
  • Home maintenance
  • Personal communication (wearable)
  • Energy consumption management

A few of the many applications

Microcontrollers

for beginners

  • 500Mhz Dual Core
  • 4 gigs flash
  • 1 gig ram
  • Node.js preloaded
  • Yocto-Linux
  • Bluetooth & Wi-Fi
  • Arduino Compatible

Intel Edison

tl;dr Tiny Internet of Things Computer

Edison kits & Where to buy

What is an MCU

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.

Seeed Header Shield

PWM

GPIO

SPI

I2C Bus

UART

An easy way to plug sensors into our Edison's pins (see pinout)

  • PWM: Pulse Width Modulation (Robot arms etc)
  • GPIO: General Purpose I/O (Digital)
  • I²C​: Bi-directional, chainable, low-speed communication
  • SPI: Synchronous, short distance communication
  • UART (RX / TX): Two lines of serial, must agree on transmission speed

Basic terms

Introduction

to Node.js

node.js basics

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 basics

  • Command line utility
  • Helps you install Node modules
  • Useful for Node.js development
  • Like Pip or RVM or Apt-Get for Node.js
$ npm install
$ npm install -g bloop
$ npm install bloop

Local, Global installation patterns

Node modules

Modules are helper libraries you can include in your project, there are thousands of them.

  • "npm_modules" folder
  • package.json
  • main.js

Example package file


{
  "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"
  }
}

npm init

$ 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

Basic project

Edit your project using your IDE of choice!

$ cat package.json
$ touch blink.js
$ open blink.js 

LibMraa

FOR beginners

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.

Libmraa syntax

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);
});

Johnny-Five Syntax

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));
  });
});

Johnny-Five Syntax

Analog Data

our sensor kit

  • Temperature x1
  • Sound Sensor x1
  • Light x1
  • Buzzer x1
  • Button x1
  • Pressure Sensor x1
  • Servo x1
  • Relay x1
  • Buzzer x1
  • LCD x1
  • LED x3

Good news!

We have sample Node.js snippets and a project for every sensor in our sensor kits available at the below link!

Time to build things!

Time to get started

Intel Edison and Node.js Overview

By Rex St. John

Intel Edison and Node.js Overview

This is my Edison and Node.js Internet of Things introduction

  • 4,628