2

Has anybody gotten the online Mbed C/C++ compiler to use config.json files with the BBC Micro:bit? If so, where in the file system did you place the config.json file?

When I use the Mbed online C/C++ compiler to build the example radio programs called microbit-simple-radio-rx and microbit-simple-radio-tx, I do not get any response from the Micro:bits after loading the hex files. However, when I use the off-line yotta command line to compile the same examples for the Micro:bit with the same config.json files and load the hex files, the examples do run correctly.

It looks to me like the config.json files are being ignored by the Mbed online compiler. The contents of this file turn off Bluetooth as the Micro:bit radio uses a custom stack which cannot run at the same time as Bluetooth. I can also turn off the Bluetooth library by adding this line to the MicroBit.h library:

#define MICROBIT_BLE_ENABLED 0

This then enables the examples to compile and run correctly with the online Mbed compiler.

config.json file :

{ 
     microbit-dal:{
        bluetooth:{
            enabled: 0 
        } 
     } 
}

microbit_simple_radio_rx:

#include "MicroBit.h"

MicroBit    uBit;

void onData(MicroBitEvent)
{
    ManagedString s = uBit.radio.datagram.recv();

    if (s == "1")
        uBit.display.print("A");

    if (s == "2")
        Bit.display.print("B");
}

int main()
{
    // Initialise the micro:bit runtime.
    uBit.init();

    uBit.messageBus.listen(MICROBIT_ID_RADIO, 
        MICROBIT_RADIO_EVT_DATAGRAM, onData);
    uBit.radio.enable();

    while(1)
        uBit.sleep(1000);
}

microbit_simple_radio_tx:

#include "MicroBit.h"

MicroBit    uBit;

int main()
{
    // Initialise the micro:bit runtime.
    uBit.init();
   uBit.radio.enable();

    while(1)
    {
        uBit.display.print("t");
        if (uBit.buttonA.isPressed())
        {
            uBit.radio.datagram.send("1");
            uBit.display.print("1");
        }
         else if (uBit.buttonB.isPressed())
        {
            uBit.radio.datagram.send("2");
            uBit.display.print("2");
        }
        uBit.sleep(200);       
    }
}
Oppy
  • 2,662
  • 16
  • 22

1 Answers1

3

The Mbed online compiler uses mbed_app.json, instead of config.json. You can do the same as you're trying to do now via:

{
    "macros": [ "MICROBIT_BLE_ENABLED=0" ]
}

Just put that in mbed_app.json and place in the root of your project.

Jan Jongboom
  • 26,598
  • 9
  • 83
  • 120