nodebots presentation @seekjobs
TRANSCRIPT
nodebots
Steven de SalasJavaScript Developer
What is this talk about?
• 30 minutes • Robots
– Hardware Parts, Electronics, Fabrication, Power– Microcontrollers vs Microprocessors (lots!)
• NodeJS & JavaScript– Using Node to talk to USB, Bluetooth, Firmata– JS Libraries, other languages.
• Quick Demo• Getting Started
What is nodebots?
• It’s a meetup. • That takes place in a
few cities. • For people who like to
make robots. • And who like
JavaScript.
nodebots day 2016
nodebots day 2016
Sumo bot fighting
nodebots day 2016
That’s Andrew, He runs the (Melbourne) meetup
Robots
Robots
What does it What does it taketake to build to build one?one?
Robots
Lets take one apart.Lets take one apart.
Robots
Robots
What do we have?
What do we have?
Frame
What do we have?
MotorisedWheels
What do we have?
Batteries
What do we have?
Jumper Leads
What do we have?
Breadboard
What do we have?
Rubber Bands
What do we have?
Blue Tac
What do we have?
Zip Ties
What do we have?
Sensors
What do we have?
Brain(Microcontroller)
What do we have?
Brain(Microcontroller)
Modern Day Applied Electronics
✓X
What is a Microcontroller?
• Like a small computerwithout an O/S
What is a Microcontroller?
What is a Microcontroller?
• Like a small computerwithout an O/S
• Physical computing
What is a Microcontroller?
• Like a small computerwithout an O/S
• Physical computing• Runs a piece of code
over and over again
What is a Microcontroller?
• Like a small computerwithout an O/S
• Physical computing• Runs a piece of code
over and over again• Receive and send
electrical signals
What is a Microcontroller?
• Like a small computerwithout an O/S
• Physical computing• Runs a piece of code
over and over again• Receive and send
electrical signals• Turns things on and off
What is a Microcontroller?
• Like a small computerwithout an O/S
• Physical computing• Runs a piece of code
over and over again• Receive and send
electrical signals• Turns things on and off
2Kb RAM, 16 MHz
What is a Microcontroller?
• Like a small computerwithout an O/S
• Physical computing• Runs a piece of code
over and over again• Receive and send
electrical signals• Turns things on and off
2Kb RAM, 16 MHz
Phenomenal Cosmic Powers !!!
Processing Power vs 80s Consumer Devices
16
2
32
1.88 8
1
64
208
128
64
0
20
40
60
80
100
120
140
Arduino UNO Atari 800 Comm 64 Mac 128K
CPU (MHz)RAM (Kb)Flash (Kb)
Processing Powervs Today’s Consumer Devices
16
2
32
1GHz
1Gb
8Gb 2,4GHz
2Gb
32Gb 1,4GHz
1Gb
64Gb
0
20
40
60
80
100
120
140
Arduino UNO RasPi 3B Galaxy S5 iPhone 6
CPU (MHz)RAM (Kb)Flash (Kb)
Processing Powervs Today’s Consumer Devices
16
2
32
1GHz
1Gb
8Gb 2,4GHz
2Gb
32Gb 1,4GHz
1Gb
64Gb
0
20
40
60
80
100
120
140
Arduino UNO RasPi 3B Galaxy S5 iPhone 6
CPU (MHz)RAM (Kb)Flash (Kb)
What about Moore’s Law?Microcontrollers do not appear to follow it.
Programming a Microcontroller
• C++, no garbage collection • Program big? Cannot fit• Long strings = out of memory• Array resizing? (Mem Pointers)
Academically interesting
Programming a Microcontroller
• C++, no garbage collection • Program big? Cannot fit• Long strings = out of memory• Array resizing? (Mem Pointers)
In practice:• SD Storage = tricky• Wifi = good luck• HTTPS = no luck
Academically interesting
Archaic
Why not use a proper computer instead?
• No Analog Sensors• No PWM• Cannot drive motors• Will fry at high loads
In Short: Great for processing, not
good for manipulating electricity.
Raspberry Pi 3B
CPU 1GHzRAM 1GbLanguages AnyStorage To 64 GbConnectivity Wifi, HTTPs
Microcontroller vs Microprocessor
• No O/S• Low RAM, no HD / network• Rugged• More power (200 mA)• Digital & Analog• Speaks C++
• Runs Linux• Lots RAM, HD + Network• Delicate • Less Power (50 mA)• Digital Only• Speaks Everything
Microcontroller vs Microprocessor
• No O/S• Low RAM, no HD / network• Rugged• More power (200 mA)• Digital & Analog• Speaks C++
• Runs Linux• Lots RAM, HD + Network• Delicate • Less Power (50 mA)• Digital Only• Speaks Everything
How about we put them together?
How about we put them together?
USB
How about we put them together?
SLAVEHandles theElectronics
MASTERReviews dataCoordinates &Makes decisions
USB
Two-way Serial communication
How about we put them together?
SLAVEHandles theElectronics
MASTERReviews dataCoordinates &Makes decisions
USB
Two-way Serial communication
How about we put them together?
SLAVEHandles theElectronics
MASTERReviews dataCoordinates &Makes decisions
USB
Two-way Serial communication I RULZ
Communication
var SerialPort = require(‘serialport’).SerialPort;
var usb = new SerialPort(‘/dev/tty0’, { baudrate: 115200});
usb.on(‘open’, function () { console.log('Connected!') usb.write(‘hey buddy, turn on the light');});
USB
Communication
var SerialPort = require(‘serialport’).SerialPort;
var usb = new SerialPort(‘/dev/tty0’, { baudrate: 115200});
usb.on(‘open’, function () { console.log('Connected!') usb.write(‘hey buddy, turn on the light');});
> hey buddy, turn on the light
USB
Communication
var SerialPort = require(‘serialport’).SerialPort;
var usb = new SerialPort(‘/dev/tty0’, { baudrate: 115200});
usb.on(‘open’, function () { console.log('Connected!') usb.write(‘hey buddy, turn on the light');});
> ???> hey buddy, turn on the light
USB
Communication
var SerialPort = require(‘serialport’).SerialPort;
var usb = new SerialPort(‘/dev/tty0’, { baudrate: 115200});
usb.on(‘open’, function () { console.log('Connected!') usb.write(‘hey buddy, turn on the light');});
> ???
$ npm install firmata
> hey buddy, turn on the light
USB
Communication
var SerialPort = require(‘serialport’).SerialPort;
var usb = new SerialPort(‘/dev/tty0’, { baudrate: 115200});
usb.on(‘open’, function () { console.log('Connected!') usb.write(‘hey buddy, turn on the light');});
> ???
$ npm install firmata> Yes Master.
> hey buddy, turn on the light
USB
Communication
var SerialPort = require(‘serialport’).SerialPort;
var usb = new SerialPort(‘/dev/tty0’, { baudrate: 115200});
usb.on(‘open’, function () { console.log('Connected!') usb.write(‘hey buddy, turn on the light');});
> ???
$ npm install firmata> Yes Master.
> hey buddy, turn on the light
Bluetooth = Serial
Running a Servo using C++ (Arduino)
Running a Servo with Johnny Five
var five = require("johnny-five");var board = new five.Board();
board.on("ready", function() {
var servo = new five.Servo({ pin: 10, type: "continuous" });
// Clockwise, top speed. servo.cw(1);});
Johnny Five Library
• npm install johnny-five
• 7K stars, Rick Waldron
• “jQuery for robots”
• Support for many microcontrollers
• Simple, well thought API
• Large community
Running a servo with Cylon JS
var Cylon = require("cylon");
Cylon.robot() .connection("arduino", { adaptor: "firmata", port: "/dev/ttyACM0" }) .device("servo", { driver: "servo", pin: 3 }) .on("ready", function(bot) { var angle = 0;
setInterval(function() { // +20deg every 100ms angle += 20; bot.servo.angle(angle++); }, 100);
}) .start();
Cylon.JS
• npm install cylon
• 2.6K stars
• Many platforms
• Bit haphazard
• Less active community
Do I have to use JavaScript?
Do I have to use JavaScript?
Do I have to use JavaScript?Nope. You just need to talk to the USB Serial Port
Do I have to use JavaScript?
artoo
CORE(LibUsbDotNet)
Nope. You just need to talk to the USB Serial Port
(ruby)
DEMO 1: C++ (only)
DEMO 2: C++ <=> (0.10)
DEMO 3: Firmata <=> johnny-five
DEMO 4: Planetary Domination Robot
DEMO 4: Planetary Domination Robot
PROTOCOL ERROR
My own journey
Nov: Arduino Starter KitDec: Arduino Yun Microcontroller (Linux)
Youtube, basic Experiments, Wifi, control via Mobile App.
2016Jan: NodeJS, Sound bot.Mar: Move to MelbourneJul: Nodebots Day. First Nodebot.
2015Aug: Zero knowledge.Sep: Electromagnets,Electronics for dummies
(eBay: $75Second-hand)
Aug: Raspberry Pi 3B. Refinements.Oct: Second Robot. Third robot.
Getting Started
Andrew Fisher https://github.com/ajfisher Chief Tinkerer
Nodebots AU Meetup(Hawthorn)Community Hackerspace First Wed of every month. Arduino Starter Kit
$100 (amazon)
Johnny Fivenode-serialport
npm install serialport npm install johnny-five
EITHER
To Recap
To Recap
1. Robotics => Microcontrollers => C++ code
To Recap
1. Robotics => Microcontrollers => C++ code2. Programming C++ sucks!
To Recap
1. Robotics => Microcontrollers => C++ code2. Programming C++ sucks!3. You can use nodeJS (or any other language)
To Recap
1. Robotics => Microcontrollers => C++ code2. Programming C++ sucks!3. You can use nodeJS (or any other language)4. Just talk to USB / use Firmata or DIY C++
code to tell controller what to do.
To Recap
1. Robotics => Microcontrollers => C++ code2. Programming C++ sucks!3. You can use nodeJS (or any other language)4. Just talk to USB / use Firmata or DIY C++
code to tell controller what to do.5. Added advantage is lots of memory / storage
and networking.
To Recap
1. Robotics => Microcontrollers => C++ code2. Programming C++ sucks!3. You can use nodeJS (or any other language)4. Just talk to USB / use Firmata or DIY C++
code to tell controller what to do.5. Added advantage is lots of memory / storage
and networking.6. Go to Nodebots AU meetup to find out more.
To Recap
1. Robotics => Microcontrollers => C++ code2. Programming C++ sucks!3. You can use nodeJS (or any other language)4. Just talk to USB / use Firmata or DIY C++
code to tell controller what to do.5. Added advantage is lots of memory / storage
and networking.6. Go to Nodebots AU meetup to find out more.7. Build some cool s**t! Because you can!
nodebots day 2016
Sumo bot fighting
THANKS!!!
Steven de Salas https://github.com/sdesalas Apprentice Tinkerer
Nodebots AU Meetup(Hawthorn)Community Hackerspace First Wed of every month. Arduino Starter Kit
$100 (amazon)
Johnny Fivenode-serialport
npm install serialport npm install johnny-five