TouchDevelop and the BBC micro:bit

From its conception in 2011, the TouchDevelop project has been about bringing the joy of learning to program modern devices such as smartphones and tablets, as well as laptops and desktops.

The TouchDevelop team is proud to be part of the BBC micro:bit project. The micro:bit is a small wearable and programmable mbed-based device that visibly features a 5x5 LED display, accelerometer, compass, buttons, I/O pins, Micro USB plug, Bluetooth Low Energy antenna, ARM Cortex-M0 processor, and battery plug.

The micro:bit provides a fun introduction to programming and making – switch on, program it to do something fun – wear it, customize it, Just like Arduino, the micro:bit can be connected to and interact with sensors, displays, and other devices. The first wave of micro:bits will land in UK schools this autumn, with every Year 7 student in the UK receving a micro:bit, for free.

As a partner on the micro:bit project, our goals are to provide: (1) a browser-based introductory programming experience for students who have never programmed before; (2) an architecture that allows students to dig deeper to uncover the many capabilities of the micro:bit; (3) materials and a platform to support teachers with the micro:bit in their classrooms.

Read on to see how we have enhanced TouchDevelop and are working with ARM, Lancaster University, and Computing at School to realize these goals.

Languages, Editors, Compilers

We extended TouchDevelop to support a progression of languages with accompanying browser-based editors. The Block Editor provides an introduction to structured programming via blocks that can be snapped together. TouchDevelop introduces a statically-typed scripting language with syntax-directed editor.

Browser-based compilers from the Block Editor to TouchDevelop and from TouchDevelop to C++ automate the transition from a visual language to a text-based language, and then to the language (C++) of the mbed-based micro:bit. The first compiler allows a student to convert a Block Editor script into a TouchDevelop script with a single press of a button.

Coding with TouchDevelop

To go from the world of browser-based scripting languages to that of the micro:bit's ARM Cortex-M0 Processor , we defined a subset of the TouchDevelop language for programming the micro:bit. Here's an example of a TouchDevelop script that counts up as the user presses the A button:

TouchDevelop count program

The language subset contains: while and for loops; if-then-else conditional statement; functions; local and global variables; integer, boolean, string and image types; operations over values of the above types; user-defined event handlers and libraries.

Compile and Flash

When a student has her TouchDevelop script ready, she can connect her micro:bit to a computer via a USB cable, so it appears as a mounted drive.

Compilation from TouchDevelop to the micro:bit proceeds into two steps. The first step (Compiler 1) compiles the TouchDevelop script to a C++ program , in the web browser.

This C++ program then is sent to ARM's mbed compiler service where the second compilation step (Compiler 2) takes place, compiling the C++ program into an ARM binary program number 3, which is sent back to the web browser.

The student is prompted to save the ARM binary program to a file, which she then simply drags to the micro:bit mounted drive, which flashes the micro:bit device number 4 with the new program.

compilation toolchain

Simulator: Test Your Code

Before a student compiles her script for the micro:bit, she can run it using the TouchDevelop micro:bit simulator, all within the confines of a web browser. The simulator has support for the LED screen, buttons, as well as compass, accelerometer, and digital I/O pins.

To run a student's TouchDevelop script in the web browser, TouchDevelop compiles it into JavaScript, the scripting language built into all web browsers.

C++ and TouchDevelop Libraries

The C++ micro:bit library, created at Lancaster University, provides access to the hardware functions of the micro:bit, as well as a set of helper functions (such as displaying a number/image/string on the LED screen). The TouchDevelop micro:bit library mirrors the functions of the C++ library. When a TouchDevelop script is compiled to C++, the calls to TouchDevelop micro:bit functions are replaced with calls to the corresponding C++ functions.

Above, see the mapping from the TouchDevelop "show number" function to its corresponding the C++ function.

Resources and Partnerships

In addition to the technology stack described above, we also provide in-depth online resources for the Block Editor, TouchDevelop, the TouchDevelop micro:bit library, and other TouchDevelop resources. The TouchDevelop authoring experience allows for "literate programming" and the generation of HTML pages and tutorials that contain example code fragments.

Working with master teachers from Computing at Schools (CAS), we will create micro:bit activities using TouchDevelop, mapped to the UK CS curriculum for year 7 students.

Events

The TouchDevelop team has run learning events for many years and already has engaged in the UK, running micro:bit workshops at the 2015 CAS conference. We will be part of the BBC's Make It Digital Tour, and plan to work with CAS to bring the micro:bit to their teachers in the fall. We also will be hosting a Virtual micro:bit Conference featuring professors, CAS master teachers, and students.

Over the summer, we will be podcasting micro:bit activities for teachers and students around the UK.