var arDrone = require('ar-drone'); var client = arDrone.createClient(); client.takeoff(); client .after(5000, function() { this.clockwise(0.5); // range from 0 to 1 }) .after(3000, function() { this.animate('flipLeft', 15); // 15ms }) .after(1000, function() { this.stop(); this.land(); });
var SerialPort = require('serialport').SerialPort; var board = new SerialPort('/dev/tty-usbserial1', { baudrate: 115200 }); board.on('data', function(data) { console.log('data:', data); board.write('It works!\n'); }); board.on('error', function(err) { console.log('error:', err); });
The JavaScript Programming Framework
npm install johnny-five
LED
DC Motor
Servo Motor
Stepper Motor
LCD
Accelerometer
Compass
Joystick
http://johnny-five.io/examples/
https://github.com/rwaldron/johnny-five/wiki/LED
var five = require('johnny-five'); var board = new five.Board(); board.on('ready', function() { // Creates a led object on pin 13 var led = new five.Led(13); // "blink" the led in 500ms on-off phase periods led.blink(500); });
board.on('ready', function() { var led = new five.Led(13); this.repl.inject({ // Allow limited on/off control access to the // Led instance from the REPL. on: function() { led.on(); }, off: function() { led.off(); } }); });
$ node led.js >> on() // will turn on the LED >> off() // will turn off the LED
https://github.com/rwaldron/johnny-five/wiki/Motor
var five = require('johnny-five'); var board = new five.Board(); board.on('ready', function() { var motor = new five.Motor(5); motor.on('start', function() { // Demostrate motor stop in 2 seconds board.wait(2000, function() { motor.stop(); }); }); // Start the motor at maximum speed motor.start(255); });
https://github.com/rwaldron/johnny-five/wiki/Servo
var five = require('johnny-five'); var board = new five.Board(); board.on('ready', function() { var servo = new five.Servo({ pin: 11, range: [0, 180] }); // Set horn to 45° servo.to(45); // Angle change takes 500ms to complete servo.to(60, 500); // Set horn to 90° servo.center(); });
https://github.com/rwaldron/johnny-five/wiki/LCD
var five = require('johnny-five'); var board = new five.Board(); board.on('ready', function() { var lcd = new five.LCD({ controller: 'PCF8574', // I²C LCD, PCF8574 rows: 2, cols: 16 }); lcd.cursor(0, 0) // Sets the cursor position .print('Loading...'); this.wait(1000, function() { lcd.clear() // Clears all text on the LCD .home() // Sets the cursor position to row 0, column 0 .print('Hello, JSDC 2015'); }); });
http://api.openweathermap.org/data/2.5/weather?units=metric&q=Taipei
var request = require('request'); var qs = '?q=Taipei&units=metric'; var url = 'http://api.openweathermap.org/data/2.5/weather' + qs; request(url, function(err, rsp, body) { var data = JSON.parse(body); : : : lcd.cursor(0, 0) .print(dt); lcd.cursor(1, 0) .print(name + ' (' + weather + ')'); lcd.cursor(2, 0) .print('T:' + temp + ' (' + tempMin + '-' + tempMax + ')'); lcd.cursor(3, 0) .print('H:' + humidity + '% W:' + windSpeed + 'km/h'); });
var five = require('johnny-five'); var board = new five.Board(); board.on('ready', function() { // Claw servo controller var claw = new five.Servo(11); // Joystick controller var joystick = new five.Joystick({ pins: ['A0', 'A1'] // X (claw), Y (none) }); // Center the claw servo claw.center(); joystick.on('change', function() { var degree = five.Fn.scale(this.x, -1, 1, 130, 180); claw.to(degree); // Range: 130°-180° }); });
$ npm install johnny-five $ npm install robotarm
var five = require('johnny-five'); var RobotArm = require('robotarm'); var board = new five.Board(); board.on('ready', function() { var robotarm = new RobotArm({ axis: { claw: new five.Servo({ pin: 11, range: [130, 180] }) } }); robotarm .then(function(next) { claw.to(130, 1000); // Open the claw in 1000ms setTimeout(next, 1500); // Wait for completion }) .then(function(next) { claw.to(180, 1000); // Close the claw in 1000ms setTimeout(next, 1500); // Wait for completion }) .play({ loop: true }); });
An open source, embedded, high performance g-code-parser and CNC milling controller written in optimized C that will run on a straight Arduino.
Powered By
socat -d -d pty,nonblock,link=$HOME/dev/ttyV0 tcp:10.0.1.12:8899Execute it like this:
node blink.js ~/dev/ttyV0
A Node library to interact with an Arduino running the firmata protocol.