Skip to content

Instantly share code, notes, and snippets.

@parshap
Last active December 28, 2015 22:19
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save parshap/7570754 to your computer and use it in GitHub Desktop.
Save parshap/7570754 to your computer and use it in GitHub Desktop.
Orbotix Sphero with Node.js

Sphero with Node

This document will help you get started with controlling an Orbotix Sphero using Node.js.

Client Libraries

There are several different libraries for controlling the Sphero. Currently, the best one seems to be spheron. This module provides a simple interface to the Sphero API.

There is also CylonJS, but this just uses the spheron module and exposes the same API, so unless you are already using Cylon to control different hardware it probably makes sense to just use spheron directly.

API Documentation

The spheron client library does provide much documentation, but Orbotix has detailed documentation for the entire Spheron API. You will have to manually inspect the functions available on the spheron sphero object and match them up to commands found in Sphero API PDF to understand the parameters and what they do. The names match up pretty nicely.

Connecting to Sphero

Based on my experience on a MBP and OSX 10.9. For Linux see comment below.

Bluetooth Pairing

Once removed from the charger, you need to shake the sphero twice until it lights up with your 3-color signature. At this point you should see the device in your Bluetooth settings (in System Preferences) and can click Pair to pair with the device. Any time the Sphero wakes up (e.g., was not "lit up" and you shook it to light it up) you will have to remove and re-pair the device (see troubleshootin below).

Connecting in Node

Once you have paired and have a Bluetooth connection with the Sphero you should see a device file in /dev.

$ ls /dev | grep -i sphero 
cu.Sphero-BYR-RN-SPP
tty.Sphero-BYR-RN-SPP

The one starting with cu. is what you will use when connecting:

var sphero = require('spheron').sphero();
sphero.open("/dev/cu.Sphero-BYR-RN-SPP");

If this fails, try the troubleshooting section below.

Troubleshooting

  • Device not in Bluetooth list: If your Sphero device does not appear in the list of found Bluetooth devices, make sure the Sphero is emitting its 3-color signature. If it is not, shake the device until it does.

  • Remove and re-pair: Any time you see the Sphero device in your Bluetooth settings but Not Connected, you should forget the device (right click -> Remove), wait for the Sphero to show up again, and click Pair again.

  • Reset the device: If you still have issues connecting, you can reset the device (described in the Sphero Quick-Start Guide manual) and try again. Make sure to remove the device from your paired Blueooth devices and re-pair after resetting.

@morganrallen
Copy link

Linux and Your Sphero

Connecting from the Linux command line uses two tools. hcitool for scanning bluetooth devices and rfcomm to connect.

both tools are provided by the bluez package and will almost certainly be installed on your Linux distribution.

Finding your Sphero

hcitool scan

Scanning ...
    00:06:66:4A:3F:4B   Sphero-RGW

This provides the MAC address for your Sphero

Determine your bluetooth interface
hcitool dev

Devices:
    hci0    74:DE:2B:93:E2:9B

It should be or similar to hci0 if yours is different substitute it for hci0 in the following commands.

Binding to your Sphero

sudo rfcomm bind hci0 00:06:66:4A:3F:4B

This should create a device for you, the default is /dev/rfcomm0 if this is not the case you might also need to run
sudo rfcomm bind hci0 /dev/rfcomm0

Troubleshooting

And any point you need to start over you should run sudo rfcomm release hci0 especially if you get any issues with address in use.

@alchemycs
Copy link

The original spheron module has been updated and now includes support for sphero internal macros, a little better documentation (I will be working on it over christmas 2013) and the patch from hybrid group.

npm install spheron

@parshap
Copy link
Author

parshap commented Dec 13, 2013

@alchemyc: Great! I updated the OP.

@julienboulay
Copy link

@morganrallen : Many thanks for this tutorial on using spheron.
Is it possible to bind more than one sphero on Linux, with a special rfcomm command for example ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment