GithubHelp home page GithubHelp logo

nvdnkpr / node-arduino-firmata Goto Github PK

View Code? Open in Web Editor NEW

This project forked from shokai/node-arduino-firmata

0.0 3.0 0.0 635 KB

Arduino Firmata protocol implementation on Node.js

Home Page: https://npmjs.org/package/arduino-firmata

License: MIT License

node-arduino-firmata's Introduction

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 Diecimila
      • Arduino Duemillanove
      • Arduino UNO
      • Arduino Leonardo
      • Arduino Micro
      • Seeduino v2
  • 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(); // use default arduino
arduino.connect('/dev/tty.usb-device-name');

arduino.on('connect', function(){

  console.log("board version"+arduino.boardVersion);
  // your-code-here

});

Reset

arduino.reset(callback);

Close

arduino.close(callback);

I/O

Digital Write

arduino.digitalWrite(13, true, callback);
arduino.digitalWrite(13, false, callback);

Digital Read

arduino.pinMode(7, ArduinoFirmata.INPUT);
console.log( arduino.digitalRead(7) ); // => true/false

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; // 0 ~ 255
  arduino.analogWrite(9, an, callback);
}, 100);

Analog Read

console.log( arduino.analogRead(0) ); // => 0 ~ 1023

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; // 0 ~ 180
  arduino.servoWrite(11, angle, callback);
}, 1000);

Sysex

Send

arduino.sysex(0x01, [13, 5, 2], callback);  // command, data_array, callback

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

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

node-arduino-firmata's People

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.