micro bit radio

Posted on
  • Hello Everyone
    Gordon has already kindly pointed me in the direction of more documentation. Unfortunately, I'm not an Espruino person - so I'm missing a lot of the background knowledge - so the Espruino radio api doesn't mean anything to me.

    Does anyone whether it is possible, or how, to access the radio from Espruino. As a example, I have a simple javascript (written for the blockly...microsoft editor) that follows:
    N.B. I know this won't work in Espruino...

    let x = 0
    let y = 0
    input.onButtonPressed(Button.B, () => {
        radio.sendNumber(x + 5 * y)
    input.onButtonPressed(Button.A, () => {
        led.unplot(x, y)
        x += 1
        if (x > 4) {
            x = 0
            y += 1
            if (y > 4) {
                y = 0
        led.plot(x, y)
    radio.onDataPacketReceived(({receivedNum­ber: recd}) => {
        y = recd / 5
        x = recd - y * 5
        led.plot(x, y)
    x = 0
    y = -1

    Any hints, tips, tutorials or pointers to documentation would be very welcome.

    Best wishes
    Andy Stratton

  • Hi Andy,

    You access the radio using the NRF class: http://www.espruino.com/Reference#NRF

    There's a bit of background on BLE here: http://www.espruino.com/About+Bluetooth+­LE

    Basically the MS editor massively simplifies what BLE can actually do (although the micro:bit can't access other devices as a 'central' - it can only be connected to by something like a phone/PC). By default, the Micro:bit will put the console (the LHS of the Web IDE) on Bluetooth when it's connected, so if you want to make something happen you can actually just send the JS code show(0xFF)\n over the BLE UART service it advertises, and 8 LEDs will light up.

    If you want to do something like the MS example, you can just do this:

    Serial1.setConsole(1); // stop the console moving from Serial1
    Bluetooth.on('data', function(d) {
      console.log("Got data ",JSON.stringify(d));

    Otherwise you can use NRF.setServices to create your own specific BLE services that have callbacks when data is set on them

  • I am likely wrong here - but I'm trying to NOT use the full BLE stack. i.e. I'm looking to have two microbits communicate with each other, without having to pair them.

    I tried your suggestion - but it didn't work - I think this is because I'm looking to have two microbits communicating without a 'central' PC.

    Am I barking up the wrong tree - or is this something Espruino can do - i.e. radio comms without pairing.

    I do have this working in uPython now - but I would prefer to use Espruino - if possible.

    Best wishes

  • Ahh, ok - Micro Python doesn't actually use Bluetooth as far as I know - it's just a proprietary radio transmission because they couldn't fit the BLE stack and micro python in the micro:bit.

    With Espruino on micro:bit you have to use BLE, you can't do proprietary radio.

    However you can use BLE to transmit data in a standard BLE way by sending 'advertising data' and then scanning for it with the other micro:bit. Again, check out the BLE page linked above.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

micro bit radio

Posted by Avatar for AndyS @AndyS