Setting Up The Development Environment

By Pradeeka Seneviratne (@pradeeka7)

The micro:bit runtime is built on the ARM mbed and Nordic nrf51 sdk platforms (Fig 1.1). It provides an easy-to-use environment for programming the BBC micro:bit in the C/C++ language. The applications can develop with ARM mbed online IDE provides a simple interface for writing, compiling, and sharing projects.

Fig 1.1: Image courtesy of microbit.org

In this lesson, you will learn:

  • How to create an account with ARM mbed.
  • How to add micro:bit board to the ARM mbed compiler.
  • How to compile the sample C/C++ project using ARM mbed online IDE

Creating an Account

This guide provides the steps to create a new user account on ARM mbed. Having an account will allow you to access mbed tools and services and contribute to the developer community.

  1. Visit https://os.mbed.com/account/login.
  2. Click the Sign up button (Fig 1.2).

 

Fig 1.2

 

  1. Fill all the required information and click the Sign up button to create the account (Fig 1.3).

Fig 1.3

 

  1. You have now successfully registered and logged in to the ARM mbed (Fig 1.4).

Fig 1.4

Adding BBC micro:bit to the Compiler

After creating the account, you should add the BBC micro:bit to the compiler.

  1. On the menu bar, click Hardware | Boards. The resulting page will show a list of available boards (Fig 1.5).

Fig 1.5

 

  1. Scroll down the page and choose BBC micro:bit (Fig 1.6).

Fig 1.6

 

  1. You will get to the BBC micro:bit platform page that provides an overview of the BBC micro:bit (Fig 1.7).

Fig 1.7

 

  1. Scroll down the page and click the Add to your Mbed Compiler (Fig 1.8) button on the side bar to the right.

Fig 1.8

 

  1. A notification says ‘Platform BBC micro:bit is now added to your account’ (Fig 1.9).

Fig 1.9

Running the Sample Project

As the first step of getting started with micro:bit runtime, let’s use a sample micro:bit project featured on the BBC micro:bit web page.

  1. Scroll down the page and find the sample project; microbit-hello-world. Then click the Import program button (Fig 1.10).

 

Fig 1.10

 

  1. Click the Import button to proceed (Fig 1.11).

 

Fig 1.11

 

  1. Once the project is imported, you can find the microbit-hello-world project under My Programs in the Program Workspace (Fig 1.12).

Fig 1.12

 

  1. Click cpp (Fig 1.13) to open the source file.

Fig 1.13

 

  1. Here’s the sample code (Listing 1.1) in C/C++ written using micro:bit runtime. Don’t worry. You will learn in detail about micro:bit runtime from the next lesson onwards.

 

Listing 1.1: microbit-hello-world/main.cpp

#include “MicroBit.h”

 

MicroBit uBit;

 

int main()

{

// Initialise the micro:bit runtime.

uBit.init();

 

// Insert your code here!

uBit.display.scroll(“HELLO WORLD! :)”);

 

// If main exits, there may still be other fibers running or registered event handlers etc.

// Simply release this fiber, which will mean we enter the scheduler. Worse case, we then

// sit in the idle task forever, in a power efficient sleep.

release_fiber();

}

 

  1. On the toolbar, click the Compile button to compile the program (Fig 1.14). Wait until the compilation process ends.

Fig 1.14

 

  1. Once compiled, you can see the Success! message under ‘Compile output for program: microbit-hello-world’ (Fig 1.15). Also, a hex file will be downloaded to your computer. For most computers, the default download location is the Downloads

 

Fig 1.15

 

  1. Connect the micro:bit board to your computer using a micro-USB cable.

 

  1. Open the Downloads folder and find the hex file, microbit-hello-world_NRF51_MICROBIT.hex. Drag and drop the hex file onto the micro:bit drive (Fig 1.16).

 

Fig 1.16

 

  1. While copying (Fig 1.17), the orange LED on the back of the micro:bit board will flash. It stop once the download is complete.

Fig 1.17

 

  1. When the copy process finishes, the micro:bit drive will reset and disconnect from your computer. Now, you can see the text HELLO WORLD! 🙂 scrolling on the micro:bit display.

 

Please submit your errata at pradeeka@outlook.com

Next: Creating a new program/project from scratch using ARM mbed online IDE.