controla hardware con Node.js y
Johnny-Five.
Julio César Castellanos
NodebotsMonteria
@juliocesar_io
Mi primer Nodebots
1. Node.js
2. Firmata
3. Node-serialport
4. Johnny five
5. Johnny five abstractions
6. Demos
Node.js
- JavaScript del lado del servidor
- Aplicaciones web en tiempo real escalables
- Non-blocking
- Asíncrono
- Orientado a eventos
- NPM
Non-blocking, Asíncrono y Orientado a Eventos
NPM
1. Node.js
2. Firmata
3. Node-serialport
6. Demos
4. Johnny five
5. Johnny five abstractions
Firmata
Firmata, es un protocolo que permite comunicar microcontraladores con una aplicación que esta siendo ejecutada desde una computadora (host)
010101101110
https://github.com/firmata/protocol
Host
Implementaciones
1. Node.js
2. Firmata
3. Node-serialport
6. Demos
4. Johnny five
5. Johnny five abstractions
Node-seriaport
http://www.voodootikigod.com/nodebots-the-rise-of-js-robotics/ - by Chris Williams
1. Node.js
2. Firmata
3. Node-serialport
6. Demos
4. Johnny five
5. Johnny five abstractions
Johnny five
https://github.com/rwaldron/johnny-five - by Rick Waldron
$( document ).ready(function() {
$( "button" ).on( "mousedown", function() {
console.log( "button down" );
});
});
IoT and Robotics programming framework
five.Board().on("ready", function() {
button = new five.Button({
pin: 2,
isPullup: true
});
button.on("down", function(value) {
console.log("down");
});
});
var five = require("johnny-five"),
button, led;
five.Board().on("ready", function() {
button = new five.Button({
pin: 2,
isPullup: true
});
button.on("down", function(value) {
console.log("down");
});
});
$ npm i johnny-five
$ node button.js
button.js
Button.js
var keypress = require('keypress');
var five = require("johnny-five"),
board;
// Johnny-Five will try its hardest to detect the port for you,
// however you may also explicitly specify the port by passing
// it as an optional property to the Board constructor:
board = new five.Board({
// port: "/dev/tty.itead-DevB"
port: "/dev/cu.itead-DevB"
});
// board = new five.Board();
board.on("ready", function() {
var speed = 80;
console.log("Repl instance auto-initialized ready!!!");
motor1 = new five.Motor([10, 8]);
motor2 = new five.Motor([9, 7]);
// motor1 = new five.Motor({
// pins:{
// pwm: 10,
// dir: 8
// }
// });
// motor2 = new five.Motor({
// pins:{
// pwm: 9,
// dir: 7
// }
// });
board.repl.inject({
lmotor: motor1,
rmotor: motor2,
});
// make `process.stdin` begin emitting "keypress" events
keypress(process.stdin);
// listen for the "keypress" event
process.stdin.on('keypress', function (ch, key) {
if (key && key.ctrl && key.name == 'c') {
process.exit(0);
}
if ( key ){
switch ( key.name ){
case 'up':
speed+=20;
console.log(' => Up: ' + speed);
motor1.rev( speed );
motor2.rev( speed );
break;
case 'down':
speed+=20;
console.log(' => Down: ' + speed);
motor1.fwd( speed );
motor2.fwd( speed );
break;
case 'left':
console.log(' => Left: ');
motor1.fwd( speed * 0.5 );
motor2.rev( speed * 0.5 );
break;
case 'right':
console.log('right');
motor1.rev( speed * 0.5 );
motor2.fwd( speed * 0.5 );
break;
case 'space':
console.log(' => Stoping...');
motor1.stop();
motor2.stop();
break;
case 'r':
console.log(' => Speed to 80');
speed = 80;
break;
default:
console.log('Ignoring key: ' + key.name);
}
}
});
process.stdin.setRawMode(true);
process.stdin.resume();
});
https://github.com/jurasec/johnny-five-guide/blob/master/example/WirelessNodeBotZumoArrows.js
$ node WirelessNodeBotZumoArrows.js
button.js
WirelessNodeBotZumoArrows.js
https://github.com/rwaldron/johnny-five - by Rick Waldron
1. Node.js
2. Firmata
3. Node-serialport
6. Demos
4. Johnny five
5. Johnny five abstractions
Johnny five abstractions
https://github.com/rwaldron/johnny-five/blob/master/lib/johnny-five.js
module.exports = {
// extract-start:apinames
Accelerometer: require("./accelerometer"),
Animation: require("./animation"),
Altimeter: require("./altimeter"),
Barometer: require("./barometer"),
Board: require("./board"),
Button: require("./button"),
Color: require("./color"),
Compass: require("./compass"),
Distance: require("./distance"),
ESC: require("./esc"),
Expander: require("./expander"),
Fn: require("./fn"),
GPS: require("./gps"),
Gripper: require("./gripper"),
Gyro: require("./gyro"),
Hygrometer: require("./hygrometer"),
IMU: require("./imu"),
IR: require("./ir"),
Keypad: require("./keypad"),
LCD: require("./lcd"),
Led: require("./led"),
LedControl: require("./led/ledcontrol"),
Light: require("./light"),
Joystick: require("./joystick"),
Motion: require("./motion"),
Motor: require("./motor"),
Nodebot: require("./nodebot"),
Piezo: require("./piezo"),
Ping: require("./ping"),
Pir: require("./pir"),
Pin: require("./pin"),
Proximity: require("./proximity"),
Relay: require("./relay"),
Repl: require("./repl"),
Sensor: require("./sensor"),
Servo: require("./servo"),
ShiftRegister: require("./shiftregister"),
Sonar: require("./sonar"),
Stepper: require("./stepper"),
Switch: require("./switch"),
Thermometer: require("./thermometer"),
Wii: require("./wii")
// extract-end:apinames
};
Demo time!
Gracias!
@Juliocesar_io
Nodebots Monteria P.1
By Julio César
Nodebots Monteria P.1
Una manera sencilla de controlar hardware con Node.js y Johnny-Five.
- 916