Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Arduinode

 Arduinode

Making Arduino and Node.js talk

Nate Good

June 28, 2012
Tweet

More Decks by Nate Good

Other Decks in Programming

Transcript

  1. Locate your arduino > ls /dev ... tty.usbserial-A6008jCB ... Use

    screen to monitor input Arduino IDE also has built in serial monitor > screen /dev/tty.usbserial-A6008jCB 9600
  2. void setup(){ // Open connection Serial.begin(9600); } void loop(){ //

    Send single byte with value 45 Serial.write(45); // Send multiple bytes (ASCII) int bytesSent = Serial.write("hello"); }
  3. protocol for speaking serial to arduino abstracts the ugly of

    serial communication removes the need for writing wiring (aka arduino code) altogether set and forget upload a single standard firmata protocol program to arduino firmata
  4. step 1 upload a standard firmata sketch to your arduino

    (available in IDE) step 2 use a firmata client library to talk to the arduino using this standard protocol step 3 plug in your arduino and start making it talk how's it work?
  5. var Board = require('firmata').Board, tty = "/dev/tty.usbserial-A6008jCB"; var board =

    new Board(tty, function() { var analogPin = 3, ledPin = 13, on = false; board.pinMode(analogPin, board.MODES.ANALOG); var readAndSleep = function() { board.analogRead(analogPin, function(sleep) { var mode = on ? board.HIGH : board.LOW; board.digitalWrite(ledPin, mode); on = !on; setTimeout(readAndSleep, sleep); }); }; readAndSleep(); });
  6. javascript + node.js event driven event driven makes it awesome

    for the web where we're waiting around for user input real world also pretty event driven a lot of waiting around for io to happen why node?
  7. express web app publishes to redis redis in turn notifies

    subscribers of the rating node.js (subscribed to redis) receives event, calculates rotation, and speaks firmata arduino receives firmata protocol, moves servo accordingly rate nate demo
  8. what next? real time node redis pubsub, socket.io components rfid,

    infrared, lcds, variable resistors, accelerometers, break-out boards beyond arduino x10, raspberry pi where? sparkfun, radioshack, digikey, make