npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

sphero-pwn

v0.5.3

Published

Driver for Sphero robots

Downloads

52

Readme

Node.js Sphero Driver

Build Status API Documentation NPM Version

This is a node.js driver for the communication protocol used by Sphero's robots.

This project is an independent effort from the official sphero.js project, and is less supported. At the same time, we are free to develop functionality that is unlikely to be added to the official project, such as driving a BB-8.

This project is written in CoffeeScript and tested using mocha.

Usage

This package's API relies heavily on ES6 Promises.

Each robot that your computer can connect to receives an identifier. The following command looks for reachable robots and shows their identifiers.

npm start

Once you have an identifier, you can use the discovery service to connect to the robot, as shown below. The discovery service has other useful methods as well.

var sphero = require('sphero-pwn');
var robot = null;
sphero.Discovery.findChannel('serial:///dev/cu.Sphero-YRG-AMP-SPP').
    then(foundChannel);  // foundChannel is defined below.

The discovery service produces a communication channel, which can be used to create a Robot. Robot's methods are convenient wrappers for the Sphero API commands.

function foundChannel(channel) {
  console.log("Found robot");
  robot = new sphero.Robot(channel);

  play();  // play is defined below.
}

For example, the following snippet sets the Sphero's permanent RGB LED color.

function play() {
  robot.setUserRgbLed({red: 255, green: 128, blue: 0}).
    then(function() {
      console.log("Set LED color");
      robot.close();
    }).
    then(function() {
      console.log("Done");
    });
}

The following example uses orbBasic to flash the robot's RGB LED.

function play() {
  robot.on('basic', function(event) {
    console.log("basic print: " + event.message);
  });
  robot.on('basicError', function(event) {
    console.log("basic error: " + event.message);
  });
  var script = "10 RGB 0, 255, 0\n" +
               "20 delay 2000\n" +
               "30 RGB 0, 0, 255\n" +
               "40 delay 2000\n";
  robot.loadBasic("ram", script).
    then(function() {
      console.log("Loaded script");
      robot.runBasic("ram", 10);
    }).
    then(function() {
      console.log("Started script");
      robot.close();
    }).
    then(function() {
      console.log("Done");
    }).
    catch(function() {
      console.error(error)
    });
}

Last, the following example uses our macro compiler to compile and execute a macro that flashes the robot's RGB LED.

var macros = require('sphero-pwn-macros');

function play() {
  var macroSource = "rgb 0 255 0\n" +
                    "delay 2000\n" +
                    "rgb 0 0 255\n" +
                    "delay 2000\n";
  var macro = macros.compile(macroSource);

  robot.on('macro', function(event) {
    console.log("macro marker: " + event.markerId);
  });
  robot.loadMacro(0xFF, new Buffer(macro.bytes)).
    then(function() {
      console.log("Loaded macro in RAM");
      robot.runMacro(0xFF);
    }).
    then(function() {
      console.log("Started macro");
      robot.close();
    }).
    then(function() {
      console.log("Done");
    }).
    catch(function() {
      console.error(error)
    });
}

Development Setup

Install all the dependencies.

npm install

List the Bluetooth devices connected to your computer.

npm start

Set the SPHERO_DEV environment variable to point to your Sphero.

export SPHERO_DEV=serial:///dev/cu.Sphero-XXX-AMP-SPP
export SPHERO_DEV=ble://ef:80:a8:4a:12:34

Run the tests.

npm test

License

This project is Copyright (c) 2015 Victor Costan, and distributed under the MIT License.