Using the BBC micro:bit with PlatformIO

By: on August 28, 2016

I recently acquired a micro:bit, the new BBC device intended for helping computer education. After a bit of delay, they’ve finally starting shipping the device, and now members of the public like myself can grab one. So, why this device in the middle of a sea of other options in the modern embedded environment? Well, for starters, it’s got a 5×5 LED grid, accelerometer and Bluetooth, along with being powerable from a pair of AAA batteries – in other words, it looked like it would make a nicely integrated electronic badge thing. They’ve also done the nice thing of having a couple of really large connector pins so you can do stuff like attach crocodile clips if you actually want to do some educational experimenting. The other nifty feature is that it appears as a USB drive when you plug it into a computer, and flashing it is just a matter of copying over the HEX file with your new firmware. It appears really quite hard to brick accidentally, which is good, because otherwise I probably would have managed to do so in my experimenting…

I’d been previously looking at options for improving Pyrexia (more in a later blog post), and had come across PlatformIO, which is a build system that just makes your life really easy with embedded systems. For those who haven’t spent much time in that area, to have a single system that finds and sets up the buildchain for whatever processor you’re going for, manages libraries (rather than copy/pasting), flashes your device, and then deals with serial communication, and all of that pretty much effortlessly, is nothing short of miraculous. To those of you who have never dealt with a computer so small it doesn’t have an operating system, you have no idea how rare those things you take for granted are in embedded systems, and to find a general purpose system that deals with pretty much every single framework and platform being used today is lovely. The micro:bit under the hood uses mbed, which is supported by PlatformIO, and the micro:bit itself is also listed as supported, so this should be really easy right?

Ok, not so much. It turns out someone had added the micro:bit to the list of supported boards, but no-one had actually tried using it with PlatformIO yet. I wasn’t the first to run into this, but with the core developers not having one of the boards, I’d have to get them a fair way in before I could hand it over. This being an open source project, you can read my full progress in the ticket, but I managed to find out that the core of the micro:bit support was a bunch of mbed code Lancaster University had put together (some forked from upstream, some new and custom), which it turns out was notably incompatible with the mbed libraries provided by PlatformIO. Luckily, PlatformIO core are in the process of developing the 3.0 version, and a number of the features I needed were to make this work were able to be added to the develop branch very quickly (particularly a number of library dependency fixes), and we were eventually able to go from my initial hacky project to a properly assembled toolchain. That work has now been announced, and the 3.0 version should be out soon.

I’ve even got a nice little demo (running off the PlatformIO develop branch), showing the LEDs, button support and the accelerometer. The first display is just the LShift logo in LEDs, then there’s a version with them getting brighter and then dim again, and the third “screen” is a demo of the “gestures” system. It gives you a number from 1-9 (or 0 when you’re inbetween) saying which way up the micro:bit is, and I’m dumping that to the display. Of course, I could have done all of this much more easily in MicroPython, or using the various web-based development options for it, but where’s the fun in that?

Share

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*