Becoming a maker: Microcontrollers

AND JAVASCRIPT USING JOHNNY-FIVE

Who am I?

Matt Webb

Front End Developer at Blinker

 

github: creatifyme

twitter: @creatify_me

We are all makers

  • Makers are enthusiasts, amateurs, DIY'ers, recyclers, reuse'ers, and crafters.
  • Makers always asking themselves "Can I do it? Can it be done?"
  • The talk is label "Becoming a maker" but really we are all makers.

?

  • Who here considers themselves a maker?
  • Do you know JavaScript and not C?
  • Own/tinkered with Arduino/Raspberry Pi or other microcontroller boards?

The Sandlot

The Sandlot

Sashimi Tabernacle Choir

Mk. II MegaBot

five finger fillet Machine

My Maker Background

  • High school class making Lego robots
  • Building Computers
  • Took a soldering class
  • Made a few custom PC cases
  • Wood working
  • Tinkering with Arduinos and JS

What will be covered?

  • What's a microcontroller?
  • What hardware basics should you learn?
  • What's Johnny-Five.js?
  • Setting Johnny Five up with Arduino
  • Arduino Demos
  • Setting Johnny-Five up with Tessel 2  
  • Tessel 2 Demos

What's A microcontroller?

A microcontroller is a small computer on a single integrated circuit containing a processor core, memory, and programmable input/output peripherals.

arduino vs Tessel 2

Arduino

  • Open-sourced
  • Has an IDE
  • Simplified version of C++
  • Can run Node.js/Johnny-five after installing the Firmata protocol 
  • CAN'T run a Node.js app without a computer
  • Perfect for rapid prototyping on the cheap

Tessel 2

  • Open-sourced
  • Linux
  • Runs Node.js out of the box
  • CAN run Node.js applications without a computer
  • Pre-made/configured modules/shields
  • Perfect for rapid prototyping and production ready 

Shopping list

Arduino

Tessel 2

What Hardware Basics Should I learn?

What Hardware Basics Should I learn?

  • Electronics Primer - learn basic hardware components and their purpose like resistors, motors, relay, etc...
  • How to use a breadboard - best friend for prototyping without soldering
  • Soldering(is fun) and De-soldering(sucks, takes practice)
  • Multimeter - nifty tool for debugging

Hello, Johnny-five!

What is Johnny-Five?

  • Open source JS robotics programming framework
  • Created by Rick Waldron in 2012
  • Maintained by a community of passionate software developers and hardware engineers
  • Community is super duper nice and noob friendly

Why Johnny-Five?

  • You don't have to learn C
  • No Compiling - just run `node blahfile.js` in terminal and/or REPL for debugging/experimenting 
  • Most popular JS robotics framework
  • Atwood’s Law - any application that can be written in JavaScript will eventually be written in JavaScript.
  • Ummm cause why not?

Johnny-Five community = Awesomesauce

Setting Up Arduino & J5 - Part 1

  1. Download Arduino IDE
  2. Connect your Arduino-compatible microcontroller via USB
  3. Launch Arduino IDE and open the Firmata sketch via the menu: File > Examples > Firmata > StandardFirmata
  4. Select your Arduino board type (e.g. Arduino Uno) via Tools > Board
  5. Select the port for your board via Tools > Serial Port > (the comm port of your Arduino)
  6. Upload the program by selecting File > Upload
  7. Close the Arduino IDE and then...

Setting Up Arduino & J5 - Part 1.5

  1. Install Node JS
  2. Make a new project folder
  3. npm init (follow prompts)
  4. npm install --save johnny-five

Setting Up Arduino & J5 - Part 2

Arduino + J5 = DEMOs!!!!

Hello World - Blinking led - Code

var five = require('johnny-five');
var board = new five.Board();

board.on('ready', function() {
  var led = new five.Led(11);

  // This will grant access to the led instance
  // from within the REPL that's created when
  // running this program.
  this.repl.inject({
    led: led
  });

  led.blink();
});

Hello World - BLINKING LED - layout

Hello World - BLINKING LED - In Action

Button - Code

var five = require('johnny-five');
var board = new five.Board();
var button;
var led;

board.on('ready', function() {
    led = new five.Led(11);

    // Create a new `button` hardware instance.
    // This example allows the button module to
    // create a completely default instance
    button = new five.Button(2);

    // Inject the `button` hardware into
    // the Repl instance's context;
    // allows direct command line access
    board.repl.inject({
      button: button,
      led: led
    });

    // Button Event API

    // "down" the button is pressed
    button.on('down', function() {
      console.log('down');
      led.brightness(255);
    });

    button.on('hold', function() {
      console.log('hold');
      led.blink(500);
    });

    // "up" the button is released
    button.on('up', function() {
      console.log('up');
      led.stop(); // Stops the blinking
      led.brightness(0);
    });
});

Button - Layout

Button - In Action

JOYSTICK PAN-TILT  - Code

var five = require('johnny-five');
var board = new five.Board();

board.on('ready', function() {
    var range = [
      0,
      180
    ];

    // Servo to control panning
    var pan = new five.Servo({
      pin: 9,
      range: range
    });

    // Servo to control tilt
    var tilt = new five.Servo({
      pin: 10,
      range: range
    });

    // Joystick to control pan/tilt
    // Read Analog 0, 1
    // Limit events to every 100ms
    var joystick = new five.Joystick({
      pins: [
        'A0',
        'A1'
      ],
      freq: 100
    });

    tilt.center();
    pan.center();

    joystick.on('change', function() {
      console.log('y: ', this.y);
      console.log('x: ', this.x);

      tilt.to(five.Fn.scale(this.y, -1, 1, 0, 170));
      pan.to(five.Fn.scale(this.x, -1, 1, 0, 170));
    });
});

JOYSTICK PAN-TILT  - Layout

JoyStick Pan-tilt - In Action

  1. Install Node JS
  2. npm install -g t2-cli
  3. Make a new project folder
  4. t2 init (in project folder)
  5. npm install --save johnny-five tessel-io

Setting Up Tessel 2 & J5

Tessel 2 + J5 = DEMOs!!!!

Need ideas? Here is 

  • House Automation
  • Nerf Turret
  • NodeBot
  • Home Arcade
  • Home Brewing
  • Halloween Costumes
  • Art Installations
  • 3d Printers
  • Just Use Your....

Build It and The ideas Will Come

PSsT, Who's Your Dealer?

Who to buy from?

  • SparkFun - Good prices, close by just past Boulder
  • Adafruit - great products and prices
  • MicroCenter - convenient but more expensive
  • RadioShack - believe it or not they still have stuff even bot kits

Questions?

Becoming a maker: Microcontrollers & JavaScript using Johnny-Five

By Matt Webb

Becoming a maker: Microcontrollers & JavaScript using Johnny-Five

  • 1,567