With Scratch2Sphero, you can control Sphero 2.0 from Scratch 1.4. Tested on MacOS X(10.8.5, 10.9, and 10.9.1).
- Sphero - This is the physical robot ball that you'll be controlling
- Scratch 1.4 - Programing environment
- hybridgroup-serialport - Used by the sphero gem to talk bluetooth
- sphero gem - Used by the script to talk to the sphero api
% git clone https://github.com/champierre/scratch2sphero.git
% bundle install
or
% git clone https://github.com/champierre/scratch2sphero.git
% ('sudo' if necessary) xcode-select --install # optional step depending on the state of your development tools. if you get errors building the gems, try this
% ('sudo' if necessary) gem install hybridgroup-serialport
% ('sudo' if necessary) gem install sphero
If you cannot use git, you can download the source code from "Download ZIP" button appeared on the right side of the README page.
- Pair your computer with your Sphero. Do this via the Bluetooth pane in settings. Remember, it can only be paired to one device at a time, so turn off bluetooth on any other devices you might be using.
- On Scratch, right-click on the () Sensor Value block, found in the Sensing category, and select the "Enable remote sensor connections" option.
- On the terminal, run scratch2sphero.rb. You can then monitor this terminal window for any debug information.
- Use Scratch variable "steps" and Broadcast "move" to make Sphero roll. The number set for "steps" is the duration that Sphero keeps moving.
- Use Scratch variable "degrees" and Broadcast "turn" to make Sphero turn. The number set for "degrees" is the degree that Sphero turns.
- (Alternative) Use Broadcast backward/forward/left/right block, found in the Control category, to make Sphero roll to the direction specified.
- You can use the following Scratch variables to change the behavior of Sphero.
- speed(default: 20) - roll speed
- initial_heading(default: 0) - initial heading in degree
To help your users know which direction the ball is facing, you might want to toggle the back LED
- Use the "back_led_on" broadcast to turn on the little light to tell you were the back of the ball is
- Use the "back_led_off" broadcast to turn the light off
Who doesn't like rainbows? Especially blinking double rainbows. You can control the main LED color of Sphero via the color broadcast.
- create a global variable named color_name and assign it a color name, then broadcast "color".
- you can also define new broadcasts with color_name where name is one of the valid color names, e.g. broadcast "color_cadetblue" or broadcast "color_crimson"
- if you send it an invalid, or blank, color name, it will restore to the saved default color for your Sphero