Luca Mottola
/
IOTAtelier1819-BLELed
BLE example of a write characteristic to control a Led
readme.md@0:c6a8f2b3efb6, 2016-07-26 (annotated)
- Committer:
- Vincent Coubard
- Date:
- Tue Jul 26 14:47:19 2016 +0100
- Revision:
- 0:c6a8f2b3efb6
- Child:
- 2:864ddfb70a9c
Update example at tag mbed-os-5.0.1-rc1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Vincent Coubard |
0:c6a8f2b3efb6 | 1 | To help you create your own BLE services, we have created this service template. |
Vincent Coubard |
0:c6a8f2b3efb6 | 2 | The LED example demonstrates the use of a read-write characteristic to control a |
Vincent Coubard |
0:c6a8f2b3efb6 | 3 | LED through a phone app. |
Vincent Coubard |
0:c6a8f2b3efb6 | 4 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 5 | The template covers: |
Vincent Coubard |
0:c6a8f2b3efb6 | 6 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 7 | * Setting up advertising and connection states. |
Vincent Coubard |
0:c6a8f2b3efb6 | 8 | * Assigning UUIDs to the service and its characteristic. |
Vincent Coubard |
0:c6a8f2b3efb6 | 9 | * Creating an input characteristic: read-write, boolean. This characteristic offers control of the LED. |
Vincent Coubard |
0:c6a8f2b3efb6 | 10 | * Constructing a service class and adding it to the BLE stack. |
Vincent Coubard |
0:c6a8f2b3efb6 | 11 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 12 | # Running the application |
Vincent Coubard |
0:c6a8f2b3efb6 | 13 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 14 | ## Requirements |
Vincent Coubard |
0:c6a8f2b3efb6 | 15 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 16 | The sample application can be seen on any BLE scanner on a smartphone. If you don't have a scanner on your phone, please install : |
Vincent Coubard |
0:c6a8f2b3efb6 | 17 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 18 | - [nRF Master Control Panel](https://play.google.com/store/apps/details?id=no.nordicsemi.android.mcp) for Android. |
Vincent Coubard |
0:c6a8f2b3efb6 | 19 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 20 | - [LightBlue](https://itunes.apple.com/gb/app/lightblue-bluetooth-low-energy/id557428110?mt=8) for iPhone. |
Vincent Coubard |
0:c6a8f2b3efb6 | 21 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 22 | Hardware requirements are in the [main readme](https://github.com/ARMmbed/mbed-os-example-ble/blob/master/README.md). |
Vincent Coubard |
0:c6a8f2b3efb6 | 23 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 24 | *NOTE:* If you have more than a single mbed board (e.g. nrf51dk or mkit) you can |
Vincent Coubard |
0:c6a8f2b3efb6 | 25 | run the BLE_LED and BLE_LEDBlinker at the same time. For more information please |
Vincent Coubard |
0:c6a8f2b3efb6 | 26 | refer to the BLE_LEDBlinker demo. |
Vincent Coubard |
0:c6a8f2b3efb6 | 27 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 28 | ## Building instructions |
Vincent Coubard |
0:c6a8f2b3efb6 | 29 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 30 | Building instructions for all samples are in the [main readme](https://github.com/ARMmbed/mbed-os-example-ble/blob/master/README.md). |
Vincent Coubard |
0:c6a8f2b3efb6 | 31 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 32 | ## Checking for success |
Vincent Coubard |
0:c6a8f2b3efb6 | 33 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 34 | **Note:** Screens captures depicted below show what is expected from this example if the scanner used is *nRF Master Control Panel* version 4.0.5. If you encounter any difficulties consider trying another scanner or another version of nRF Master Control Panel. Alternative scanners may require reference to their manuals. |
Vincent Coubard |
0:c6a8f2b3efb6 | 35 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 36 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 37 | 1. Build the application and install it on your board as explained in the building instructions. |
Vincent Coubard |
0:c6a8f2b3efb6 | 38 | 1. Open the BLE scanner on your phone. |
Vincent Coubard |
0:c6a8f2b3efb6 | 39 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 40 | 1. Start a scan. |
Vincent Coubard |
0:c6a8f2b3efb6 | 41 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 42 | ![](img/start_scan.png) |
Vincent Coubard |
0:c6a8f2b3efb6 | 43 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 44 | **figure 1** How to start scan using nRF Master Control Panel 4.0.5 |
Vincent Coubard |
0:c6a8f2b3efb6 | 45 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 46 | 1. Find your device; it should be named `LED`. |
Vincent Coubard |
0:c6a8f2b3efb6 | 47 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 48 | ![](img/scan_results.png) |
Vincent Coubard |
0:c6a8f2b3efb6 | 49 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 50 | **figure 2** Scan results using nRF Master Control Panel 4.0.5 |
Vincent Coubard |
0:c6a8f2b3efb6 | 51 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 52 | 1. Establish a connection with your device. |
Vincent Coubard |
0:c6a8f2b3efb6 | 53 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 54 | ![](img/connection.png) |
Vincent Coubard |
0:c6a8f2b3efb6 | 55 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 56 | **figure 3** How to establish a connection using Master Control Panel 4.0.5 |
Vincent Coubard |
0:c6a8f2b3efb6 | 57 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 58 | 1. Discover the services and the characteristics on the device. The *LED service* has the UUID `0xA000` and includes the *LED state characteristic* which has the UUID `0xA001`. Depending on your scanner, non standard 16-bit UUID's can be displayed as 128-bit UUID's. If it is the case the following format will be used: `0000XXXX-0000-1000-8000-00805F9B34FB` where `XXXX` is the hexadecimal representation of the 16-bit UUID value. |
Vincent Coubard |
0:c6a8f2b3efb6 | 59 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 60 | ![](img/discovery.png) |
Vincent Coubard |
0:c6a8f2b3efb6 | 61 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 62 | **figure 4** Representation of the Led service using Master Control Panel 4.0.5 |
Vincent Coubard |
0:c6a8f2b3efb6 | 63 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 64 | 1. Open the write pannel of the *LED state* characteristic. |
Vincent Coubard |
0:c6a8f2b3efb6 | 65 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 66 | ![](img/write_characteristic.png) |
Vincent Coubard |
0:c6a8f2b3efb6 | 67 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 68 | **figure 5** How to read and write a characteristic value using Master Control Panel 4.0.5 |
Vincent Coubard |
0:c6a8f2b3efb6 | 69 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 70 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 71 | 1. The characteristic accept a 1 byte value: |
Vincent Coubard |
0:c6a8f2b3efb6 | 72 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 73 | ![](img/write_pannel.png) |
Vincent Coubard |
0:c6a8f2b3efb6 | 74 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 75 | **figure 6** Write characteristic pannel using Master Control Panel 4.0.5 |
Vincent Coubard |
0:c6a8f2b3efb6 | 76 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 77 | * `0x00`: LED ON |
Vincent Coubard |
0:c6a8f2b3efb6 | 78 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 79 | ![](img/LED_ON.png) |
Vincent Coubard |
0:c6a8f2b3efb6 | 80 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 81 | **figure 6** Write characteristic pannel to set the LED on using Master Control Panel 4.0.5 |
Vincent Coubard |
0:c6a8f2b3efb6 | 82 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 83 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 84 | * `0x01`: LED OFF |
Vincent Coubard |
0:c6a8f2b3efb6 | 85 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 86 | ![](img/LED_OFF.png) |
Vincent Coubard |
0:c6a8f2b3efb6 | 87 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 88 | **figure 6** Write characteristic pannel to set the LED off using Master Control Panel 4.0.5 |
Vincent Coubard |
0:c6a8f2b3efb6 | 89 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 90 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 91 | 1. Toggle the LED characteristic value and see the LED turn ON or turn OFF according to the value you set. |
Vincent Coubard |
0:c6a8f2b3efb6 | 92 | |
Vincent Coubard |
0:c6a8f2b3efb6 | 93 | If you can see the characteristic, and the LED is turned on/off as you toggle its value, the application is working properly. |