Programming With Robots, Part I: Sphero SPRK

Reading Time: 7 minutes

Robotics Kits

For a kid who discovered a love of programming during the Reagan administration, it wasn’t easy growing up in a small Midwestern farming town. My high school computer teacher was a wonderful woman, but the computer class she taught consisted of playing Oregon Trail, using a word processor, and creating crossword puzzles on the school’s dozen or so rapidly deteriorating Apple IIe computers. One year, I even entered a program I wrote into the “computers” division at the 4-H fair–I was the only entrant. So when the school decided to offer computer programming classes, it was quickly apparent to my teacher, and to the three of us who signed up, that we were all going to have to figure it out as we went along. We played with Pascal, flipped through FORTRAN books, and generally just goofed off on the computer. (Did you know that on the old Mac, you could set it to play a sound on every keystroke? After the 90th “Are you out of your Vulcan mind,” our teacher did.)

Fast forward 20 years. My wife and I are touring the middle school where my oldest son would soon be attending 7th grade. As we walked into the computer lab, I was floored by, and more than a little envious of, the resources available to these kids. They had Photoshop classes, classes where students can produce their own movies or music, and the kicker, an entire section on robotics and programming with LEGO Mindstorms.

Unfortunately, this is not the norm across the country. Although schools regularly recognize the importance of computers and the internet, many are simply raising up a generation of technology users who have no concept of how anything works. As mobile technology and the “app” culture advances, this disconnect between computer users and programmers grows even wider. Even so-called STEM (and its cousin STEAM) programs frequently focus on technology use (e.g. CAD/CAM, engineering software, Matlab, etc.) over technology development. Perhaps that is why, despite the increase in the popularity of the STEM program, only 1 in 5 STEM college students believe K-12 education prepared them extremely well for relevant college coursework.

With the popularity of this year’s BattleBots reboot, as well as movie robots such as Chappie, Ultron, and Star Wars‘ BB-8, now is a great time for educators or parents to spark an interest in programming via robotics. Hardly a day goes by where someone else isn’t announcing a new Internet of Things or robotics project on Kickstarter. We at GeekDad got our hands on a number of different kits, from closed system units to expandable kits that snap, plug, or solder together. Whether you’re looking to instruct one student or a dozen, at home or at school, from pre-K to college level, there is likely a kit that fits your need.

Note: I am using “robotics” as a catch-all term to refer to any device that is controlled by a computer program. This includes both movable robots like Johnny 5 and C3PO and fixed location robots like the one that puts on door hinges at the Ford factory, as well as devices that have no moving parts such as PLCs and Arduino.

Sphero SPRK 1

Just released today from Sphero, makers of the fun little remote controlled ball that sparked an entire development community, is the SPRK Edition Sphero. Designed to accommodate everyone from beginners to experienced programmers, the SPRK (Schools/Parents/Robots/Kids) edition was created with the idea that learning should be fun and that there is value in play.

The first big change in the SPRK Edition Sphero is the ball itself. Instead of the translucent white shell of previous versions, the new Sphero is completely transparent. If, like our family, you have a young hardware hacker who has to know exactly how everything works, but who rarely can reassemble things the way he found them, the transparent shell is a lifesaver. Now kids can see exactly how the drive system works, and, in doing so, better understand the correlation between a programming command to “turn right 90 degrees” and the action taken to complete this command. For even more detail about the inner workings of the Sphero, the new SPRK app, also released today on Android and iOS, includes a 360 degree exploded view of the robot with all of the parts labeled.

The true power of the new app, however, is its new block-based programming interface. This zero code solution allows anyone to start programming the Sphero SPRK right out of the box without any prior coding experience. Want to turn the LED red? Simply drag the “Set Color” command block to the main screen and snap it to the “On Start Program” block. Other actions include setting the speed, heading, and directly controlling the motors individually. You can also listen for events like “On Freefall,” “On Collision,” and “On Land,” and perform actions based on these events. Sensors on the device can give feedback regarding heading, speed, and vertical acceleration, and you can use these values as parameters for other actions or operations (e.g. “if Speed is greater than 100, set LED light to red”).

