The micro:bit… inside and out

Joe Finney [email protected]

School of Computing and Communications Lancaster University UK [email protected] School of Computing and Communications: InfoLab21 What computers used to look like… (I had one of these!)

Commodore 64 ( I had one of these) What computers used to look like… (I didn’t have one of these – but martin did!)

Sinclair ZX Spectrum (I didn’t have one of these) And then there was this one too!

BBC Model B (Delivered free to every school in the UK in the 1980s) Circa January 2015 Micro:bit Legend

Howard Baker “We have some prototypes…”

BBC R&D by Michael Sparks early 2015… http://www.bbc.co.uk/rd/blog/2015-07-prototyping-the-bbc-microbit Delivered by a wide partnership More Prototyping…

The micro:bit SB1… And More Prototyping…

Micro:bits of Legend… In the most unlikely places…

Micro:bit SB2 Proof of Concept… In the most unlikely places…

Micro:Bit Font is called “Pendolino” for a reason… In the most unlikely places…

Micro:bit device drivers largely written at the car park at Cockerham Junior Football Club… A whirlwind of events… But not without its problems… We delivered 22nd March 2016… DEMO: Coding a micro:bit with MakeCode Inside the micro:bit…

. 25 LED matrix screen . Light sensor . User definable buttons

. 17 Digital input/output . 6 Analog input . 3 PWM output . 3 Touch sensitive . I2C, SPI, UART Inside the micro:bit…

. 16MHz ARM Cortex M0 . 16KB RAM, 256K FLASH

. USB Storage/Serial/Debug

. 3 axis accelerometer . 3 axis magnetometer . Temperature sensor . Bluetooth Low Energy How it all works… Web sites pxt.microbit.org

Blocks <-> JavaScript Editors

TypeScript PXT Simulator Compiler

Micro:bit DAL Runtime

Devices Introducing the micro:bit runtime

Provides a Device Abstraction Layer (DAL) for the BBC micro:bit

. Built on the ARM platform and Nordic libraries . Accessible C/C++ component based API for all capabilities of device . Open source (MIT licence)

. Designed with many requirements in mind: . High level language features in mind (concurrency, eventing models and managed types) . RAM efficiency . Power efficiency http://lancaster-university.github.io/microbit-docs/ The micro:bit runtime architecture

The micro:bit community encourages many languages… The micro:bit runtime architecture II Eventing and the Message Bus

. Many languages support the concept of events.

. This is also something that kids find familiar from visual languages such as Scratch. . And something that lends itself to embedded systems too… e.g. Eventing and the Message Bus

. The micro:bit runtime contains a simple yet powerful extensible eventing model

. Events are themselves a very simple managed type. . Contain two numeric values: a source and a value.

. Every component in the runtime has a unique ID – the source of an event. . Each component can then create ANY value with that ID as a source at any time:

MicroBitEvent e(MICROBIT_ID_GESTURE, MICROBIT_ACCELEROMETER_EVT_SHAKE);

#define MICROBIT_ID_GESTURE 27 #define MICROBIT_ACCELEROMETER_EVT_SHAKE 11 Eventing and the Message Bus

. The MessageBus then delivers events to any code that registers an interest.

. Functions can be either plain C functions, or C++ methods. . Wildcard values can also be used to capture lots of events at once.

