Hands-on with Swift Playgrounds for educational robots

What if you could use a single programming environment to learn to code at an early age, then use that same environment to explore programming for robots, IoT, Augmented Reality, and then take those projects into a full-blown programming environment? Apple’s Swift Playgrounds is a free app that aspires to do all of these things. I spent some time working with their new features for controlling educational robots, and here is what I found.

The Swift programming language was introduced in 2014, along with a feature called Playgrounds in Xcode, Apple’s main developer tool. The Swift Playgrounds app for iPad was introduced in 2016 as a “learn to code” environment aimed at children, but it is very much real programming. This spring (2017) it received substantial updates, including the ability to program several educational robots,

I spent some time using Swift Playgrounds with these robots:

Other robots are supported, including Parrot drones and Meebot, but I didn’t have a chance to test them.

What I found is a VERY promising beginning. The core Swift Playgrounds tutorials (Learn to Code) are really solid, and provide for a seamless transition into robotics. The robotics support is good, even though the level of finish and polish is variable. The ability to bring projects into XCode (Apple’s IDE) is an important bonus, and opens the path to more sophisticated projects.

  • Lego Mindstorms is very polished, with a useful Live View, and very complete support for the API. Documentation is extremely thorough. You can do everything you can do with the Lego software. It feels like an advanced step for students used to the Lego apps.
  • Wonder Workshops Dash is also well designed, but it seems like the API support is limited. It feels like you can only use the robot to a fraction of its capabilities, it may benefit from further api testing to maximize the capabilities of the API and robots communication. The tutorials are very easy, but without much of a growth path. It feels like an extension to basic Swift tutorials, instead of using this tool as a way to explore more advanced concepts.
  • The Sphero playgrounds are very solid, with complete API support, Live Views, and thorough documentation. Well structured Star Wars themed tutorials for the R2-D2 robot, and more general tutorials for the entire Sphero product line. This also feels like an advanced step past the native apps.

Keep reading for more detail on my experience.

In the Swift Playgrounds app, new Playgrounds can be added from scratch, or from a library. The robot programming setups are all in the Accessory tab. They often include a more structured tutorial as well as a blank template.

Authoring these tutorials is straightforward, including the addition of “dashboard” type elements for live control, images and video. Apple has published a full specification for creating your Playgrounds. (Interactive features are themselves coded in Swift, which is neat.)

In order to save typing, Playgrounds will autocomplete most of the robot API commands. You can get through the tutorials by pointing and clicking. When typing, Playgrounds has an interesting alternative keyboard layout that lets you add common coding constructs by swiping down on keys.

I tried Swift Playgrounds with some of the robots I have around the house, connecting and writing simple programs.

Lego Mindstorms EV3

Swift Playgrounds for Mindstorms includes both a structured tutorial and a blank template.

The Lego Mindstorms tutorial is well constructed, with a narrative about creating animals and helping them survive. The set of lessons ramps up the difficulty level slowly, starting with tips on connecting the EV3 Brick and testing with a limited set of motors, and progressing to the construction of a moderately complex “turtle” bot.

A very attractive feature is a Live View that is active when a robot is connected, which displays real-time status of any connected motors and sensors. A Graph View page keeps track of values over the time. These can be logged and saved.

The implementation of the EV3 API (application programming interface) is extremely thorough. Every function available in Lego’s own software seems to be supported, including movement functions for robots with two motor drivetrains. The documentation is completely populated, with both the Glossary and pop-help features providing extremely detailed information, including assembly instructions for a sample robot that works with the tutorials.

The blank template includes the complete API, the Live View and the Graph View, but none of the structured tutorials.

I found the Lego Mindstorms EV3 support in Swift Playground very thorough and easy to use, with real potential to build interesting apps. If you are already using Mindstorms, this will substantially expand your possibilities at no extra cost.

The one downside is that, unlike the native Lego apps, programs are not compiled and uploaded to the robot. The programs you write run on the iPad, and control the robot remotely. This means you need to keep an iPad connected while using the robot.

