Arm Mbed OS support forum

Radio Communication between two Micro:Bit controllers

Hey everyone,

for a university project, I am trying to build an embedded application with two BBC Micro:Bit controllers.

In the future, I want to synchronize their system clocks.
To start, I simply want to enable them to communicate with each other in a very basic way.
But not even the easiert programm is working.

This is the code that I have put on the first controller:

int main()
{
uBit.init();
uBit.radio.enable();

while(1)
{
    if (uBit.buttonA.isPressed())
        uBit.radio.datagram.send("1");

    else if (uBit.buttonB.isPressed())
        uBit.radio.datagram.send("2");
}

}

And this is the code for the second controller:

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

if (s == "1")
    uBit.display.scroll("1“);

if (s == "2")
    uBit.display.scroll("2“);

}

int main()
{
uBit.init();
uBit.radio.enable();

while(1)
{
     uBit.messageBus.listen(MICROBIT_ID_RADIO, MICROBIT_RADIO_EVT_DATAGRAM, onData);
}

}

Both controllers are connected to power via my computer.
But if I press a button on the first controller, nothing happens.

Could anyone help me fixing my code for this basic application?

Thank you so much in advance!
Tim