Connect & play around with BB-8 by Sphero with JavaScript on a Mac

Posted on in JavaScript Robotics

I'm a huge Star Wars fan, and like most of you, i've seen The Force Awakens as well. I immediately felt in love with BB-8. The little white orange droid.
So you can imagine, how happy I was, when I opened my christmas presents, and found the little BB-8 by Sphero droid in a box.

BB-8 by Sphero, is a little toy robot that you can control with apps for Android and iOS, via bluetooth. Actually the sphere is the true robot, BB-8's head is attached to the big sphere, via a magnet, and it has little wheels so it always stays on top, and gives it the Looney Toones Road runner look, while rolling. Cute.

This little droid has the following functionalities; it can roll around (quiet fast,), it can listen to your voice (via the app), it can show colors, it has IMU, 3 axis accelerometer, 3 axis rotation gyro and locator sensors.
The BB-8 uses a Bluetooth Low Energy (LE) interface, also known as "Bluetooth Smart" or "Bluetooth 4.0/4.1". What's really awesome is that Sphero opens up their APIs, so developers like me, can play around with this. And that's great.
There are SDKs for Android, iOS, Windows development, and there's a JavaScript SDK!

Since I'm a JavaScript lover, I thought, let's give it a go, and try this out myself. Here's are the steps that I took, to get it all up and running.

I tried it on a Mac OSX with XCode installed. You will need an editor and Node JS on your machine. With these base requirements, you will need to install the Sphero SDK, and also Noble, a hardware adapter that supports the Bluetooth 4.x+ standard to connect your computer to your BB-8. https://github.com/sandeepmistry/noble
With Noble, you can read out the bluetooth information, which you will later need while writing your code.

To get Noble up and running I had to fix my system paths. I've added the following to my bashprofile, to make sure Noble and XPC-Connection which is what the package uses under the hood, don't run into build errors:

export MYBIN=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin
export PATH=${MYBIN}:${PATH}

Then afterwards, run the following commands to make a connection from your computer:

The UUID is what you'll need. I wrote this simple script, which I run in Node to make a simple connection with my little friend, and read out his information:

It doesn't do anything special yet, other than switching some colors, but this is a great start. My next goal will be to create my own Sencha universal app, to control BB-8 via a web interface. I'll need a Node JS Express back-end for that: Once, I'm done with that I can share this, in another blog post, but here's a start:
https://github.com/savelee/bb8-starwars

For now, take a look into these resources:

Comments

  1. oleg says on
    January 20, 2016 at 8:50 am
    Reply

    Thank you for the post.
    It is very useful. I also have a bb-8 and sphero 2.0, and playing around with them.
    BB-8 works well with nodejs om my mac, now I’m trying to do the same with my Windows station.

  2. Agustín says on
    May 12, 2017 at 10:58 am
    Reply

    I have an SPRK+ from Sphero and with your help, I managed to connect it to my mac. But the first connection is so slow, it takes about 30 seconds… Does it happen to you as well?

Post a Comment

Your email is never published nor shared.
Required fields are marked *