Getting the BBC Micro:bit radio to work with the mbed online C/C++ compiler
Last updated: Jan 24, 2023
This blog explains how to get the example programs for working with the non-Bluetooth radio on the BBC Micro:bit to compile correctly using the Mbed online C/C++ compiler. Since I wrote this in 2017, the mbed online compiler for the BBC micro:bit was depreciated.
Short story
Two options:
1 Place the line:
#define MICROBIT\_BLE\_ENABLED 0
in the MicroBit.h library and forget about the config.json file.
Or
2 Create an mbed_app.json file instead of the config.json file with this content:
{ "macros": \[ "MICROBIT\_BLE\_ENABLED=0" \] }
Long story
The Mbed online compiler and the yotta offline compiler for the BBC Micro:bit are explained at the Lancaster University github site here:
https://lancaster-university.github.io/microbit-docs/
I couldn’t get the example radio programs supplied with the online Mbed C/C++ compiler to work with the BBC Micro:bit. These programs did work with the yotta offline compiler. It took a while to figure out that the config.json file supplied with the examples is being ignored by the Mbed online compiler. The BBC Micro:bit has a custom radio setup which does not work when Bluetooth is enabled. The compiler needs to be told that Bluetooth is disabled. In the examples supplied for both the yotta offline compiler and for the mbed online compiler this is done using a config.json file containing:
{ microbit-dal:{ bluetooth:{ enabled: 0 } } }
The example programs are called simple-radio-rx and simple-radio-tx. For the Mbed online compiler, these can be found at:
https://os.mbed.com/teams/microbit/code/microbit-simple-radio-rx/
https://os.mbed.com/teams/microbit/code/microbit-simple-radio-tx/
For the offline yotta compiler the same programs and config.json files can be found at:
https://github.com/lancaster-university/microbit-samples/tree/master/source/examples
The hex files created using the Mbed online compiler resolutely refused to do anything when I loaded them onto the microbits. I figured out that the the config.json file was being ignored by the Mbed online compiler. To disable the Bluetooth through code, place this line:
#define MICROBIT\_BLE\_ENABLED 0
in the MicroBit.h library. After doing this, the hex files produced by compiling the example programs using the Mbed online compiler ran correctly.
I posted this on the Mbed questions site and an Mbed moderator said that the issue will be fixed:
https://os.mbed.com/questions/79592/BBC-Microbit-how-to-use-the-radio/?compage=1#c29069
A while later, a helpful guy on Stackoverflow advised me to use an mbed_app.json file instead of the config.json file with this content:
{ "macros": \[ "MICROBIT\_BLE\_ENABLED=0" \] }