void onShake(MicroBitEvent e) { // do something cool here! } int main() { uBit.messageBus.listen(MICROBIT_ID_GESTURE, MICROBIT_ACCELEROMETER_EVT_SHAKE, onShake); } Eventing and the Message Bus

. The runtime generates a range of events application can build on. . Users can also define their own events easily… just numbers!

#define MICROBIT_ACCELEROMETER_EVT_TILT_UP 1 #define MICROBIT_ACCELEROMETER_EVT_TILT_DOWN 2 #define MICROBIT_ACCELEROMETER_EVT_TILT_LEFT 3 #define MICROBIT_ACCELEROMETER_EVT_TILT_RIGHT 4 #define MICROBIT_ACCELEROMETER_EVT_FACE_UP 5 #define MICROBIT_ACCELEROMETER_EVT_FACE_DOWN 6 #define MICROBIT_ACCELEROMETER_EVT_FREEFALL 7 #define MICROBIT_ACCELEROMETER_EVT_SHAKE 11

#define MICROBIT_BUTTON_EVT_DOWN 1 #define MICROBIT_BUTTON_EVT_UP 2 #define MICROBIT_BUTTON_EVT_CLICK 3 #define MICROBIT_BUTTON_EVT_LONG_CLICK 4 #define MICROBIT_BUTTON_EVT_HOLD 5 #define MICROBIT_BUTTON_EVT_DOUBLE_CLICK 6

#define MICROBIT_RADIO_EVT_DATAGRAM 1 Fiber Scheduler: Providing Concurrent behaviour… …or at least apparently concurrent behaviour!

. Take this simple example again. What behaviour would you expect? . Given that show string will scroll the given text on the 5x5 matrix display… Fiber Scheduler: Providing Concurrent behaviour… . Fibers can be created at any time, and execute independently . By design, a non pre-emptive scheduler to reduce potential race conditions. . Fibers can sleep, or block on events on the MessageBus . Anytime there’s nothing to do… processor enters a power efficient sleep

void doSomething() void doSomethingElse() { { while(1) while(1) { { uBit.display.print(‘A’); uBit.display.print(‘B’); uBit.sleep(100); uBit.sleep(100); } } } } Fiber Scheduler: Providing Concurrent behaviour… void onButtonA() { uBit.display.scroll(“hello”); }

void onButtonB() { uBit.display.scroll(“goodbye”); }

// Then in your main program...

uBit.messageBus.listen(MICROBIT_ID_BUTTON_A, MICROBIT_BUTTON_EVT_CLICK, onButtonA); uBit.messageBus.listen(MICROBIT_ID_BUTTON_B, MICROBIT_BUTTON_EVT_CLICK, onButtonB); Device Drivers . Each hardware component is supported by a corresponding C++ object:

. MicroBitAccelerometer . MicroBitButton . MicroBitMultiButton . MicroBitCompass . MicroBitDisplay . MicroBitIO . MicroBitLightSensor . MicroBitRadio . MicroBitSerial . MicroBitStorage . MicroBitThermometer Putting the pieces together…

Editors Simulator

Blockly JavaScript

ARM ARM TypeScript IR Assembly binary

ARM ARM TypeScript Linker binary binary cached copy

ARM mapping C++ binary compile decompile Cloud-based compilation link Memory Footprint

. micro:bit has 16Mhz Nordic nrf51822 CPU (32 bit Cortex M0) . 256 KB , 16KB SRAM…

BLE Bootloader 16 KB stack 2 KB

User data ~72 KB User data 2.5 KB micro:bit runtime 1.5 KB micro:bit runtime ~50 KB ARMmbed/Nordic-sdk 2 KB ARMmbed/Nordic-sdk 20 KB

Nordic Nordic 8 KB Soft Device 98 KB Soft Device

FLASH MEMORY SRAM MEMORY Power Efficiency

Pi 3 ~ 2000mW https://www.raspberrypi.org/help/faqs/

Pi Zero ~500mW http://raspi.tv/2015/raspberry-pi-zero-power-measurements

http://www.reuk.co.uk/wordpress/microbit-battery-capacity/ What can you do?

Baseball pitch counter – Hawaii Micro:bit in Space – Rishworth School Air guitar – Tech Will Save Us Micro:bit as a security device Micro:bit family fun day – IET/Schneider Electric What can you do?

IET Faraday Challenge Day 2016 winners… the “No-Nod” by Kings School, Winchester. Meeting the Princess Royal at the opening of IET Savoy Place What can you do?

Veggard from Norway (age 12) What can you do? What can you do? What can you do? The Outcome? A positive impact that is changing attitudes • 13 million visits to the • 70% increase in the number micro:bit website of girls that said they would definitely choose computing • Nearly 10 million code simulator runs • 86% said it made computer science more interesting • And nearly 2 million • 88% said it showed that compiles to the device coding isn’t as hard as they thought

Source: Discovery Research Report for BBC Learning Going Forward… Web sites pxt.microbit.org mini.pxt.io adafruit.pxt.io

Blocks <-> JavaScript Editors

TypeScript PXT Simulator Compiler

Runtime

Devices The future is now!

Joe Finney Micro:bit Foundation Vision: In the future, every child will be an inventor Mission: To empower children, parents and teachers around the globe to learn and innovate using the micro:bit Big Objective: 100M people globally will use a micro:bit BBC micro:bit is going global

Now available in 32 microbit.org in countries 8 languages

National roll-outs 78 partner in UK, Iceland, Croatia ecosystem globally! Croatia: 1000 primary schools Crowd Funded… Sri Lanka: Early Days…

micro:bit User Group Sri Lanka Key Take Away…

All children are natural inventors, which micro:bit is helping unleash!

Call to Action Everyone can help, visit us at http://microbit.org to find out how!