Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Lyza Danger Gardner

FrontFest
November 21, 2017

Lyza Danger Gardner

FrontFest

November 21, 2017
Tweet

More Decks by FrontFest

Other Decks in Programming

Transcript

  1. JavaScript on Things A Web Developer’s Introduction to Electronics Lyza

    Danger Gardner @lyzadanger FrontFest Moscow, 2017
  2. Software + hardware ★ JavaScript ★ Web standards ★ Web

    development workflows ★ electronic components ★ embedded systems
  3. EMBEDDED SYTEM: ★ processor ★ I/O capabilities ★ program storage

    (ROM) ★ designed to do one thing ★ power-efficient ★ small, “embedded” MCU
  4. 3 WAYS:host-client ★ constrained 8-bit MCU ★ only 2k ROM

    for programs ★ cannot run JS or Node.js directly Arduino Uno R3 ATMega 328P MCU
  5. 3 WAYS: embedded JavaScript ★ constrained microcontrollers ★ optimized subset

    of JavaScript ★ not usually a full OS Espruino Pico STM32F401CDU6 ARM Cortex M4
  6. 3 WAYS:Single-board computers (SBCs) Raspberry Pi 3, Model B ★

    powerful, runs “real” OS ★ I/O support (pins) ★ sometimes overwhelming for beginners Quad Core 1.2GHz Broadcom BCM2837
  7. index.js const five = require('johnny-five'); const board = new five.Board({

    }); const Tessel = require('tessel-io'); io: new Tessel() board.on('ready', () => { const blinky = new five.Led('A5'); blinky.blink(); });
  8. ★ File -> ★ Examples -> ★ Firmata -> ★

    StandardFirmataPlus Arduino IDE
  9. Arduino Uno 1 2 R3 ATMega 328P MCU 1 USB

    interface 2 Digital I/O pins 3 3
  10. Built-In LED ★ pin 13 has a built-in LED ★

    LED turns on when pin 13 set HIGH ★ no need to build LED circuit
  11. index.js const five = require('johnny-five'); const board = new five.Board();

    board.on('ready', () => { const blinkyLED = new five.Led(13);
  12. const five = require('johnny-five'); const board = new five.Board(); board.on('ready',

    () => { const blinkyLED = new five.Led(13); blinkyLED.blink(); }); index.js
  13. ★ host and client communicate using firmata ★ Johnny-Five API

    includes “component classes” like Led ★ LED only blinks while host is running script Recap: Hello, World
  14. index.js const five = require(‘johnny-five'); const board = new five.Board();

    board.on('ready', () => { const blinkyLED = new five.Led(13); blinkyLED.blink(); }); const Tessel = require('tessel-io');
  15. index.js const five = require(‘johnny-five'); const board = new five.Board({

    }); board.on('ready', () => { const blinkyLED = new five.Led(13); blinkyLED.blink(); }); const Tessel = require('tessel-io'); io: new Tessel()
  16. index.js const five = require(‘johnny-five'); const board = new five.Board({

    }); board.on('ready', () => { const blinkyLED = new five.Led(13); blinkyLED.blink(); }); const Tessel = require('tessel-io'); io: new Tessel()
  17. index.js const five = require(‘johnny-five'); const board = new five.Board({

    }); board.on('ready', () => { const blinkyLED = new five.Led(“L1”); blinkyLED.blink(250); }); const Tessel = require('tessel-io'); io: new Tessel()
  18. $ t2 run index.js INFO Looking for your Tessel... INFO

    Connected to brightspot. INFO Building project. INFO Writing project to RAM on brightspot (1318.912 kB)... INFO Deployed. INFO Running index.js... 1510090718990 Available Tessel 2 (brightspot) 1510090719161 Connected Tessel 2 (brightspot) 1510090719219 Repl Initialized >> terminal
  19. index.js const five = require('johnny-five'); const Tessel = require('tessel-io'); const

    board = new five.Board({ io: new Tessel() }); board.on('ready', () => { const blinkyLED = new five.Led('L1'); blinkyLED.blink(250); }); const blinkyLED2 = new five.Led('L2'); blinkyLED2.blink(500);
  20. Arduino Uno 1 2 R3 ATMega 328P MCU 1 USB

    interface 2 Digital I/O pins 3 3 4 4 4 Power pins
  21. Arduino Uno 1 2 R3 ATMega 328P MCU 1 USB

    interface 2 Digital I/O pins 3 3 4 4 4 Power pins
  22. index.js const five = require('johnny-five'); const board = new five.Board();

    board.on('ready', () => { const blinkyLED = new five.Led(13); blinkyLED.blink(); });
  23. index.js const five = require('johnny-five'); const board = new five.Board();

    board.on('ready', () => { const blinkyLED = new five.Led(5); blinkyLED.blink(); });
  24. Port A Port B A0 A1 A2 A3 A4 A5

    A6 A7 B0 B1 B2 B3 B4 B5 B6 B7 GND +3.3V GND +3.3V
  25. A5

  26. index.js const five = require(‘johnny-five'); const Tessel = require('tessel-io'); const

    board = new five.Board({ io: new Tessel() }); board.on('ready', () => { const blinkyLED = new five.Led(“L1”); blinkyLED.blink(250); });
  27. index.js const five = require(‘johnny-five'); const Tessel = require('tessel-io'); const

    board = new five.Board({ io: new Tessel() }); board.on('ready', () => { const blinkyLED = new five.Led(“A5”); blinkyLED.blink(250); });
  28. $ t2 run index.js INFO Looking for your Tessel... INFO

    Connected to brightspot. INFO Building project. INFO Writing project to RAM on brightspot (1318.912 kB)... INFO Deployed. INFO Running index.js... 1510090718990 Available Tessel 2 (brightspot) 1510090719161 Connected Tessel 2 (brightspot) 1510090719219 Repl Initialized >> terminal
  29. index.js const five = require(‘johnny-five'); const Tessel = require('tessel-io'); const

    board = new five.Board({ io: new Tessel() }); board.on('ready', () => { const blinkyLED = new five.Led(“A5”); blinkyLED.blink(250); });
  30. index.js const five = require(‘johnny-five'); const Tessel = require('tessel-io'); const

    board = new five.Board({ io: new Tessel() }); board.on('ready', () => { const blinkyLED = new five.Led(“A5”); blinkyLED.pulse(); });
  31. $ t2 run index.js INFO Looking for your Tessel... INFO

    Connected to brightspot. INFO Building project. INFO Writing project to RAM on brightspot (1318.912 kB)... INFO Deployed. INFO Running index.js... 1510090718990 Available Tessel 2 (brightspot) 1510090719161 Connected Tessel 2 (brightspot) 1510090719219 Repl Initialized >> terminal
  32. PWM

  33. Arduino Uno 1 2 R3 ATMega 328P MCU 1 USB

    interface 2 Digital I/O pins 3 3 4 4 4 Power pins
  34. Arduino Uno 1 2 R3 ATMega 328P MCU 1 USB

    interface 2 Digital I/O pins 3 3 4 4 4 Power pins ~ PWM
  35. Port A Port B A0 A1 A2 A3 A4 A5

    A6 A7 B0 B1 B2 B3 B4 B5 B6 B7 GND +3.3V GND +3.3V Tessel 2 ~ ~
  36. index.js const five = require('johnny-five'); const board = new five.Board();

    const colors = [ '#ff0000', // red '#ff7f00', // orange '#ffff00', // yellow '#00ff00', // green '#0000ff', // blue '#4b0082', // indigo '#9400D3' // violet ];
  37. index.js ‘#ff0000', // red '#ff7f00', // orange '#ffff00', // yellow

    '#00ff00', // green '#0000ff', // blue '#4b0082', // indigo '#9400D3' // violet ]; const five = require('johnny-five'); const board = new five.Board(); const colors = [
  38. index.js ‘#ff0000', // red '#ff7f00', // orange '#ffff00', // yellow

    '#00ff00', // green '#0000ff', // blue '#4b0082', // indigo '#9400D3' // violet ]; const five = require('johnny-five'); const board = new five.Board(); const colors = [ board.on('ready', () => { const rgb = new five.Led.RGB({ pins: [3, 5, 6] }); var colorIndex = 0; setInterval(() => { rgb.color(colors[colorIndex]); colorIndex++; if (colorIndex >= colors.length) { colorIndex = 0; } }, 1000); });
  39. index.js board.on('ready', () => { const rgb = new five.Led.RGB({

    pins: [3, 5, 6] }); var colorIndex = 0; setInterval(() => { rgb.color(colors[colorIndex]); colorIndex++; if (colorIndex >= colors.length) { colorIndex = 0; } }, 1000); });
  40. ADC

  41. Arduino Uno 1 2 R3 ATMega 328P MCU 1 USB

    interface 2 Digital I/O pins 3 3 4 4 4 Power pins ~ PWM 5 Analog in (ADC) 5
  42. index.js const five = require('johnny-five'); const board = new five.Board();

    board.on('ready', () => { }); const thermo = new five.Thermometer({ controller: 'TMP36', pin: 'A0' }); thermo.on('change', () => { console.log(`${thermo.celsius}°C`); });
  43. $ node index.js 1510087983163 Available /dev/cu.usbmodem1411 1510087983197 Connected /dev/cu.usbmodem1411 1510087984798

    Repl Initialized >> 22.84°C 21.28°C 21.31°C 21.36°C 21.38°C 21.4°C 21.42°C 21.44°C 21.46°C 21.48°C 21.47°C 21.49°C 21.5°C terminal
  44. Arduino Uno 1 2 R3 ATMega 328P MCU 1 USB

    interface 2 Digital I/O pins 3 3 4 4 4 Power pins ~ PWM 5 Analog in (ADC) 5 TTL Serial (RX 0, TX 1) 6 6
  45. Arduino Uno 1 2 R3 ATMega 328P MCU 1 USB

    interface 2 Digital I/O pins 3 3 4 4 4 Power pins ~ PWM 5 Analog in (ADC) 5 TTL Serial (RX 0, TX 1) 6 6
  46. Arduino Uno 1 2 R3 ATMega 328P MCU 1 USB

    interface 2 Digital I/O pins 3 3 4 4 4 Power pins ~ PWM 5 Analog in (ADC) 5 TTL Serial (RX 0, TX 1) 6 6 ★ Software Serial (firmata; TX 10, RX 11) 6
  47. index.js const five = require('johnny-five'); const board = new five.Board();

    board.on('ready', function () { }); const gps = new five.GPS([11, 10]); board.repl.inject({ gps: gps });
  48. Arduino Uno 1 2 R3 ATMega 328P MCU 1 USB

    interface 2 Digital I/O pins 3 3 4 4 4 Power pins ~ PWM 5 Analog in (ADC) 5 TTL Serial (RX 0, TX 1) 6 6 ★ Software Serial (firmata; TX 10, RX 11) 6 7 7 I2C Serial (SCL A5, SDA A4)
  49. Port A Port B A0 A1 A2 A3 A4 A5

    A6 A7 B0 B1 B2 B3 B4 B5 B6 B7 GND +3.3V GND +3.3V Tessel 2 SCL SDA SCL SDA
  50. const five = require(‘johnny-five'); const Tessel = require('tessel-io'); const board

    = new five.Board({ io: new Tessel() }); board.on('ready', () => { }); index.js weatherSensor.on('change', () => { console.log(weatherSensor.thermometer.C); console.log(weatherSensor.barometer.pressure); }); const weatherSensor = new five.Multi({ controller: 'BMP180' });
  51. JavaScript on Things ★ coming holiday season 2017! ★ available

    in e-Book prerelease now https://www.manning.com/books/javascript-on-things