mbed BLE for developers

This document is written for experienced BLE developers who are switching to mbed platforms. If you feel that you need more information than this document provides, please refer to our extended documentation.

BLE on mbed

mbed gives you three things: a well defined hardware platform, APIs to abstract this platform (including some specifically for BLE) and an online compiler integrated with these tools:

  1. Some platforms require an external BLE component, and some have it built-in.

  2. mbed has a BLE-specific API (BLE_API), a high level abstraction for using BLE on multiple platforms. You can see the Doxygen here.

  3. The mbed BLE tools are written in C++ and can be used from the online mbed compiler or offline, for example with GCC.

BLE is most useful when used with a website or app on your mobile or tablet. See the next section for options.


Connecting


A BLE device currently requires an app or website running on a phone


Rapid prototyping

mbed comes from a heritage of rapid prototyping and allows you to test code and ideas on BLE devices very easily.


For information about rapid prototyping with mbed BLE, see here.


BLE in depth

If you want more information about how BLE works, see our BLE in Depth document.


Quick samples


Tip: The quick samples are written for experienced BLE developers with an understanding of the mbed IDE. If you want more information about the IDE, see the tutorials, which offer extended versions of the same samples.

The samples cover:

  1. A UriBeacon.

  2. A heart rate monitor.

  3. Service creation: for a read-only characteristic and for a read/write characteristic.


Quick sample one: UriBeacon


Tip: If you don’t know how to register your board, or how to work with the mbed compiler, please see the extended UriBeacon tutorial.

You might want to start with a short video.

To get this sample working, you’ll need:

  • To see BLE devices and their advertisement or beacon information, get one of the following installed on your phone:

  • A BLE-enabled mbed board.


Note: if your board appears as JLINK instead of mbed, please go to the platform page for your board and follow the firmware update instructions.

If you’re familiar with mbed and our compiler, you can get the beacon working in just a few minutes:

  1. Open the compiler and select or add your board.

  2. Import the BLE_URIBeacon program.

  3. In main.cpp, find the line
    nrfURIBeaconConfigService uriBeaconConfig(ble,
    params, !fetchedFromPersistentStorage,
    "http://www.uribeacon.org", defaultAdvPowerLevels);
    and edit the URL. Note that it’s limited to 18 characters, with “http://www.” (or “http://”, if there’s no “www” ) counting as one, and the suffix “.org” (or “.com”) counting as another.

  4. Compile the code. It will be downloaded to your Downloads folder (on some browsers you may need to specify a download location).

  5. Drag and drop the compiled file to your board as the target platform.

  6. Restart the board.

  7. On the app you installed on your phone, discover your beacon and check that the URL is correct.


    Note: the UriBeacon goes into configuration mode for the first 60 seconds after it’s turned on. It will appear with your information when that minute is up.

You might be interested in some of the UriBeacon’s advanced features.


Quick sample two: heart rate


Tip: If you don’t know how to register your board, or how to work with the mbed compiler, please see the extended UriBeacon tutorial.

To see the heart rate information on your phone, download PanoBike for iOS or Android. Then:

  1. Open the compiler and select or add your board as the target platform.

  2. Import the heart rate service.

  3. In main.cpp, find the line const static char DEVICE_NAME[] = "HRM1"; and change the beacon’s name from HRM1.

  4. Compile the code. It will be downloaded to your Downloads folder (on some browsers you may need to specify a download location).

  5. Drag and drop the compiled file to your board.

  6. Restart the board.

  7. On the PanoBike application, watch the heart rate. It should go from 100 to 175 in increments of one, then reset.


For service creation, see our advanced samples.