In the era of Internet of Things, connecting things to the mobile devices and web is becoming ubiquitous. You can control room light using your mobile phone. You can monitor your heart rate and weight on browser. Front-end developers like you already have skills to prototype software ideas, so why not prototyping the Internet of Everything?
- Arduino
- Raspberry Pi
- Johnny-Five JS robotics framework
- PubNub Data Stream
15. @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
22. @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 (Ω)
23. @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Ω
30. @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(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)
38. @girlie_mac
Sending Data from browser
redInput.addEventListener('change', function(e){
publishUpdate({color: 'red', brightness: +this.value});
}, false);
function publishUpdate(data) {
pubnub.publish({
channel: 'hue',
message: data
});
}
Send the red value to PubNub to
tell the MCU to reflect the
change!
the value has
changed! Publish the
new value!
39. @girlie_mac
Receiving Data to LED
pubnub.subscribe({
channel: 'hue',
callback: function(m) {
if(led) {
r = (m.color === 'red') ? m.brightness : r;
g = (m.color === 'green') ? m.brightness : g;
b = (m.color === 'blue') ? m.brightness : b;
led.color({red: r, blue: b, green: g});
}
}
});
to the GPIO pins
that connect to
LED anodes
42. @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)
44. @girlie_mac
PIR Sensor > Run Camera
board.on('ready', function() {
// Create a new `motion` hardware instance.
var motion = new five.Motion(7); //a PIR is wired on pin 7 (GPIO 4)
// 'calibrated' occurs once at the beginning of a session
motion.on('calibrated', function() {console.log('calibrated');});
motion.on('motionstart', function() { // Motion detected
// Run raspistill command to take a photo with the camera module
var filename = 'photo/image_'+i+'.jpg';
var args = ['-w', '320', '-h', '240', '-o', filename, '-t', '1'];
var spawn = child_process.spawn('raspistill', args);
...
motion detected!
Take a photo!
45. @girlie_mac
Processing Photo
...
spawn.on('exit', function(code) {
if((/jpg$/).test(filename)) {
var imgPath = __dirname + '/' + filename;
// Child process: read the file and detect cats with KittyDar
var args = [imgPath];
var fork = child_process.fork(__dirname+'/detectCatsFromPhoto.js');
fork.send(args);
// the child process is completed
fork.on('message', function(base64) {
if(base64) {
// Send to cloud storage
}
}); ...
var kittydar = require
('kittydar');
a cat detected!