$ npm install sphero
To connect to your Sphero, you first need to pair it. To pair your device on OS X, open the Bluetooth settings here: System Preferences > Bluetooth. From this menu, locate your Sphero in the Devices list and click the Pair button to pair it with your computer.
Once you've successfully paired your Sphero, open your terminal and navigate to your system's
/dev/ directory and locate the serial device connection for your newly paired Sphero; it should look something like this:
Note, your device will likely be different depending on its preset color code (the three colors your Sphero cycles through when you first turn it on). The example above is for a Sphero with a Red, Green, and Blue (RGB) color code.
To make things easy install
Blueman Bluetooth Manager. In Ubuntu this is pretty easy, just open the Ubuntu Software Center, type the program name and install it from there. When the installation is complete, open the program and search for devices. Make sure the Sphero is flashing its color code. Once the Sphero appears in the list of devices, select it, click on setup and follow the instructions.
You can connect and disconnect the Sphero from a serialport interface by right clicking on it inside the Blueman list of devices and selecting
disconnect, respectively (after it has been setup and added permanently to the list). Make sure to notice the serialport address Blueman displays after the Sphero connects, as this will be the one used in your code. The serialport address displayed for the Sphero should look something like this:
Locate the Bluetooth icon in the taskbar (or inside the system task tray button) and follow the necessary steps to pair with your Sphero.
Once you've successfully paired your Sphero, there are two options available to you to check and see which serialport corresponds to the Sphero you just connected. The first option is to right click on the bluetooth icon in the task bar (same you use to pair), click on
Open Settings, when the settings window appears, navigate to the
COM Ports tab where you should see a list of ports which should list your Sphero. If your Sphero is listed in more than one port, take note of the one that has
RN-SPP in the name, and use that one to connect. The list should look something similar to:
In the above case, you should use serialport
The second option is to identify the port number. Click the
start button and type
device manager. Once the program appears in the list, open it. Navigate the tree of devices to
Ports, there you should see a list of COM ports, i.e.
(COM3, COM4). From that port list, select the one that belongs to your Sphero. If your Sphero name is not listed in the ports list, you can either try them one by one or use the first method to identify which port belongs to your Sphero. The port address should look something like:
COM2, COM3, COM4
To initialize and connect to a Sphero:
var sphero = require"sphero"orb = sphero"/dev/rfcomm0";orbconnect// Sphero's connected!// do some cool stuff here!;
Once connected, you can give Sphero commands:
orbconnect// roll Sphero forwardorbroll150 0;// turn Sphero greenorbcolor"green";// have Sphero tell you when it detect collisionsorbdetectCollisions;// when Sphero detects a collision, turn red for a second, then back to greenorbon"collision"console.log"collision detected";console.log" data:" data;orbcolor"red";setTimeoutorbcolor"green";1000;;;
For more examples, check out the
The Sphero.js module is currently compatible with Node.js versions 0.10.x thru 4.2.x.
npm install to install development dependencies. You will also need to install Grunt by running
npm install -g grunt-cli
You can then run tests with
grunt lint to run ESLint against both
grunt command by itself will run both of the above tasks.
Copyright (c) 2015 Orbotix.
For more details, see the