Teaching robotics with the BBC micro:bit

Jim Mussared
May 18, 2017 · 8 min read

For the past several years, I’ve been fortunate to help run the Embedded Programming stream at the NCSS Summer School, a high-school summer camp attended by over 130 students and teachers each year. Previously, we’ve taught Arduino but this year we decided to try something new: enter the BBC micro:bit.

The BBC micro:bit is a new embedded computing device produced by a collaboration of tech companies including ARM, The Python Software Foundation, Tech Will Save Us, Microsoft, and of course, the BBC. In 2016, every grade seven student in the UK was given a micro:bit. Getting technical, it’s an ARM Cortex M0, with onboard Bluetooth radio, accelerometer, compass, temperature sensor, 25 LEDs and two buttons. They can be programmed in a variety of languages, from MicroPython to JavaScript to C++, plus a selection of visual languages such as PXT / MakeCode and Blockly.

Students work towards a Robo-olympics project: a late-night robotics & fitness event where the groups go head to head in a set of interactive activities designed by the students themselves. Each group of about 2–5 students has to come up with their own idea, from push-up challenges and robo-soccer arm-wrestling, to ‘Dab Dab Revolution’, a modern take on Dance Dance Revolution.

Many of the students have no previous experience with electronics, robotics or programming, whilst some have been competing at a high level in other computing and robotics programs. This extreme disparity in experience makes teaching at a level where everyone is engaged and pushed rather challenging, but we are incredibly lucky to have a great team of tutors such that we have a student-to-tutor ratio of around 3:1.

Teaching electronics and programming together

Previously we’ve worked with embedded devices like Arduino that need additional components like LEDs or buttons to be wired externally before students can run a “Hello World” style program. Having external wiring as an additional, separate source of errors makes programs particularly hard to debug, especially when students are only just learning about debugging! We found that adding this extra hurdle got in the way of building a solid programming foundation.

2012: Last-minute debugging before sending it up in the plane!

When it came time to build much more sophisticated programs that involved external circuitry, debugging was a lot simpler and much less frustrating because the students had first learnt to write more robust and well-designed code. In the past, simple things like a wire falling out could be catastrophic.

When a student’s first experience with both coding and electronics is overly frustrating, it’s all too easy for students to write it off as uninteresting and complex. This year, we had much better engagement from the beginning, particularly with students with less coding experience.

Embedded programming with MicroPython

Using Grok’s micro:bit Crash Course in the lab.

We used MicroPython as the primary language for the summer school because it gives a great balance between simplicity and power. In comparison to C++ (which is used on many other similar devices, such as Arduino), the ability to get understandable error messages including traces and line numbers, removes a huge part of the frustration of getting your program working. We’ve watched students in the past being forced to litter their code with Serial.println to narrow down where the program fails (if it even reliably fails at all!), whereas on the micro:bit, errors like “IndexError on line 20” mean students know exactly where to look.

When combined with the MicroPython REPL (the Read Eval Print Loop), which allows the student to get an interactive Python prompt on the micro:bit itself, students can try out and explore what a piece of code will do without needing to upload a program, or even pause the current program and explore the value of variables and call functions. This facilitates a really useful way to learn by experimentation. We encouraged the tutors to ask questions like “what do you think will happen if…?” and the students could very quickly experiment.

We also explored the MicroPython ecosystem, including using the “pyboard” which has a much more powerful CPU and the ability to run much longer programs. One of the most popular exercises in the labs was to use the pyboard’s “HID device support” where it can pretend to be a USB keyboard or mouse. A few students also used the ESP8266 to add WiFi to their projects, although the additional time required to cover socket programming and run a server proved to be a little too much for the 10 days. It’s great that the MicroPython ecosystem allows the same code to be written and run on a wide variety of different devices, from micro:bits to satellites.

Python errors are easy to understand and fix!

Adding electronics to the mix

We then introduced line-following robots using a robot kit from Kitronik, and the students wrote code to control the robots and explore the behaviour of various control algorithms.

Making micro:bits talk to each other

Simple radio demo — sender detects button presses and receiver shows them on the display.

One limitation is that because MicroPython mode doesn’t support full Bluetooth functionality, the micro:bit can’t pair with a PC or Phone/Tablet. However, you can communicate with a PC by using another micro:bit plugged into the PC via USB and a simple Python program running on the PC to access the serial port.

Compared to using a Bluetooth module (e.g. with Arduino) the micro:bit radio was a huge success. The students had no trouble at all building activities that involved 10+ micro:bits, all communicating simultaneously with each other. A few students even experimented with building a mesh network and were able to successfully get micro:bits that were individually out of radio range of each other to still talk via the devices between them.

Project time: micro:bit robo-olympics!

Again, the radio proved fantastic. Being able to attach 6 micro:bits to a player’s arms, legs, head, etc. and not have to worry about connecting wires simplified program development and debugging, and opened up lots of opportunities. Players (and robots!) were free to move around — rather important in exercise games! If there was a problem, a replacement micro:bit could be used without worrying about pairing — just upload the same software and it was ready to go!

Another key part of the project was the non-computing side. A huge variety of craft supplies and hundreds of metres of masking tape went into creating some incredible physical interfaces, including sensor-laden vests, mazes for the robots, dance machines, control panels and displays.

Final thoughts

  • Students were more confident experimenting — they were able to try new ideas faster because hardware and software problems were easier to debug.
  • Teaching first Python, then electronics, was a win.
  • The micro:bit radio allowed students to build fundamental skills in something that’s quite complex.
  • Finally, the micro:bit is ridiculously cute and engaging. Students were hooked from the very first “Hello World” style smiley face.
happy.py :)

Thanks to WiseTech Global, for giving each NCSS student a micro:bit to take home with them. And thanks to the micro:bit Foundation for donating a set of micro:bits which allowed us to have enough spare micro:bits to have a lot of fun with the radios.

Check out Grok’s micro:bit resources at https://groklearning.com/microbit

Grok Learning

Articles about coding by the team at Grok Learning & teacher friends.

Thanks to Ben Taylor, Owen Brasier, and Vivian Li

Jim Mussared

Written by

Grok Learning

Articles about coding by the team at Grok Learning & teacher friends.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade