Build Robots, Learn Swift

Lego EV3 Mindstorms is a robotics system for education that is very popular at elementary and middle school level, for good reason. Using this platform, kids can learn the basics of mechanical engineering and mechatronics in a format that they already know. A more familiar framework for learning means kids get to the good stuff faster.

So what's the catch? Lego's proprietary EV3 programming platform is, well, proprietary. Though kids can learn many fundamental coding concepts, that learning is tied to a block-based interface they'll never see again. It can also be a frustrating application to use.

Screenshot of Swift Playgrounds Lego Mindstorms EV3 activity introduction.

Enter EV3 Extension Activity for Swift Playgrounds

EV3 has an API for programming that has been wrapped into a Swift library. Cool! Educators and parents can download two EV3 extension packs through the "What's Next" links inside Swift Playgrounds.

EV3 Animal Rescue Pack

The first download is a guided tutorial introducting programming structures used to control the robot and retreive data from its sensors, and also illustrated building concepts such has how to attach a motor the control module (also known as the Brick).

This activity is fun for kids because it is presented in story format, and there are specific objectives at each step. Much like Swift Playgrounds standard content, kids can guide their character to complete tasks. In this case, their character is a robot in real life, that they've built themselves!

There are no step-by-step instructions for building in this pack. Kids are given hints about how to build the robot rather than handed the solution. Figuring it out is part of the fun! The programming lessons are progressive, so not all features of the Swift EV3 library are available at all times in the auto-complete feature. This can be frustrating for kids who immediately think "that's cool, now what if I..." - guiding them to the full reference so they can "skip ahead" or extend the activity with more features will help.

Another feature great for learning is the raw sensor feedback shown when the brick is connected to the iPad. This facilitates discussions about how sensors work and what they measure, and also how that information can be used to help the robot make decisions about what it will do next.

EV3 Template

The other available download is a template that can be used for any EV3 project. There is no guidance in this pack, so it's important to do the tutorial first to learn the names of classes/methods and availability of features through the Swift Playgrounds interface. The Glossary found under the "..." menu in the sandbox area contains a list of methods in the ev3 object - but unfortunately is not complete and does not show the signatures. Click here for a more complete reference compiled by a generous community member.

Troubleshooting

The brick connects to the iPad over bluetooth, and it can sometimes be fussy. Go to Settings and disconnect the EV3 device if you're having trouble connecting through the Swift Playgrounds app.

Have fun!

We think this activity is pretty neat - and love that it introduces kids to a real programming language that they might use in the future in other contexts. Try it out and let us know how it went in the comments!