Internet All The Things!

 

...with Intel® Edison and Johnny-Five

by @rexstjohn

Rex St. John

 

 

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

Get the deck

http://bit.ly/1Hgxe4l

Follow along (with clickable links)

  • Windows drivers
  • Latest Edison Image
  • Windows Installer
  • FileZilla, PuTTy, WinSCP, Intel XDK
  • Code snippets

Copy the USB stick

Please pass it on or bring it back to me when you are done!

Things we will learn

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

Agenda

  1. Learn about all the things
  2. Set up all the things
  3. Network all the things
  4. Build all the things
  5. Conclusion (of the things)

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!

Agenda

  1. Learn about all the things
  2. Set up all the things
  3. Network all the things
  4. Build all the things
  5. Conclusion (of the things)

Setting up the things

Thing we will build

Button | Light | Edison | Node.js

Using the right usb

  • Middle = Power
  • Outer = Serial
  • Plug in both!

mac

flashing your edison

  • Download Windows drivers or use the installer
  • Use image on the provided USB for speed
  • Windows installer will need to download the latest image which will take time

Make sure to follow 100% of the steps...

Agenda

  1. Learn about all the things
  2. Set up all the things
  3. Network all the things
  4. Build all the things
  5. Conclusion (of the things)

Networking the things

FTDI drivers must be installed!

MAC

$ 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!

lets get online

$ configure_edison --setup
$ ping www.google.com (to test internet)
  1. Name your Edison
  2. Set a password
  3. Scan for Wi-Fi
  4. Set Wi-Fi network
  5. Test internet

Default password is "root."

Usually you have to scan for Wi-Fi twice (hit '0') to make it scan again...

Gotchas

  • Bad USB cables...power only
  • Make sure you and Edison are on the same wi-fi
  • Not online? Run "ping www.google.com" to check
  • Could not find a PTY error (Mac only)
    • Kill screen process - Use "bloop clean" to fix it.
  • Make sure both Micro-USB are plugged in

get your ip address

sftp://10.0.1.132

deploy code

  1. Open FileZilla
  2. Enter IP
  3. Your user / pw
  4. Quickconnect
  5. Drag & drop!
  • Use "wpa_cli status" to find your  IP
  • All code goes to /node_app_slot
  • Port 22

 

$ 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

blink pin 13

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

blink pin 4

All Platforms

$ node blink.js

expected result

Add a button

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

expected result

johnny-five is alive!

Congrats! Thanks to @rwaldron for creating Johnny-Five.

Made with Slides.com