File Exchange

image thumbnail

Sphero Connectivity Package

version (730 KB) by Danvir Sethi
Control a Sphero from MATLAB and Simulink


Updated 16 Jul 2018

View Version History

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

Sphero is an inexpensive differential-drive robotic ball that can be controlled from a Bluetooth enabled device. It features a number of sensors (accelerometers, gyros, back-emf encoders) which allows it to measure its position and velocity with a fair degree of accuracy. The Sphero's RGB LEDs allow it to glow in any color of choice, while the blue back LED indicates its current orientation. Two wheels allow the Sphero to roll on the ground and to rotate along its vertical axis.
This package (which works with MATLAB releases 2014b and newer) allows us to communicate with a Sphero from within MATLAB (and Simulink), on a computer running either Windows or 64-bit version of Mac OS 10.7 or earlier.
The package is mainly based upon a "sphero" class, which in turn relies on the MATLAB Bluetooth class. The class methods and properties allow you to perform (within MATLAB) many operations available with the underlying Sphero API, such as connecting, disconnecting, sleeping, changing LED colors, reading (and/or streaming back) the Sphero's position and velocity, and commanding each of the 2 motors independently. An higher-level roll command can also be used to move the Sphero with a certain speed and direction. The Simulink library contained in the package also features Simulink blocks for setup, timing, and basic sensing and actuation.
The readme.txt file explains how to pair up the Sphero to your computer, install the package, and create Sphero objects in MATLAB, while several examples are also included to illustrate the use of the available commands and Simulink blocks.
NOTE that the 'readLocator' capability was temporarily removed in version 3.71 of the Sphero firmware, so if you need this functionality you need to use either an older or newer version of the firmware.

Cite As

Danvir Sethi (2021). Sphero Connectivity Package (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (12)

Aydin Can

Hi, I was wondering if this package will be updated in order to support the SPRK+ or the sphero mini, as the Sphero 2.0 and the Sphero SPRK have now been discontinued

Somasundar Kannan

The simulink examples don't seem to work as shown in the examples page. Is there any problem with the simulink model of the sphero?

Somasundar Kannan

Does it work with Sphero mini?

Jose Lara

Philippe Hautcoeur

Hi Danvir thank you for your quick answer. You've made a great job!

Danvir Sethi

Hi Philippe,
The package is compatible with the Sphero 2.0 and Sphero SPRK versions. It is not compatible with the Sphero SPRK+ or the BB-8 because they use the Bluetooth Low Energy(BLE) or Bluetooth Smart technology, which is currently not supported by the Instrument Control Toolbox.

Philippe Hautcoeur

Sorry I wanted to say Sphero SPRK or SPRK+ version

Philippe Hautcoeur

hi Danvir! Thank you for this great work. Is it compatible with sphero 2.0?


Mark Tomaszewski

Hey Danvir,

I'm playing with your m-code with great interest as a collaborator on the only other Sphero projects here on FEX.

I didn't get too far without throwing an error due to Matlab release compatibility, and so I'm commenting with a "bug-report" and description of my quick patch.

I'm using r2013a which doesn't seem to support the inputParser/addParameter. However, My version does support inputParser/addParamValue with (I think) the same signature. I threw my first error on line 770 of "sphero.m" when calling sphero/logSensors on line 230 of "sphero_getting_started.m"

Wrap addParamValue with a user-defined function addParameter. This seems to be working for me. I just added this function to my search path:

function out = addParameter(varargin)
out = addParamValue(varargin{:});

Siddharth Sundar

Darsana Thulasi

MATLAB Release Compatibility
Created with R2014b
Compatible with R2013a and later releases
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!