nodejs-piYou can program the BrickPi in Node.JS.  Make your Raspberry Pi Robots in NodeJS:

What is Node.js?

Node.js is an open source, cross-platform runtime environment for server-side and networking applications. Node.js applications are written in JavaScript, and can be run within the Node.js runtime on OS X, Microsoft Windows, Linux and FreeBSD.

Where do I start?

  • You can install the package on your Raspberry Pi using this package.
  • To try it out, on the PI, run “sudo apt-get install nodejs npm”  which will install both node and the npm package manager.
  • Once done, run “npm install brickpi-raspberry” which will add the module.
  • Check out the source-code here on Github.

Example Raspberry Pi Node.js

 

You can then run the following example:

var brickpi = require('brickpi-raspberry');

var robot = new brickpi.Robot();
var motorA = new brickpi.Motor({port: brickpi.MOTOR.A, name: 'Upper arm'});

var touchA = new brickpi.Sensor({port: brickpi.SENSOR_PORT.ONE, type: brickpi.SENSOR_TYPE.TOUCH, name: 'Touch Sensor on upper arm'});

robot.setup().addMotor(motorA).addSensor(touchA).run(function() {});

motorA.start(-100).stopIn(720, function(err) {
  // callback called when motor has reached end point
});

touchA.on('change', function() {
    // access value of touchA sensor.
    console.log(touchA.getValue());
});

motorA.on('stop', function(motor) {
   console.log("Motor " + motor.getName() + " has stopped");
});