Send/Receive data using BLE and MBED | BBC Microbit

BLE Microbit

BLE

This video is all about sending and receiving data between BBC Microbit and any BLE enabled smart phone. Over here I have used C/C++ (MBED) as the programming language as other language (Python/JavaScript) don’t support UART data transfer service.

 

The BBC micro:bit is a pocket-sized, codable computer that allows anyone to get creative with technology. Made possible through a major partnership with 31 organisations, a micro:bit has been given to every 11 or 12 year old child in year 7 or equivalent across the UK, for free.
Source : Mbed (https://goo.gl/dTBWGi)
———————————————————————————————–
Links :
Setting up Yotta : http://bit.ly/2hCPxLH
Code File: http://bit.ly/2hWQWt8

#include "MicroBit.h"
#include "MicroBitUARTService.h"

MicroBit uBit;
MicroBitUARTService *uart;


int connected = 0;

void onConnected(MicroBitEvent)
{

    uBit.display.scroll("C");

    connected = 1;

    // mobile app will send ASCII strings terminated with the colon character
    ManagedString eom(":");

    while(connected == 1) {
        ManagedString msg = uart->readUntil(eom);
        uBit.display.scroll(msg);
    }

}

void onDisconnected(MicroBitEvent)
{
    uBit.display.scroll("D");
    connected = 0;
}

void onButtonA(MicroBitEvent)
{
    if (connected == 0) {
        return;
    }
    uart->send(ManagedString("Connected"));
    uBit.display.scroll("Y");
}

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

  uBit.messageBus.listen(MICROBIT_ID_BLE, MICROBIT_BLE_EVT_CONNECTED, onConnected);
  uBit.messageBus.listen(MICROBIT_ID_BLE, MICROBIT_BLE_EVT_DISCONNECTED, onDisconnected);
    uBit.messageBus.listen(MICROBIT_ID_BUTTON_A, MICROBIT_BUTTON_EVT_CLICK, onButtonA);


    uart = new MicroBitUARTService(*uBit.ble, 32, 32);
    uBit.display.scroll("Ready");

  release_fiber();
}

Config File: http://bit.ly/2hWXgRx

{
    "microbit-dal": {
        "bluetooth": {
            "enabled": 1,
            "pairing_mode": 1,
            "open": 1,
            "event_service": 1
        },
        "gatt_table_size": "0x600"
    }
}

 

Configuration details : http://bit.ly/2hX2zAh
Android app by Martin Woolley : http://bit.ly/2hWWvrF
********************************************************************
Subscribe YouTube : http://bit.ly/2gsIZ2g

Guys Subscribe to my channel for latest contents into your inbox.
Support me to keep going.
___________________________________________

Website : https://wglabz.in
Twitter : https://twitter.com/geekybikash
YouTube : https://www.youtube.com/weargenius
Instagram : https://www.instagram.com/weargenius/
GIT : https://github.com/oksbwn
Facebook: http://www.facebook.com/geekybikash

Related posts

Leave a Comment