How to use firmata - 10 common examples

To help you get started, we’ve selected a few firmata examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github iamdustan / react-hardware / scripts / babel / test-deps / mock-firmata.js View on Github external
const origMockFirmata = mock.Firmata;
mock.Firmata = function(opts, callback) {
  const result = new origMockFirmata(opts);
  if (callback) {
    setTimeout(() => {
      callback.call(result);
    });
  }
  return result;
};

Object.assign(mock.Firmata, origMockFirmata);

// use the real implementation for this
mock.Firmata.isAcceptablePort = Firmata.isAcceptablePort;

module.exports = mock;
github watterott / RPi-ShieldBridge / software / Firmata.js View on Github external
var rpio = require('rpio');
var firmata = require('firmata');

// GPIO18 low -> Arduino reset off
rpio.setOutput(12);
rpio.write(12, rpio.LOW);

// start connection to Arduino
//  USB: /dev/ttyUSB0 or /dev/ttyACM0
//  UART: /dev/ttyAMA0
var board = new firmata.Board('/dev/ttyAMA0', function(err)
{
  if(err)
  {
    console.log(err);
    return;
  }
  console.log('connected');
  board.pinMode(13, board.MODES.OUTPUT);
  // switch on LED
  board.digitalWrite(13, board.HIGH);
  // switch off LED after 3s
  setTimeout(function()
  {
    board.digitalWrite(13, board.LOW);
    process.exit(0);
  }, 3000);
github iamdustan / react-hardware / src / firmata / HardwareInstanceManager.js View on Github external
'experimental at best. Have fun! :)'
    );
    setupConnection('experimental-board', board);
    board.on('ready', (error) => {
      if (error) {
        callback(error);
      } else {
        updateConnection('experimental-board', board);
        callback(null, board);
      }
    });
    return;
  }

  console.info('Connecting to port "%s"', port);
  const board = new Board(port, (error) => {
    if (error) {
      console.info('Board setup error');
      callback(error);
    } else {
      updateConnection(port, board);
      callback(null, board);
    }
  });
  setupConnection(port, board);

  board.on('error', (error) => {
    // TODO: look up docs/source code for this
    console.info('Board error event!');
    console.log(error);
  });
github ajfisher / node-pixel / examples / repl.js View on Github external
var firmata = require("firmata");
var repl = require("repl");

var serialport = "/dev/ttyUSB0";

var red = 0, green = 0, blue = 0;

var board = new firmata.Board(serialport, function (error) {
    if (error) {
        console.log(error);
        return;
    }

    console.log('Connected to ' + serialport);
    console.log('Firmware: ' +
        board.firmware.name + '-' +
        board.firmware.version.major + '.' +
        board.firmware.version.minor
        );

    var context = repl.start("RGB>").context;
//    context.sses = sendSysExString;
    context.sendPixel = sendPixel;
    context.rainbow = rainbow;
github iamdustan / react-hardware / src / ReactHardwareMount.js View on Github external
function connect(maybePort:string, callback:Function) {
  if (maybePort !== TRANSIENT_CONTAINER_IDENTIFIER) {
    connect(maybePort);
  } else {
    console.info('Requesting port...');
    Board.requestPort((err, port) => {
      if (err) {
        throw err;
      } else {
        console.log(port.comName);
        // Remap the connection from transient state to the real port
        connectionsByContainer[port.comName] = connectionsByContainer[maybePort];
        delete connectionsByContainer[maybePort];
        connect(port.comName);
      }
    });
  }

  function connect(port) {
    console.info('Connecting to port "%s"', port);
    const board = new Board(port, function(err) {
      if (err) {
github rwaldron / johnny-five / lib / board.js View on Github external
// Board({ port: path String })
      //
      // Board()
      //    ie. auto-detected
      //
      path = portOrPath;
    }

    // Add the usb device path to the list of device paths that
    // are currently in use - this is used by the filter function
    // above to remove any device paths that we've already encountered
    // or used to avoid blindly attempting to reconnect on them.
    Serial.used.push(path);

    try {
      io = new IO(portOrPath, function(error) {
        if (error) {
          caught = error;
        }

        callback.call(this, caught, caught ? "error" : "ready", io);
      }.bind(this));

      // Extend io instance with special expandos used
      // by Johny-Five for the IO Plugin system.
      io.name = "Firmata";
      io.defaultLed = 13;
      io.port = path;

      // Made this far, safely connected
      isConnected = true;
    } catch (error) {
github iamdustan / react-hardware / src / ReactHardwareMount.js View on Github external
(
        typeof nextElement === 'function' ?
          ' Instead of passing a component class, make sure to instantiate ' +
          'it by passing it to React.createElement.' :
        // Check if it quacks like an element
        nextElement != null && nextElement.props !== undefined ?
          ' This may be caused by unintentionally loading two independent ' +
          'copies of React.' :
          ''
      )
    );

    warning(
      typeof container === 'string' ? (
        container === TRANSIENT_CONTAINER_IDENTIFIER ||
        Board.isAcceptablePort({comName: container})
      ) : true,
      'Attempting to render into a possibly invalid port: %s',
      container
    );

    if (container) {
      const prevConnection = connectionsByContainer[container];

      if (prevConnection) {
        warning(
          prevConnection.status !== 'CONNECTING',
          'Attempting to render to port `%s` that is in the process of mounting. ' +
          'You should wait until ReactHardware(comp, port, callback) callback is ' +
          'called to render again',
          container
        );
github monteslu / node-red-contrib-gpio / lib / nodebotNode.js View on Github external
var mqtt = require('mqtt');
          VirtualSerialPort = require('mqtt-serial').SerialPort;

          client = mqtt.connect(n.mqttServer,
          {username: n.username, password: n.password});
          client.on('error', function(err){
            node.warn(err);
          });

          sp = new VirtualSerialPort({
            client: client,
            transmitTopic: n.pubTopic,
            receiveTopic: n.subTopic
          });

          node.io = new firmata.Board(sp, {samplingInterval: 300, reportVersionTimeout: 15000});
          start(node);
        }catch(exp){
          console.log('error initializing mqtt firmata', exp);
          process.nextTick(function() {
            node.emit('ioError', exp);
          });
        }
      }
      else if(n.connectionType === 'tcplisten'){ //mode listen network

        node.tcpServer = net.createServer(function(socket){
          node.io = new firmata.Board(socket);
          start(node);
            console.log('client ready', socket.remoteAddress + ":" + socket.remotePort );
             socket.emit('open', {});
            socket.on('error', function(err){
github iamdustan / react-hardware / src / ReactHardwareMount.js View on Github external
function connect(port) {
    console.info('Connecting to port "%s"', port);
    const board = new Board(port, function(err) {
      if (err) {
        console.error('Failed connecting to port %s', port);
        throw err;
      }

      callback(board, port);
    });
  }
}
github iamdustan / react-hardware / src / firmata / HardwareInstanceManager.js View on Github external
connect(
    port : ?string,
    callback: Result
  ) {
    if (port == null) {
      console.info('Requesting port...');
      Board.requestPort((error, port) => {
        if (error) {
          callback(error);
        } else {
          setup(port.comName, callback);
        }
      });
    } else {
      setup(port, callback);
    }
  },

firmata

Firmata protocol implementation for programmatic interaction with Arduino and Arduino compatible development boards. Includes Serialport

MIT
Latest version published 4 years ago

Package Health Score

48 / 100
Full package analysis