This document discusses hardware hacking for JavaScript developers. It introduces several hardware platforms that can be programmed with JavaScript, including Arduino, Tessel, Raspberry Pi, and Johnny-Five. Examples are provided on how to program an LED to blink on these platforms using JavaScript. The document also discusses prototyping smart home devices and provides an example of a "KittyCam" project that streams photos and detects cats using hardware, a Raspberry Pi, and Node.js.
3. @girlie_mac
I am a:
● Front-End Engineer
● N00b Hardware Hacker
● Sr. Developer Evangelist at
PubNub
● (Former) Mobile Geek
● Cat Lady of The InterWeb
16. @girlie_mac
Programming Tessel in Node.js
var tessel = require('tessel');
var camera = require('camera-vc0706').use(tessel.port['A']);
camera.on('ready', function() {
camera.takePicture(function(err, image) {
if (err) { console.log(err); }
else {
var name = 'pic-' + Date.now() + '.jpg';
process.sendfile(name, image);
camera.disable();
}
});
});
the port the
camera module
is plugged in
ready
event
callback
23. @girlie_mac
Ohm’s Law & Resistors
R =
V - Vs f
I
source voltage (V) forward voltage (V) (LED
voltage drop)
current thru the LED (A)
resistance (Ω)
24. @girlie_mac
Ohm’s Law & Resistors
R =
3.3 - 1.9
0.02
source voltage (V) forward voltage (V) (LED
voltage drop)
current thru the LED (A)
resistance (Ω)
= 70Ω
31. @girlie_mac
Blinking LED in Python
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
LED = 4
GPIO.setup(LED,GPIO.OUT)
for i in range(6):
GPIO.output(LED,True)
time.sleep(0.5)
GPIO.output(LED,False)
time.sleep(0.5)
import RPi.GPIO libs
GPIO 4 pin (Pin 7)
set LED pin as output
toggle light pin signal to
low/high to make it blink.
32. @girlie_mac
Programming Pi in Node.js
Download & install Node.js from terminal:
$ wget http://node-arm.herokuapp.
com/node_latest_armhf.deb
$ sudo dpkg -i node_latest_armhf.deb
34. @girlie_mac
Blinking LED
var five = require('johnny-five');
var raspi = require('raspi-io');
var board = new five.Board({io: new raspi()});
board.on('ready', function() {
var led = new five.Led(P1-7); // Create an instance
led.blink(500); // "blink" in 500ms on-off phase periods
});
Pin 7 (GPIO-4)
Plugin for RPI
(Default w/o plugins
works for all Arduino)
43. @girlie_mac
KittyCam in Node.js
1. Detect motion (Johnny-Five IR.Motion obj)
2. Take photos (Raspistill, command line tool)
3. Cat facial detection (KittyDar)
4. Store the photos in Cloudinary
5. Publish the data to PubNub
6. Stream on web (subscribe the data from
PubNub)