Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BLE_API color_pixels mbed nRF51822
Fork of BLE_LCDDemo by
Color pixels library using WS2812B and nRF51822 (16MHz)

You can get the colorful led strip from seeed:
- http://www.seeedstudio.com/depot/Digital-RGB-LED-FlexiStrip-60-LED-1-Meter-p-1666.html
- http://www.seeedstudio.com/depot/WS2812B-Digital-RGB-LED-Waterproof-FlexiStrip-144-LEDmeter-2-meter-p-1869.html
- http://www.seeedstudio.com/depot/WS2812B-RGB-LED-with-Integrated-Driver-Chip-10-PCs-pack-p-1675.html
Click this link to download the color pixels app for android. The source code of the Android app is at https://github.com/Seeed-Studio/ble_color_pixels
If the BLE device is disconnected frequently, we can improve the stability by changing the BLE parameters - Advertising Duration (main.cpp), Min Interval and Max Interval (nRF51822/projectconfig.h)
#define CFG_GAP_CONNECTION_MIN_INTERVAL_MS 20 /**< Minimum acceptable connection interval */ #define CFG_GAP_CONNECTION_MAX_INTERVAL_MS 200 /**< Maximum acceptable connection interval */
Revision 7:0e54bd52bd2d, committed 2015-05-05
- Comitter:
- yihui
- Date:
- Tue May 05 05:48:40 2015 +0000
- Parent:
- 6:95beab5ab88b
- Commit message:
- update libraries
Changed in this revision
--- a/BLE_API.lib Mon Sep 15 06:30:03 2014 +0000 +++ b/BLE_API.lib Tue May 05 05:48:40 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#189ff241dae1 +http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#501ad8b8bbe5
--- a/color_pixels.lib Mon Sep 15 06:30:03 2014 +0000 +++ b/color_pixels.lib Tue May 05 05:48:40 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/teams/Seeed/code/color_pixels/#0322642447e2 +http://mbed.org/teams/Seeed/code/color_pixels/#16ef874fa57f
--- a/main.cpp Mon Sep 15 06:30:03 2014 +0000
+++ b/main.cpp Tue May 05 05:48:40 2015 +0000
@@ -3,6 +3,7 @@
#include "mbed.h"
#include "BLEDevice.h"
+#include "UARTService.h"
#include "color_pixels.h"
#define NEED_CONSOLE_OUTPUT 0 /* Set this if you need debug messages on the console;
@@ -20,23 +21,8 @@
BLEDevice ble;
DigitalOut led1(LED1);
-// The Nordic UART Service
-const uint8_t uart_base_uuid[] = {0x6e, 0x40, 0x00, 0x01, 0xb5, 0xa3, 0xf3, 0x93, 0xe0, 0xa9, 0xe5, 0x0e, 0x24, 0xdc, 0xca, 0x9e};
-const uint8_t uart_tx_uuid[] = {0x6e, 0x40, 0x00, 0x02, 0xb5, 0xa3, 0xf3, 0x93, 0xe0, 0xa9, 0xe5, 0x0e, 0x24, 0xdc, 0xca, 0x9e};
-const uint8_t uart_rx_uuid[] = {0x6e, 0x40, 0x00, 0x03, 0xb5, 0xa3, 0xf3, 0x93, 0xe0, 0xa9, 0xe5, 0x0e, 0x24, 0xdc, 0xca, 0x9e};
-const uint8_t uart_base_uuid_rev[] = {0x9e, 0xca, 0xdc, 0x24, 0x0e, 0xe5, 0xa9, 0xe0, 0x93, 0xf3, 0xa3, 0xb5, 0x01, 0x00, 0x40, 0x6e};
-
-bool rxPayloadUpdated = false;
-uint8_t rxPayload[20] = {0,};
-uint8_t txPayload[20] = {0,};
-GattCharacteristic rxCharacteristic (uart_tx_uuid, rxPayload, 1, sizeof(rxPayload),
- GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE);
-GattCharacteristic txCharacteristic (uart_rx_uuid, txPayload, 1, sizeof(txPayload),
- GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY);
-GattCharacteristic *uartChars[] = {&rxCharacteristic, &txCharacteristic};
-GattService uartService(uart_base_uuid, uartChars, sizeof(uartChars) / sizeof(GattCharacteristic *));
-
-
+UARTService *uartServicePtr;
+
void processPacket(uint8_t *packet)
{
@@ -68,23 +54,21 @@
}
-void disconnectionCallback(uint16_t handle)
+void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason)
{
DEBUG("Disconnected!\n\r");
+
DEBUG("Restarting the advertising process\n\r");
ble.startAdvertising();
}
-void onDataWritten(uint16_t charHandle)
+void onDataWritten(const GattCharacteristicWriteCBParams *params)
{
- if (charHandle == rxCharacteristic.getHandle()) {
- DEBUG("onDataWritten()\n\r");
- uint16_t bytesRead;
- ble.readCharacteristicValue(rxCharacteristic.getHandle(), rxPayload, &bytesRead);
- if (bytesRead < sizeof(rxPayload)) {
- rxPayload[bytesRead] = 0;
- }
- processPacket(rxPayload);
+ if ((uartServicePtr != NULL) && (params->charHandle == uartServicePtr->getTXCharacteristicHandle())) {
+ uint16_t bytesRead = params->len;
+ DEBUG("received %u bytes\n\r", bytesRead);
+ ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), params->data, bytesRead);
+ processPacket((uint8_t *)params->data);
}
}
@@ -109,20 +93,21 @@
ble.init();
ble.onDisconnection(disconnectionCallback);
ble.onDataWritten(onDataWritten);
-
+
/* setup advertising */
ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
- (const uint8_t *)"Color Pixels", sizeof("Color Pixels") - 1);
+ (const uint8_t *)"Color Pixels", sizeof("Color Pixels") - 1);
ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
- (const uint8_t *)uart_base_uuid_rev, sizeof(uart_base_uuid));
-
- ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */
+ (const uint8_t *)UARTServiceUUID_reversed, sizeof(UARTServiceUUID_reversed));
+
+ ble.setAdvertisingInterval(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(1000));
ble.startAdvertising();
-
- ble.addService(uartService);
-
+
+ UARTService uartService(ble);
+ uartServicePtr = &uartService;
+
while (true) {
ble.waitForEvent();
}
--- a/mbed.bld Mon Sep 15 06:30:03 2014 +0000 +++ b/mbed.bld Tue May 05 05:48:40 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/9327015d4013 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5 \ No newline at end of file
--- a/nRF51822.lib Mon Sep 15 06:30:03 2014 +0000 +++ b/nRF51822.lib Tue May 05 05:48:40 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/yihui/code/nRF51822_for_nRF_UART/#2fbfd93d9ba3 +http://mbed.org/teams/Nordic-Semiconductor/code/nRF51822/#bdc690669431
