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.
- Visit https://os.mbed.com/account/login.
- Click the Sign up button (Fig 1.2).
- Fill all the required information and click the Sign up button to create the account (Fig 1.3).
- You have now successfully registered and logged in to the ARM mbed (Fig 1.4).
Adding BBC micro:bit to the Compiler
After creating the account, you should add the BBC micro:bit to the compiler.
- On the menu bar, click Hardware | Boards. The resulting page will show a list of available boards (Fig 1.5).
- Scroll down the page and choose BBC micro:bit (Fig 1.6).
- You will get to the BBC micro:bit platform page that provides an overview of the BBC micro:bit (Fig 1.7).
- Scroll down the page and click the Add to your Mbed Compiler (Fig 1.8) button on the side bar to the right.
- A notification says ‘Platform BBC micro:bit is now added to your account’ (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.
- Scroll down the page and find the sample project; microbit-hello-world. Then click the Import program button (Fig 1.10).
- Click the Import button to proceed (Fig 1.11).
- Once the project is imported, you can find the microbit-hello-world project under My Programs in the Program Workspace (Fig 1.12).
- Click cpp (Fig 1.13) to open the source file.
- 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
// Initialise the micro:bit runtime.
// 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.
- On the toolbar, click the Compile button to compile the program (Fig 1.14). Wait until the compilation process ends.
- 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
- Connect the micro:bit board to your computer using a micro-USB cable.
- 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).
- 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.
- 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 firstname.lastname@example.org
Next: Creating a new program/project from scratch using ARM mbed online IDE.