Programming with the Sphero BOLT

Programming with the Sphero BOLT

My first exposure with robots was at an engineering camp I attended when I was 15, and let me tell you: it was not love at first sight. I loved the programming aspect of it (that camp was also where I was introduced to programming), but I never developed a love for sticking bits of machinery together.

I avoided it so thoroughly that I managed to escape a (now mandatory) class in university that involved building robots. While my friends were playing with arduinos and drones, I was reading books about data science and the human mind.

Enter, the Sphero Bolt

When I was asked if I’d like to try out the new Sphero Bolt I was skeptical. I knew they were a robotics company and I don’t like advocating for products that I, well, don’t like. However, after unboxing it and fiddling with it for thirty minutes I was completely sold.

The Sphero Bolt is a small plastic orb with machinery inside (the guts don’t just make it move and light up, but also have a host of sensors that I haven’t even begun to explore). It differs from Sphero’s other products in that it has a matrix on top that can be used to spell out words or create shapes which provides a whole different level of interaction.

A robot for the sake of being a robot? Not cool.

A robot for the sake of education? I can get behind that.

A robot that you can program to interact with a human (or group of humans) that is also educational? Count me in.

The Bolt also happens to be cute and compact – coffee cup for scale

In terms of programming, you can choose what level of complexity you’re comfortable with. They have both phone and computer apps that act as IDEs (development environments) with drag-and-drop capabilities as well as the ability to program in JavaScript. Then again, if you feel like just using the Bolt as a remote-control ball so you can run into people’s ankles, you can do that too.

Programming a Party Game in JavaScript

I don’t have a ton of room in my one-bedroom apartment, so I had no desire to set up a maze or obstacle course that I’d be tripping over for days. After looking at some of the programs published by the Sphero community, I realized that the matrix could act the interface for a video-game, but instead of buttons to push you can use the sensors to interact with it through collisions and tilts.

For my first interactive program i decided to go simple, very simple.

  • I have 8 different frames (images), 7 of them are hearts in different colors, and 1 of them is a little fire symbol
  • The Bolt starts out with a heart
  • When it senses a collision, it randomly choose a number between 0 and 7 and displays that frame
  • Rinse and Repeat

 

If I’m being honest, I’m unreasonably proud of the flame symbol I came up with

 

Their IDE is contained within the Sphero Edu app that you can get on either your phone or computer (or both) – it has a fair number of pre-named functions, auto-complete, and the IDE will throw errors to help you debug your code. This means that if you want to try your hand at textual programming but have never used JavaScript before you won’t get totally lost.

The IDE also allows you to do “block” programming (and it can translate the block programming into JavaScript). Block programming is akin to programming in sentences; it involves pre-made instructions you drag-and-drop into order then fill in the blanks:

“Turn 90 degrees and travel for 2 seconds” or “Show this picture on the screen”.

All this is to say that if you’re hesitant to dive right into JavaScript (or if you’re using this with a child who’s not ready for functional programming) you can create a program using the blocks and then view the JavaScript code after you’ve perfected your program.

This is what the code looks like:

// This is triggered as soon as the program starts
async function startProgram() {
	playMatrixAnimation(0);
}

// This is triggered each time there is a collision
async function onCollision() {
	 var randomNumber = getRandomInt(0, 7);
	 playMatrixAnimation(randomNumber);
}

registerEvent(EventType.onCollision, onCollision);

// Each frame is registered separately
registerMatrixAnimation({
	frames: [[[0, 0, 0, 0, 0, 0, 0, 0],
			  [0, 1, 1, 0, 0, 1, 1, 0],
			  [1, 1, 1, 1, 1, 1, 1, 1],
			  [1, 1, 1, 1, 1, 1, 1, 1],
			  [0, 1, 1, 1, 1, 1, 1, 0],
			  [0, 0, 1, 1, 1, 1, 0, 0],
			  [0, 0, 0, 1, 1, 0, 0, 0],
			  [0, 0, 0, 0, 0, 0, 0, 0] //Heart
			 ]],
	fps: 1,
	palette: [
		{ r: 0, g: 0, b: 0 }, 
		{ r: 255, g: 0, b: 0 }] // Red
});
	
registerMatrixAnimation({
	frames: [[[0, 0, 0, 0, 0, 0, 0, 0],
			  [0, 1, 1, 0, 0, 1, 1, 0],
			  [1, 1, 1, 1, 1, 1, 1, 1],
			  [1, 1, 1, 1, 1, 1, 1, 1],
			  [0, 1, 1, 1, 1, 1, 1, 0],
			  [0, 0, 1, 1, 1, 1, 0, 0],
			  [0, 0, 0, 1, 1, 0, 0, 0],
			  [0, 0, 0, 0, 0, 0, 0, 0] //Heart
			 ]],
	fps: 1,
	palette: [
		{ r: 0, g: 0, b: 0 },
		{ r: 119, g: 136, b: 153 }] // Grey
});

registerMatrixAnimation({
	frames: [[[0, 0, 0, 0, 2, 0, 0, 0],
			  [0, 0, 0, 2, 2, 0, 0, 0],
			  [0, 0, 2, 1, 2, 0, 0, 0],
			  [0, 0, 2, 1, 2, 2, 0, 0],
			  [0, 0, 2, 1, 1, 2, 2, 0],
			  [0, 2, 2, 1, 1, 2, 2, 0],
			  [0, 2, 1, 1, 1, 1, 2, 0],
			  [0, 0, 2, 2, 2, 2, 0, 0] //Fire
			 ]],
	fps: 1,
	palette: [
		{ r: 0, g: 0, b: 0 }, // Black
		{ r: 255, g: 0, b: 0 }, // Red
		{ r: 255, g: 97, b: 3 }] //Orange 
});

