Alice

in hardware land

JavaScript models of interaction with the physical world


Use ← → keys to navigate the slides
You may block the camera access as they were used during live demos.

  1. 1
    JS Logo
  2. 2
    JS Logo
  3. 3
    WiFi animated logo
    JS Logo
  1. 1
    JS Logo

    JavaScript running on hardware:
    single-board computers or micro-controllers

JS on Single-board computer

Processor Architecture OS
My laptop Intel Core i5 x86 MacOS
Tessel 2 MediaTek MT7620 MIPS Linux (OpenWRT)
Raspberry PI 3 Broadcom BCM2837 ARM Linux (Debian)
Beaglebone Black Sitara AM335x ARM Linux (Debian)

Node.js (ARM / MIPS) running on a tiny computer
with GPIO and wireless capabilities!

GPIO is general-purpose input/output pin on a chip or computer board

JS on micro-controllers

  • JerryScript website
  • Ducktape website
  • Espruino website

Demo

  1. Join WiFi: TesselRouter
  2. Visit URL: 192.168.1.101

Hardware: Tessel & Servo

Tessel and Servo hardware wiring
Tessel Tessel 2: MediaTek (Linux and WiFi), Atmel μ-controller
Servo Tower Pro SG92

Software: JavaScript

					
// File: index.js
// Run: t2 push index.js

var tessel = require('tessel')
var servoPin = tessel.port.A.pwm[0]
var app = require('express')()
var angle = 0
...

tessel.pwmFrequency(50)
servoPin.pwmDutyCycle(1/20)

app.get('/turn', function (req, res) {
  angle += 30
  servoPin.pwmDutyCycle(((angle)/180 + 1)/20) // move the servo
  ...
})
					
				

Practical application: Robotics

OpenROV running on Beaglebone

OpenROV plugin thrusters in node.js

Explore

  • Beaglebone Bonescript Github page
  • GPIO node lib for Linux boards
  • Tessel.io website
  1. 2
    JS Logo

    JavaScript tethered with firmata

Firmata is a protocol for communicating with
microcontrollers

Abstraction: Tethered app

app node-pixel JS laptop
firmata.js JS laptop
serial-port JS & C++ laptop
firmata sketch Arduino (C++) arduino uno
arduino library Arduino (C++) arduino uno
micro-controller ATmega328p binary arduino uno

Demo

Hardware: Neopixel & Arduino

Neopixel with Arduino board
Neopixel WS2812 has control circuit and RGB chip integrated
Arduino micro-controller
Host our laptop

Software: JavaScript

					
var five = require('johnny-five')
var pixel = require('node-pixel')
var board = new five.Board({ port: 8000 })

board.on('ready', function() {
  ring = new pixel.Strip({
    data: 6,
    length: 60,
    color_order: pixel.COLOR_ORDER.GRB,
    board: this,
    controller: 'FIRMATA',
  })

  ring.on('ready', function() {
    app.get('/red', function(req, res) {
      ring.color('#100')
      ring.show()
      res.redirect('/')
    })
...
					
				

Examples of Firmata

JS lib Firmata Hardware
node pixel node pixel Neopixel
johnny-five StandardFirmataPlus plenty!
johnny-five PingFirmata hc-sr04 proximity
particle-io voodootiki particle photon

Use nodebots-interchange to flash
custom firmata in your boards!

Explore

  • Beaglebone Bonescript Github page
  • GPIO node lib for Linux boards
  • Tessel.io website
  1. 3
    WiFi animated logo
    JS Logo

    Hardware talking to the JavaScript server:
    IoT Platform

Wireless Technologies

Wireless Gateway Range Power Data rate
BLE Laptop medium low low
WiFi Router medium high high
4G Cell Tower wide high high
LoRaWAN Receivers wide low low
NB IoT Cell towers wide low low

Low cost, low powered sensors running for years

IoT platforms talk to devices via the Internet protocol through gateways

Demo

IoT platform: get sensor data, visualise data, interpret data

Hardware: TI Sensor Tag

Neopixel with Arduino board
TI Sensor tag Low powered BLE platform with sensors
Server laptop or mobile with BLE capabilities

Software: Node.js

						
var SensorTag = require('sensortag')
var app = require('express')()
var async = require('async')
var WebSocketServer = require('ws').Server
...
SensorTag.discover(function(sensorTag) {
   async.series([
      function(callback) {
        console.log('Connected to Sensor Tag')
        sensorTag.connectAndSetUp(callback)
      },

      function(callback) { sensorTag.enableIrTemperature(callback); },
      function(callback) { setTimeout(callback, 2000); },
      function(callback) {
        sensorTag.readIrTemperature(function(error, objectTemperature, ambientTemperature) {
          console.log('Temperature = %d °C', ambientTemperature.toFixed(1))
          callback();
        });
...
						
				

Explore: IoT Platform

  • Thingspeak website
  • AWS IoT website
  • Google Iot platform
  1. 1
    JS Logo

    running on single-board computers or micro-controllers

  2. 2
    JS Logo

    communicating over firmata with boards and hardware

  3. 3
    WiFi animated logo
    JS Logo

    talking to wireless sensors via the Internet through gateways

Alice talking to the Cheshire cat

One day Alice came to a fork in the road and saw a Cheshire cat in the tree.

"Which road should I take?" she asked.

"Where do you want to go?" was his response.

"I don't know" Alice answered.

"Then", said the cat,
"it doesn't matter"

Have a
fun adventure with JavaScript and Hardware!

References & Credits 📚

  1. Tessel 2 servo example
  2. Digital-first vs Physical-first
  3. Adafruit Neopixel Uberguide
  4. TI Sensor Tag hardware

Danke!

Slides: talks.sayanee/alice

Demo code: GitHub