Upload
alexander-roche
View
109
Download
1
Tags:
Embed Size (px)
DESCRIPTION
Hardware Hacking using the Raspberry Pi and NodeJS with a bit of general knowledge thrown in.
Citation preview
HARDWARE HACKING AND THE RASPBERRY PI; WHAT'S JAVASCRIPT GOT TO DO WITH IT?
ALEX ROCHE@alexHacked
HARDWARE HACKING; WAT?
HARDWARE HACKING; WAT?
• We take electronics and bend them to our will
HARDWARE HACKING; WAT?
• We take electronics and bend them to our will
• Can use any component, as long as it can be soldered
HARDWARE HACKING; WAT?
• We take electronics and bend them to our will
• Can use any component, as long as it can be soldered
• A variety of levels of difficulty and accessibility
HARDWARE HACKING; WHY?
HARDWARE HACKING; WHY?
• Prototyping concepts and systems
HARDWARE HACKING; WHY?
• Prototyping concepts and systems
• Replacing older tech that has failed
HARDWARE HACKING; WHY?
• Prototyping concepts and systems
• Replacing older tech that has failed
• Making something cool
HARDWARE HACKING; HOW?
HARDWARE HACKING; HOW?
• A basic knowledge of electronics is definitely helpful
HARDWARE HACKING; HOW?
• A basic knowledge of electronics is definitely helpful
• Skills such as soldering and stripping wires
HARDWARE HACKING; HOW?
• A basic knowledge of electronics is definitely helpful
• Skills such as soldering and stripping wires
• GPIO pins; GPIO pins everywhere!
HARDWARE HACKING; HOW?
• A basic knowledge of electronics is definitely helpful
• Skills such as soldering and stripping wires
• GPIO pins; GPIO pins everywhere!
• No 'correct' or 'right' way
HARDWARE HACKING; HOW?
• A basic knowledge of electronics is definitely helpful
• Skills such as soldering and stripping wires
• GPIO pins; GPIO pins everywhere!
• No 'correct' or 'right' way
• Be safe and have respect for electricity
HARDWARE HACKING; WHEN?
HARDWARE HACKING; WHEN?
• Creating projects to react solely to electricity
HARDWARE HACKING; WHEN?
• Creating projects to react solely to electricity
• Using timing chips, resistors and circuit boards
HARDWARE HACKING; WHEN?
• Creating projects to react solely to electricity
• Using timing chips, resistors and circuit boards
• Programmable micro controllers
HARDWARE HACKING; WHEN?
• Creating projects to react solely to electricity
• Using timing chips, resistors and circuit boards
• Programmable micro-controllers
• Micro-controllers on an integrated platform
ALL THE OPTIONS!
• A lot of options for a lot of different skill levels
ALL THE OPTIONS!
• A lot of options for a lot of different skill levels
• Little Bits
ALL THE OPTIONS!
• A lot of options for a lot of different skill levels
• Little Bits
• Makey Makey
ALL THE OPTIONS!
• A lot of options for a lot of different skill levels
• Little Bits
• Makey Makey
• Arduino
ALL THE OPTIONS!
• A lot of options for a lot of different skill levels
• Little Bits
• Makey Makey
• Arduino
• Raspberry Pi
LITTLE BITS
LITTLE BITS
LITTLE BITS
• Individual, pre-formed components
LITTLE BITS
• Individual, pre-formed components
• Held together with magnets
LITTLE BITS
• Individual, pre-formed components
• Held together with magnets
• Different colours to help design a circuit
LITTLE BITS; A BIT USEFUL?
LITTLE BITS; A BIT USEFUL?
• Extremely Modular
LITTLE BITS; A BIT USEFUL?
• Extremely Modular
• Incredibly Hands On
LITTLE BITS; A BIT USEFUL?
• Extremely Modular
• Incredibly Hands On
• Makes exploring hardware simple and fun
LITTLE BITS; A BIT USEFUL?
• Extremely Modular
• Incredibly Hands On
• Makes exploring hardware simple and fun
• Best for proof of concepts and toying with new ideas
MAKEYMAKEY
MAKEYMAKEY
• Plug and Play with your computer
MAKEYMAKEY
• Plug and Play with your computer
• Acts as a Keyboard
MAKEYMAKEY
• Plug and Play with your computer
• Acts as a Keyboard
• Plug and clip wires in to the board to complete a circuit
MAKEYMAKEY; MAKES THINGS COOL?
MAKEYMAKEY; MAKES THINGS COOL?
• Binary Input
MAKEYMAKEY; MAKES THINGS COOL?
• Binary Input
• Easy way to hack together basic interaction
MAKEYMAKEY; MAKES THINGS COOL?
• Binary Input
• Easy way to hack together basic interaction
• Key Events can be used to detect interaction
ARDUINO
ARDUINO
• Microcontroller on a circuitboard
ARDUINO
• Microcontroller on a circuitboard
• GPIO pins
ARDUINO
• Microcontroller on a circuitboard
• GPIO pins
• Programmable over USB
ARDUINO
• Microcontroller on a circuitboard
• GPIO pins
• Programmable over USB
• Can run Javascript and NodeJS
ARDUINO; OPEN SOURCE MEANS OPEN OPTIONS
ARDUINO; OPEN SOURCE MEANS OPEN OPTIONS
• Arduino UNO
ARDUINO; OPEN SOURCE MEANS OPEN OPTIONS
• Arduino UNO
• Arduino Mega
ARDUINO; OPEN SOURCE MEANS OPEN OPTIONS
• Arduino UNO
• Arduino Mega
• Arduino Lilypad
ARDUINO; OPEN SOURCE MEANS OPEN OPTIONS
• Arduino UNO
• Arduino Mega
• Arduino Lilypad
• Open Source; can be reproduced by anybody with the right components
ARDUINO; HOW TO CODE
ARDUINO; HOW TO CODE
• IDE based on translating simple code to C++
ARDUINO; HOW TO CODE
• IDE based on translating simple code to C++
• BreakoutJS; Javascript and Web Browser interactivity
ARDUINO; HOW TO CODE
• IDE based on translating simple code to C++
• BreakoutJS; Javascript and Web Browser interactivity
• Johnny Five; Node based framework
RASPBERRY PI; TASTY!
RASPBERRY PI; TASTY!
• A computer (and then some)
RASPBERRY PI; TASTY!
• A computer (and then some)
• GPIO pins
RASPBERRY PI; TASTY!
• A computer (and then some)
• GPIO pins
• Has all the hardware needed for a computer onboard
RASPBERRY PI; TASTY!
• A computer (and then some)
• GPIO pins
• Has all the hardware needed for a computer onboard
• Runs a boatload of operating systems
RASPBERRY PI; TASTY!
• A computer (and then some)
• GPIO pins
• Has all the hardware needed for a computer onboard
• Runs a boatload of operating systems
• GPIO pins are easily addressable
RASPBERRY PI; CHOICES!
RASPBERRY PI; CHOICES!
• Two Different Types
RASPBERRY PI; CHOICES!
• Two Different Types
• Model A
RASPBERRY PI; CHOICES!
• Two Different Types
• Model A
• Model B
RASPBERRY PI; MODEL A
RASPBERRY PI; MODEL A
• Single USB
RASPBERRY PI; MODEL A
• Single USB
• 256MB RAM
RASPBERRY PI; MODEL A
• Single USB
• 256MB RAM
• Audio & RCA video output
RASPBERRY PI; MODEL A
• Single USB
• 256MB RAM
• Audio & RCA video output
• HDMI output
RASPBERRY PI; MODEL A
• Single USB
• 256MB RAM
• Audio & RCA video output
• HDMI output
• 26 GPIO pins
RASPBERRY PI; MODEL A
• Single USB
• 256MB RAM
• Audio & RCA video output
• HDMI output
• 26 GPIO pins
• Runs Minecraft!
RASPBERRY PI; MODEL B
RASPBERRY PI; MODEL B
• 2 USB Connectors
RASPBERRY PI; MODEL B
• 2 USB Connectors
• 512MB RAM
RASPBERRY PI; MODEL B
• 2 USB Connectors
• 512MB RAM
• Ethernet Jack
RASPBERRY PI; MODEL B
• 2 USB Connectors
• 512MB RAM
• Ethernet Jack
• 34 GPIO pins
RASPBERRY PI; MODEL B
• 2 USB Connectors
• 512MB RAM
• Ethernet Jack
• 34 GPIO pins
• Additional 8 are mostly unused; supply power and ground
RASPBERRY PI; GPIO MAPPING
RASPBERRY PI; GPIO MAPPING
RASPBERRY PI; GPIO MAPPING
RASPBERRY PI; WHY?
RASPBERRY PI; WHY?
• More Processing Power
RASPBERRY PI; WHY?
• More Processing Power
• Onboard Storage
RASPBERRY PI; WHY?
• More Processing Power
• Onboard Storage
• Freedom of Language Choice
RASPBERRY PI; WHY?
• More Processing Power
• Onboard Storage
• Freedom of Language Choice
• Easily configured Internet Access
RASPBERRY PI; WHY?
• More Processing Power
• Onboard Storage
• Freedom of Language Choice
• Easily configured Internet Access
• Runs any code you write for it on the board instead of tethered to a computer
RASPBERRY PI; WHY NOT?
• Less battery life than an Arduino
RASPBERRY PI; WHY NOT?
• Less battery life than an Arduino
• Can be cumbersome to set up and program
RASPBERRY PI; WHY NOT?
• Less battery life than an Arduino
• Can be cumbersome to set up and program
• Doesn’t have as much of a support for shields
SHIELDS?
SHIELDS?
• Pre created circuit boards that extend functionality
SHIELDS?
• Pre created circuit boards that extend functionality
• Can use multiple shields at once ...
SHIELDS?
• Pre created circuit boards that extend functionality
• Can use multiple shields at once ...
• ... though like using multiple of anything at once, take care.
NODE; WHAT IS IT?
NODE; WHAT IS IT?
• A familiar flavour of Javascript; people already know it!
NODE; WHAT IS IT?
• A familiar flavour of Javascript; people already know it!
• Non Blocking I/O
NODE; WHAT IS IT?
• A familiar flavour of Javascript; people already know it!
• Non Blocking I/O
• Event Driven using callbacks
NODE; WHAT IS IT?
• A familiar flavour of Javascript; people already know it!
• Non Blocking I/O
• Event Driven using callbacks
• Operating System Agnostic (mostly)
NODE; WHY IS IT COOL?
NODE; WHY IS IT COOL?
• Incorporates Google’s V8 Engine for speed
NODE; WHY IS IT COOL?
• Incorporates Google’s V8 Engine for speed
• Has some really fun functions
NODE; WHY IS IT COOL?
• Incorporates Google’s V8 Engine for speed
• Has some really fun functions
• Crypto, OS, FS
NODE; WHY IS IT COOL?
• Incorporates Google’s V8 Engine for speed
• Has some really fun functions
• Crypto, OS, FS
• Has a massive amount of external libraries to augment it
NODE; WHY IS IT COOL?
• Incorporates Google’s V8 Engine for speed
• Has some really fun functions
• Crypto, OS, FS
• Has a massive amount of external libraries to augment it
• A server side language front end developers can write!
NODE; HOW TO INSTALL? LINUX
NODE; HOW TO INSTALL? LINUX
> wget http://nodejs.org/dist/v.0.8.11/node-v0.8.11.tar.gz > tar -zxf node-v0.8.11.tar.gz > cd node-v0.8.11 > ./configure > make > sudo make install
NODE; HOW TO INSTALL? MAC & WINDOWS
NODE; HOW TO INSTALL? MAC & WINDOWS
• Much more simple and straightforward than Linux
NODE; HOW TO INSTALL? MAC & WINDOWS
• Much more simple and straightforward than Linux
• Go get the installer from nodejs.org/download/
NODE; HOW TO INSTALL? MAC & WINDOWS
• Much more simple and straightforward than Linux
• Go get the installer from nodejs.org/download/
• No, really. Download it from there and install it. Job done.
NODE; HOW TO INSTALL? MAC & WINDOWS
• Much more simple and straightforward than Linux
• Go get the installer from nodejs.org/download/
• No, really. Download it from there and install it. Job done.
NODE; HOW TO USE?
NODE; HOW TO USE?
• Write JavaScript!
NODE; HOW TO USE?
• Write JavaScript!
• Watch out for the PHP-esque require(“”); though!
NODE; HOW TO USE?
• Write JavaScript!
• Watch out for the PHP-esque require(“”); though!
• Make use of the inbuilt libraries in NodeJS
NPM; NOT PROBLEMATIC, MOSTLY
NPM; NOT PROBLEMATIC, MOSTLY
• Nodes inbuilt library management tool
NPM; NOT PROBLEMATIC, MOSTLY
• Nodes inbuilt library management tool
• Has its own website listing all of the modules
NPM; NOT PROBLEMATIC, MOSTLY
• Nodes inbuilt library management tool
• Has its own website listing all of the modules
• Makes it incredibly easy to install modules
NPM; HOW TO USE
NPM; HOW TO USE
• It all starts with npm
NPM; HOW TO USE
• It all starts with npm
• Different Keywords; https://npmjs.org/docs
NPM; HOW TO USE
• It all starts with npm
• Different Keywords; https://npmjs.org/docs
• Most useful are install and update
NPM; HOW TO USE
• It all starts with npm
• Different Keywords; https://npmjs.org/docs
• Most useful are install and update
•npm install || npm update
NPM; INSTALLING A MODULE
NPM; INSTALLING A MODULE
• Find the package you want to install on the npm site
NPM; INSTALLING A MODULE
• Find the package you want to install on the npm site
• Run npm install gpio to install the package
NPM; INSTALLING A MODULE
• Find the package you want to install on the npm site
• Run npm install gpio to install the package
•-g flag installs globally instead of locally for command line use
NPM; INSTALLING A MODULE
• Find the package you want to install on the npm site
• Run npm install gpio to install the package
•-g flag installs globally instead of locally for command line use
•require(“gpio”); in your project
NPM; INSTALLING A MODULE
• Find the package you want to install on the npm site
• Run npm install gpio to install the package
•-g flag installs globally instead of locally for command line use
•require(“gpio”); in your project
• npm packages need to be installed in each project’s folder you intend to use them in
BAKING A RASPBERRY PI
BAKING A PI
• We have a lot of choices for the operating system
BAKING A PI
• We have a lot of choices for the operating system
• Linux
BAKING A PI
• We have a lot of choices for the operating system
• Linux
• RISC
BAKING A PI
• We have a lot of choices for the operating system
• Linux
• RISC
• Android
BAKING A PI
• We have a lot of choices for the operating system
• Linux
• RISC
• Android
• FirefoxOS
COOKING THE FILLING
• ç
COOKING THE FILLING
• Windows
• Win32DiskImager
COOKING THE FILLING
• Windows
• Win32DiskImager
• Mac
• RPI sd card builder, PiWriter, Pi Filler
COOKING THE FILLING
• Windows
• Win32DiskImager
• Mac
• RPI sd card builder, PiWriter, Pi Filler
• Linux
• ImageWriter
COOKING THE FILLING
• Windows
• Win32DiskImager
• Mac
• RPI sd card builder, PiWriter, Pi Filler
• Linux
• ImageWriter
COOKING THE FILLING
• Windows
• Win32DiskImager
• Mac
• RPI sd card builder, PiWriter, Pi Filler
• Linux
• ImageWriter
CUTTING IN TO THE PI
CUTTING IN TO THE PI
• First off, we install Adafruit’s Occidentalis distribution
CUTTING IN TO THE PI
• First off, we install Adafruit’s Occidentalis distribution
• We SSH in to the Raspberry Pi
CUTTING IN TO THE PI
• First off, we install Adafruit’s Occidentalis distribution
• We SSH in to the Raspberry Pi
• We connect it to a monitor with keyboard and mouse
CUTTING IN TO THE PI; SSH
CUTTING IN TO THE PI; SSH
• Power it up!
CUTTING IN TO THE PI; SSH
• Power it up!
• Plug an Ethernet cable in to your Pi and your Router
CUTTING IN TO THE PI; SSH
• Power it up!
• Plug an Ethernet cable in to your Pi and your Router
• Run ssh raspberrypi.local on your computer to get to the Pi
CUTTING IN TO THE PI; SSH
• Power it up!
• Plug an Ethernet cable in to your Pi and your Router
• Run ssh raspberrypi.local on your computer to get to the Pi
• Alternatively log in to your router and get the IP of the Pi from there; ssh pi@<ip_of_pi> . Use the password “raspberry”
WIRED IS BORING, RIGHT?!
LETS GO WIRELESS!
CUTTING THE PI LOOSE
CUTTING THE PI LOOSE
• Run sudo nano /etc/network/interfaces
CUTTING THE PI LOOSE
• Run sudo nano /etc/network/interfaces
• Delete the contents of the file
CUTTING THE PI LOOSE
• Run sudo nano /etc/network/interfaces
• Delete the contents of the file
• <- Replace it with this
> auto lo > iface lo inet loopback > iface eth0 inet dhcp > allow-hotplug wlan0 > auto wlan0 > iface wlan0 inet dhcp > wpa-ssid "ssid" > wpa-psk "password"
CUTTING THE PI LOOSE
• Run sudo nano /etc/network/interfaces
• Delete the contents of the file
• <- Replace it with this
• Replace SSID and PASSWORD
> auto lo > iface lo inet loopback > iface eth0 inet dhcp > allow-hotplug wlan0 > auto wlan0 > iface wlan0 inet dhcp > wpa-ssid "ssid" > wpa-psk "password"
BLOWING RASPBERRIES
BLOWING RASPBERRIES
GPIO
API; https://npmjs.org/package/gpio
Manual Setting and Getting
BLOWING RASPBERRIES
Johnny-Five
API; https://github.com/rwaldron/johnny-five/wiki
Function Based System for Arduino
GPIO
API; https://npmjs.org/package/gpio
Manual Setting and Getting for Raspberry Pi
BLOWING RASPBERRIES; SETTING UP A CONTEXT
BLOWING RASPBERRIES; SETTING UP A CONTEXT
GPIO > var gpio = require("gpio"); > >/* Calling export with a pin >number will export that header >and return a gpio header >instance*/ > > var gpio4 = gpio.export(4, { > direction: 'out', > interval: 200, > ready: function() { > } >});
BLOWING RASPBERRIES; SETTING UP A CONTEXT
Johnny-Five > var five = require("johnny- five"), board, led; > > board = new five.Board(); > >board.on("ready", function() { });
GPIO > var gpio = require("gpio"); > >/* Calling export with a pin >number will export that header >and return a gpio header >instance*/ > > var gpio4 = gpio.export(4, { > direction: 'out', > interval: 200, > ready: function() { > } >});
BLOWING RASPBERRIES; MAKING A LIGHT BLINK
BLOWING RASPBERRIES; MAKING A LIGHT BLINK
GPIO >Var strobeTimer = setInterval(function() { > gpio4.set(); > setTimeout( > function(){ > gpio4.reset(); > }, 200); > }, 400); >/*Can also pass a number in to >the >set function.*/
BLOWING RASPBERRIES; MAKING A LIGHT BLINK
Johnny-Five > /* Create a standard `led` >hardware instance*/ > Var led = new five.Led(13); > > /* "strobe" the led in 100ms >on-off phases*/ > led.strobe( 100 );
GPIO >Var strobeTimer = setInterval(function() { > gpio4.set(); > setTimeout( > function(){ > gpio4.reset(); > }, 200); > }, 400); >/*Can also pass a number in to >the >set function.*/
BLOWING RASPBERRIES; GETTING VALUES
BLOWING RASPBERRIES; GETTING VALUES
GPIO >var gpio = require("gpio"); >var gpio4 = gpio.export(4, { > direction: "in", > ready: function() { > Console.log(gpio4.value > } >});
BLOWING RASPBERRIES; GETTING VALUES
Johnny-Five >new five.Pin(13).query( >function(state) { > console.log(state); >});
GPIO >var gpio = require("gpio"); >var gpio4 = gpio.export(4, { > direction: "in", > ready: function() { > Console.log(gpio4.value > } >});
BLOWING RASPBERRIES; SETTING VALUES
BLOWING RASPBERRIES; SETTING VALUES
GPIO > gpio4.set(function() >{ console.log(gpio4.value); >});
BLOWING RASPBERRIES; SETTING VALUES
Johnny-Five Nothing explicit; is accomplished by passing values straight in to the functions
GPIO > gpio4.set(function() >{ console.log(gpio4.value); >});
FINAL HINTS AND TIPS
• Once connected so you can SSH in to it, use a file transfer client
FINAL HINTS AND TIPS
• Once connected so you can SSH in to it, use a file transfer client
• Helpful if the GPIO pins are labeled using the paper overlay for the PI
FINAL HINTS AND TIPS
• Once connected so you can SSH in to it, use a file transfer client
• Helpful if the GPIO pins are labeled using the paper overlay for the PI
• Get a ribbon cord for the Pi; will make your life easier.
HE’S STILL NOT FINISHED?
• Not everything has to be written in NodeJS
HE’S STILL NOT FINISHED?
• Not everything has to be written in NodeJS
• Is, however, an accessible starting point for front end developers
HE’S STILL NOT FINISHED?
• Not everything has to be written in NodeJS
• Is, however, an accessible starting point for front end developers
• Projects don’t need to be in the same language
HE’S STILL NOT FINISHED?
• Not everything has to be written in NodeJS
• Is, however, an accessible starting point for front end developers
• Projects don’t need to be in the same language
• Important that what you’ve written works
MAYBE HE NEARLY IS?
• Don’t be afraid; there’s always help at hand!
MAYBE HE NEARLY IS?
• Don’t be afraid; there’s always help at hand!
• Don’t expect to not learn anything during the project!
MAYBE HE NEARLY IS?
• Don’t be afraid; there’s always help at hand!
• Don’t expect to not learn anything during the project!
• Have fun with your project!
MAYBE HE NEARLY IS?
• Don’t be afraid; there’s always help at hand!
• Don’t expect to not learn anything during the project!
• Have fun with your project!
• Be Careful!
THANK YOU!
RESOURCES
• Node; nodejs.org/downloads/
• NPM; npmjs.org
• NodeSchool; nodeschool.io
• Adafruit Industries; http://learn.adafruit.com/category/learn-raspberry-pi
• RS-Components; uk.rs-online.com
• Farnell; uk.farnell.com