particle
Spark Core / Particle – Room Temp/Humidity Monitoring & Mobile App
May 9, 2016
micromouse
Create a basic BBC Micro:Bit Air Mouse
May 21, 2016
Show all

Getting Started with Offline C++ on the BBC Micro:Bit

micro

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++.

rxubgeld

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.

Setting up for Offline C++

  1. Download Yotta (click here) and start the installation. You will be prompted to select components to install, tick all of them except git-scm and mercurial, there are version control systems which we will not using right now. For the serial driver, you will need the Micro:Bit connected to your PC.
  2. Download SRECORD (click here) and extract this to the Yotta install folder (C:\yotta) SRecord is what will be handling our .HEX file conversions/builds and is required to build a Micro:Bit project.

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:

  1. Launch Yotta using the shortcut it placed on your desktop. You’re now in the Yotta environment in a console window.
  2. Create a new folder (where you wish) to house our project. e.g. mkdir hellomicro (or use Windows explorer to right click > new folder)
  3. CD to the specified folder in the console window. e.g. cd hellomicro
  4. Perform a yotta init command (this will build our folder structure and details) this will ask you a series of questions regarding your project, make sure you select Yes to it being executable, or the project will not work correctly.
  5. You now need to add the yotta microbit dependency to the project using: yotta target bbc-microbit-classic-gcc
  6. And another required dependency, this library will be downloaded from the internet. yotta install lancaster-university/microbit 

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

Leave a Reply

Your email address will not be published. Required fields are marked *