If all of this sounds way too confusing, 12 sample programs are included. They cover all of the functions, and you can edit and save each one instead of starting from scratch. In addition, the app includes a link to the Sphero community where in the future you will be able to download programs from others and share your own programs with the rest of the community. In keeping with the educational nature of the SPRK Edition Sphero, all of the block based programs are simply a user-friendly interface for the Sphero code itself, which is written in OVAL, Sphero’s own version of C, and which is visible for each program by tapping code view button in the upper right corner of the block programming screen. Future versions of the app will allow direct editing of the OVAL code for more advanced programmers who want to start out with the blocks but then make changes in the code itself.

The Test

sphero sprk edition box contents

Minutes after the box arrived in my office, I had the Sphero sitting on the charger and was installing the app on my iPad Mini. Firing up the app, I ran into my first problem with the device. The instructions on the screen said to tap the Sphero twice to turn it on. I assumed it was touch sensitive, and was gently tapping the ball in every spot imaginable to no avail. My son, for whom delicacy is not his strongest trait, picked it up and *THWAP* *THWAP*, it came right on.

And that’s the first thing you have to realize about the Sphero. This sucker is durable. I’ve played with a number of DIY robotics kits, and this is the first where they actually suggest actions like running into things, throwing it up in the air, and tossing it in water! My idea of an “On Collision” method would be:


OnCollision(){
   TakeExpensiveRobotAwayFromChild();
}

Sphero does recommend not dropping the device from a height of greater than six inches, nor kicking or throwing it. While I’m not recommending taking it to soccer practice or chucking it off the roof, our Sphero did get accidentally kicked a number of times and dropped off the desk at least once, apparently without any ill effect.

Once you come to the realization that you’re not going to break it, playing with the Sphero becomes a joy, which is the entire point of the SPRK Edition. Play drives inquisitiveness, which drives discovery and education. We quickly went through all 12 sample programs and started creating our own, both from scratch and using the samples as a starting point. Can we drive it completely around the house? How high can we make it bounce by directly manipulating the drive motors? Can we combine side to side motions and lighting effects to make the Sphero “dance?” What happens if we tweak the code to try to do two things simultaneously?

Unfortunately, this is where we ran into the biggest limitation of the SPRK Edition Sphero. While you can view the source code in order to understand how the program you just wrote looks in OVAL, you cannot directly edit the code. My 13-year-old was about 10 minutes into the programming before this question came up, so it’s something to be aware of if you have a kid who is a little more experienced with coding. However, I asked Sphero about this limitation and they do plan to add it as a feature in a later release of the app. Also, if you’re used to programming with kits like littleBits or Cubit, the inability to add modules to expand functionality can be disappointing, particularly when you start considering the possibilities (cameras for autonomous navigation, ultrasonic sonar for object avoidance, etc).

SPRK Packaging Small

Don’t let these limitations dissuade you, though. While it’s easy to criticize based on a bulleted list of missing features, Sphero excels at the one thing that is lacking in too many other robotics kits: it’s incredibly fun and easy to use. I’ve had other kits sit on my workbench for weeks with the kids showing little but a passing interest, but as soon as the Sphero came out of the box, both of my boys were clamoring for the chance to get their hands on it. My concerns about the programming environment being too simplistic for my 15-year-old CS student were quickly assuaged. Heck, I’ve been writing software for years and, despite a few missing features I’d like to see added in future versions (e.g. multi-selecting blocks for moving or deleting), even I enjoyed creating custom programs with the block-based language.

On top of all that, it’s still a Sphero, and the new app includes the ability to put the programming on hold and simply have fun driving it around the house, or with the addition of the Nubby Cover, around the neighborhood. Plus, when you’re not using it as a programming platform, the SPRK Edition Sphero can be used with the more than a dozen games and apps created by Sphero for both Android and iOS, including Sphero Golf, The Rolling Dead, and Sphero Draw ‘N Drive.

According to Sphero:

There’s no rule that says learning shouldn’t be fun, or that playing can’t be valuable. If there is, we created SPRK Edition to break it.

Mission Accomplished.

SPRK Edition Sphero is available today at Amazon, Target, Sphero.com, Brookstone, and other retailers.

Get the Official GeekDad Books!