arduino-firmata
Arduino Firmata protocol (http://firmata.org) implementation on Node.js.
Install
% npm install arduino-firmata
Requirements
- Arduino (http://arduino.cc)
- testing with Arduino UNO, Leonardo and Micro.
- Arduino Standard Firmata v2.2
- Arduino IDE -> [File] -> [Examples] -> [Firmata] -> [StandardFirmata]
Usage
Samples
Setup
Connect
var ArduinoFirmata = require('arduino-firmata');
var arduino = new ArduinoFirmata();
arduino.connect();
arduino.connect('/dev/tty.usb-device-name');
arduino.on('connect', function(){
console.log("board version"+arduino.boardVersion);
});
Close
arduino.close(callback);
I/O
Digital Write
arduino.digitalWrite(13, true);
arduino.digitalWrite(13, false);
Digital Read
arduino.pinMode(7, ArduinoFirmata.INPUT);
console.log( arduino.digitalRead(7) );
Digital Read (event)
arduino.pinMode(7, ArduinoFirmata.INPUT);
arduino.on('digitalChange', function(e){
console.log("pin" + e.pin + " : " + e.old_value + " -> " + e.value);
});
Analog Write (PWM)
setInterval(function(){
var an = Math.random()*255;
arduino.analogWrite(9, an);
}, 100);
Analog Read
console.log( arduino.analogRead(0) );
Analog Read (event)
arduino.on('analogChange', function(e){
console.log("pin" + e.pin + " : " + e.old_value + " -> " + e.value);
});
Servo Motor
setInterval(function(){
var angle = Math.random()*180;
arduino.analogWrite(11, angle);
}, 1000);
Sysex
Send
arduino.sysex(0x01, [13, 5, 2]);
Register Sysex Event
arduino.on('sysex', function(e){
console.log("command : " + e.command);
console.log(e.data);
});
Test
Install SysexLedBlinkFirmata into Arduino
Run Test
% npm install
% npm test
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request