Wonder Workshop Dash

Wonder Workshops seems to have taken a completely different tack.

The Dash robot is aimed at younger children, and the Swift Playgrounds support reflects that. The graphics and lessons are consistent with the Wonder Workshop apps. I’m not sure this is entirely a good idea: why not use the native apps to serve the younger audience, and use Swift Playgrounds to enable more sophisticated projects? The API support is very limited, with MoveForward() and TurnLeft() and TurnRight() functions like those in the beginning Swift tutorials (move a step, turn left or right 90 degrees), whereas the robot is capable of much more. The native apps have much better control of movement speed, turning on the various LEDs, etc.

The built-in documentation features in Swift Playgrounds are not used at all, which is frustrating. You have to rely on the AutoComplete features to figure out what commands are available.

In general, a child that has completed the first few Swift tutorials will easily understand this playground, but might get bored rather quickly. Given that this system requires much more reading and writing than the native apps, there seems a bit of a mismatch here.

I was surprised that a robot positioned for “learning to code” didn’t make more of the Swift Playgrounds opportunity – perhaps they are trying to steer users to their own apps. If you already have a Wonder Workshops Dash robot, Swift Playgrounds does not add much (if anything) beyond the native apps.

Like the others, there is both a structured tutorial and a blank template for programming.

Unlike Mindstorms, the Dash robots already rely on a tablet or phone for their programming, and that is the same with Swift.

Sphero R2-D2 and BB-8

Sphero seems to have really jumped on the opportunity to do something interesting with their robot offering. The Playground templates include one specific to the newly released R2-D2 toy, with a series of detailed Star Wars themed challenges. Another template is called Sphero Arcade, and is more focused on Sphero’s original spherical robots (which are compatible with their BB-8 toy). Finally there is a blank template.

All the materials look good, with thorough documentation, full support of the API for R2-D2 and BB-8, a nice sensor view, and a dashboard built in Swift that allows manual driving of the robots.

The Sphero Playgrounds suffered from connection issues early on, but those appear to have been fixed with a recent IOS update. I was able to detect and connect to both R2-D2 and BB-8.

If you already have a Sphero robot, Swift Playgrounds is a good way to increase their possibilities. In particular, since some of the Spheros are marketed as toys, this is a way to gain some more educational value from them. Compared to the native apps (both the toy control and the Sphero EDU apps), you are able to write more complex programs.

Taking it further – connecting with XCode

One of the more intriguing features is that Swift Playgrounds are themselves built in Swift, and can be created and extended using XCode. Apple has provided complete instructions to the Playground format.

Playgrounds are saved in iCloud Drive, and can be directly opened in XCode on a Mac. Since everything is built in Swift, including the code to connect to robots, it is possible to take a project started on the iPad and convert it to a full-blown IOS app (with some work). I found it really interesting to browse the code for connecting to the different robots with Bluetooth, and to provide the Live View functionality. You can also build your own Playgrounds templates following Apple’s instructions and add support for new robots this way.

This is a very interesting development. Someone can learn to code from the most basic level, and progress on to controlling various different robots. It is possible to take code from a Playground and eventually use it to build a self-contained app for MacOS or IOS.


Swift Playgrounds is worth a look by anyone involved in educational robotics. It provides a seamless path from the very beginnings of programming all the way to a variety of robot platforms. For some of the supported platforms, Playgrounds is at least as good as the native apps supplied with the robots, with the benefit of being a real, generally applicable programming language. Many robot programming solutions are very specific to the world of robots, and transferring lessons learned to and from other systems is not easy. Swift makes this seamless.

The ability to examine the Playgrounds themselves, and borrow code from them to make real apps, is also interesting.

2 comments to Hands-on with Swift Playgrounds for educational robots

  • Dave

    where are the playgrounds associated with sphero and Mindstorms?

    • vill30

      When you click “New Playground”, at the bottom of the screen you see the options Learn to Code, Challenges, Accessories and Starting Points. The robot playgrounds are all in Accessories.