registerMatrixAnimation({
	frames: [[[0, 0, 0, 0, 0, 0, 0, 0],
			  [0, 1, 1, 0, 0, 1, 1, 0],
			  [1, 1, 1, 1, 1, 1, 1, 1],
			  [1, 1, 1, 1, 1, 1, 1, 1],
			  [0, 1, 1, 1, 1, 1, 1, 0],
			  [0, 0, 1, 1, 1, 1, 0, 0],
			  [0, 0, 0, 1, 1, 0, 0, 0],
			  [0, 0, 0, 0, 0, 0, 0, 0] //Heart
			 ]],
	fps: 1,
	palette: [
		{ r: 0, g: 0, b: 0 },
		{ r: 0, g: 245, b: 255 }] // Turquoise
}); 

registerMatrixAnimation({
	frames: [[[0, 0, 0, 0, 0, 0, 0, 0],
			  [0, 1, 1, 0, 0, 1, 1, 0],
			  [1, 1, 1, 1, 1, 1, 1, 1],
			  [1, 1, 1, 1, 1, 1, 1, 1],
			  [0, 1, 1, 1, 1, 1, 1, 0],
			  [0, 0, 1, 1, 1, 1, 0, 0],
			  [0, 0, 0, 1, 1, 0, 0, 0],
			  [0, 0, 0, 0, 0, 0, 0, 0] //Heart
			 ]],
	fps: 1,
	palette: [
		{ r: 0, g: 0, b: 0 },
		{ r: 142, g: 56, b: 142 }] //Purple 
});

registerMatrixAnimation({
	frames: [[[0, 0, 0, 0, 0, 0, 0, 0],
			  [0, 1, 1, 0, 0, 1, 1, 0],
			  [1, 1, 1, 1, 1, 1, 1, 1],
			  [1, 1, 1, 1, 1, 1, 1, 1],
			  [0, 1, 1, 1, 1, 1, 1, 0],
			  [0, 0, 1, 1, 1, 1, 0, 0],
			  [0, 0, 0, 1, 1, 0, 0, 0],
			  [0, 0, 0, 0, 0, 0, 0, 0] //Heart
			 ]],
	fps: 1,
	palette: [
		{ r: 0, g: 0, b: 0 },
		{ r: 61, g: 89, b: 171 }] //Cobalt 
});

registerMatrixAnimation({
	frames: [[[0, 0, 0, 0, 0, 0, 0, 0],
			  [0, 1, 1, 0, 0, 1, 1, 0],
			  [1, 1, 1, 1, 1, 1, 1, 1],
			  [1, 1, 1, 1, 1, 1, 1, 1],
			  [0, 1, 1, 1, 1, 1, 1, 0],
			  [0, 0, 1, 1, 1, 1, 0, 0],
			  [0, 0, 0, 1, 1, 0, 0, 0],
			  [0, 0, 0, 0, 0, 0, 0, 0] //Heart
			 ]],
	fps: 1,
	palette: [
		{ r: 0, g: 0, b: 0 },
		{ r: 255, g: 182, b: 193 }] //Pink 
});

registerMatrixAnimation({
	frames: [[[0, 0, 0, 0, 0, 0, 0, 0],
			  [0, 1, 1, 0, 0, 1, 1, 0],
			  [1, 1, 1, 1, 1, 1, 1, 1],
			  [1, 1, 1, 1, 1, 1, 1, 1],
			  [0, 1, 1, 1, 1, 1, 1, 0],
			  [0, 0, 1, 1, 1, 1, 0, 0],
			  [0, 0, 0, 1, 1, 0, 0, 0],
			  [0, 0, 0, 0, 0, 0, 0, 0] //Heart
			 ]],
	fps: 1,
	palette: [
		{ r: 0, g: 0, b: 0 },
		{ r: 0, g: 205, b: 102 }] //Cobalt 
});
Sphero Bolt Party Game

A collision is registered when the Bolt senses it’s run into something. Traditionally, this would be hitting a wall or other object, but it can also be something like being tapped or landing in someone’s hand after being thrown.

In terms of making this into a game there’s a lot of flexibility and variations you can do with this select-a-random-image pattern. Personally, I like the idea that when someone gets the fire symbol they have to answer a question or do something silly (or a different activity, depending on the age group).

This program could also be easily modified into some kind of icebreaker used by an organization by making each symbol represent a different get-to-know-you question, it could be used to decide where lunch-mates should go out to eat, or it could even be modified to create a “surprise workout routine” – if you wanted, you could get really complicated and add a timer to it. Like I said, the opportunities are endless even for adults.

To test your program you must have a bluetooth connection to load it up onto the Sphero Bolt, but it happens so fast (less than 10 seconds) that it’s easy to make minor adjustments and test as you develop.

TL;DR

Sphero sent me their new product to test out, and I absolutely love it. I can see how it would be great for teaching kids how to program, but even as an adult the applications seem pretty endless. In this blog post I explain the code for a simple game that you could use at a party or within a small group of people, but it could be modified to do pretty much anything. You can get your own here.



Share your experience

This site uses Akismet to reduce spam. Learn how your comment data is processed.


%d bloggers like this: