If you don’t already know, The Micro Bit is a circuit board measuring just 50x40mm with two buttons and an array of 25 red LEDs in a 5×5 arrangement. It comes in various colours, including green and blue. The device is being handed out free of charge to pupils in the UK to learn programming. The editors currently available are online IDEs supporting Touch Develop, Blocks, JavaScript, Python and C++.
This will provide you with a guide to get started with Offline development with the Micro:Bit using C++ and the official Micro:Bit DAL. We will be doing this by installing Yotta, which is used to make and build your project, the end result will be a .HEX file that you just copy onto the Micro:Bit device.
Note: You may be prompted to sign up/login to the MBed website to download the code.
That is our environment setup, now we need to use Yotta to build our project. We will have to create a new directory, perform some basic yotta commands and add the Micro:Bit dependencies to our project, using the steps below:
That is the project setup. You can now start programming your Micro:Bit with C++. Create a new file called main.cpp in your source folder and add in the following code:
#include "MicroBit.h" MicroBit uBit; int main() { uBit.init(); uBit.display.scroll("Hello World!"); release_fiber(); }
The last step is to actually compile the project and make it into a .HEX file that the Micro:Bit will run. Perform a yotta build command and this will compile your project. You will find the compiled hex file in your project folder \build\bbc-microbit-classic-gcc\Source\hellomicro-combined.hex (replace hellomicro with your actual project name)
Copy the .HEX file to your BBC Micro:Bit and watch your code run!
We will also be covering how to get started with Eclipse/Netbeans IDE so you can debug and have help when writing your code. Use the links below to view some sample C++ applications as well as the official C++ documentation. Stay tuned for more!
C++ Documentation: Click here
Micro:Bit Sample C++ Applications: Click here