From 5e0bfe175e2eca91951c2a8ed37bb68f95920806 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 17 Feb 2020 13:01:23 +0700 Subject: [PATCH 01/21] rename cplay_ble to bluefruit_playground.ino --- README.md | 4 ++-- boards.txt | 14 ++++++++++++-- .../.cplaynrf52840.test.only | 0 .../bluefruit_playground.ino} | 0 4 files changed, 14 insertions(+), 4 deletions(-) rename libraries/Bluefruit52Lib/examples/Peripheral/{cplay_ble => bluefruit_playground}/.cplaynrf52840.test.only (100%) rename libraries/Bluefruit52Lib/examples/Peripheral/{cplay_ble/cplay_ble.ino => bluefruit_playground/bluefruit_playground.ino} (100%) diff --git a/README.md b/README.md index 890ba32b..0d0f9781 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,11 @@ This repository contains the Arduino BSP for Adafruit Bluefruit nRF52 series: -- Adafruit CLUE nRF52840 +- [Adafruit CLUE nRF52840](https://www.adafruit.com/product/4500) - [Adafruit Circuit Playground Bluefruit](https://www.adafruit.com/product/4333) - [Adafruit Feather nRF52832](https://www.adafruit.com/product/3406) - [Adafruit Feather nRF52840 Express](https://www.adafruit.com/product/4062) -- Adafruit Feather nRF52840 Sense +- [Adafruit Feather nRF52840 Sense](https://www.adafruit.com/product/4516) - [Adafruit ItsyBitsy nRF52840 Express](https://www.adafruit.com/product/4481) - Adafruit Metro nRF52840 Express diff --git a/boards.txt b/boards.txt index fbe911a9..f789cb30 100644 --- a/boards.txt +++ b/boards.txt @@ -167,9 +167,9 @@ feather52840sense.menu.debug.l3=Level 3 (Segger SystemView) feather52840sense.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3 -# ---------------------------------- +# --------------------------------------------- # Bluefruit ItsyBitsy nRF52840 Express -# ---------------------------------- +# --------------------------------------------- itsybitsy52840.name=Adafruit ItsyBitsy nRF52840 Express # VID/PID for bootloader with/without UF2, Arduino + Circuitpython App @@ -380,6 +380,16 @@ metro52840.menu.debug.l2.build.debug_flags=-DCFG_DEBUG=2 metro52840.menu.debug.l3=Level 3 (Segger SystemView) metro52840.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3 + + + +# ------------------------------------------------------- +# +# Boards that aren't made by Adafruit +# +# ------------------------------------------------------- + + # ---------------------------------- # Nordic nRF52840DK (PCA10056) # ---------------------------------- diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/cplay_ble/.cplaynrf52840.test.only b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/.cplaynrf52840.test.only similarity index 100% rename from libraries/Bluefruit52Lib/examples/Peripheral/cplay_ble/.cplaynrf52840.test.only rename to libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/.cplaynrf52840.test.only diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/cplay_ble/cplay_ble.ino b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino similarity index 100% rename from libraries/Bluefruit52Lib/examples/Peripheral/cplay_ble/cplay_ble.ino rename to libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino From 1aea90e6c936a6b44dcd63ad0931628fde6c8698 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 17 Feb 2020 13:01:55 +0700 Subject: [PATCH 02/21] add PIN_BUZZER to variants with built-in speaker --- variants/circuitplayground_nrf52840/variant.h | 7 +++++-- variants/clue_nrf52840/variant.h | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/variants/circuitplayground_nrf52840/variant.h b/variants/circuitplayground_nrf52840/variant.h index aa6e5a74..2bbadeb0 100644 --- a/variants/circuitplayground_nrf52840/variant.h +++ b/variants/circuitplayground_nrf52840/variant.h @@ -54,14 +54,17 @@ extern "C" #define LED_STATE_ON 1 // State when LED is litted // Buttons -#define PIN_BUTTON1 (4) -#define PIN_BUTTON2 (5) +#define PIN_BUTTON1 (4) // Button A (Left) +#define PIN_BUTTON2 (5) // Button B (Right) // Microphone #define PIN_PDM_DIN 24 #define PIN_PDM_CLK 25 #define PIN_PDM_PWR -1 // not used +// Buzzer +#define PIN_BUZZER 12 + /* * Analog pins */ diff --git a/variants/clue_nrf52840/variant.h b/variants/clue_nrf52840/variant.h index f37b9176..e2d6fa86 100644 --- a/variants/clue_nrf52840/variant.h +++ b/variants/clue_nrf52840/variant.h @@ -52,14 +52,17 @@ extern "C" #define LED_STATE_ON 1 // State when LED is litted // Buttons -#define PIN_BUTTON1 (5) -#define PIN_BUTTON2 (11) +#define PIN_BUTTON1 (5) // Button A +#define PIN_BUTTON2 (11) // Button B // Microphone #define PIN_PDM_DIN 35 #define PIN_PDM_CLK 36 #define PIN_PDM_PWR -1 // not used +// Buzzer +#define PIN_BUZZER 46 + /* * Analog pins */ From c340043a57b968e08c1fe56c8cae931dc69458d9 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 17 Feb 2020 13:02:56 +0700 Subject: [PATCH 03/21] porting bluefruit play to clue --- .../bluefruit_playground.ino | 68 ++++++++++++++++--- 1 file changed, 60 insertions(+), 8 deletions(-) diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino index 268704b3..9cfe7b22 100644 --- a/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino +++ b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino @@ -11,11 +11,17 @@ All text above, and the splash screen below must be included in any redistribution *********************************************************************/ + +/* This sketch demonstrate the BLE Adafruit Service that is used with + * "Adafruit Bluefruit Playground" app. Supported boards are + * - Circuit Playground Bluefruit (https://www.adafruit.com/product/4333) + * - CLUE nRF52840 (https://www.adafruit.com/product/4500) + */ + #include #include #include #include -#include // BLE Service BLEDfu bledfu; // OTA DFU service @@ -32,40 +38,75 @@ BLEAdafruitTone bleTone; BLEAdafruitAddressablePixel blePixel; -Adafruit_NeoPixel strip = Adafruit_NeoPixel(10, CPLAY_NEOPIXELPIN, NEO_GRB + NEO_KHZ800); +// Circuit Playground Bluefruit +#if defined ARDUINO_NRF52840_CIRCUITPLAY + #include + + #define DEVICE_NAME "CPlay" + #define NEOPIXEL_COUNT 10 + + +#elif defined ARDUINO_NRF52840_CLUE + + #define DEVICE_NAME "CLUE" + #define NEOPIXEL_COUNT 1 + + +#else + #error "Board is not supported" +#endif + +Adafruit_NeoPixel strip = Adafruit_NeoPixel(NEOPIXEL_COUNT, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800); uint16_t measure_button(uint8_t* buf, uint16_t bufsize) { uint32_t button = 0; +#if defined ARDUINO_NRF52840_CIRCUITPLAY button |= ( CircuitPlayground.slideSwitch() ? 0x01 : 0x00 ); button |= ( CircuitPlayground.leftButton() ? 0x02 : 0x00 ); button |= ( CircuitPlayground.rightButton() ? 0x04 : 0x00 ); +#else + // Button is active LOW on most board except CPlay + + // No slide switch + button |= ( digitalRead(PIN_BUTTON1) ? 0x00 : 0x02 ); + button |= ( digitalRead(PIN_BUTTON2) ? 0x00 : 0x04 ); + +#endif + memcpy(buf, &button, 4); return 4; } uint16_t measure_temperature(uint8_t* buf, uint16_t bufsize) { +#if defined ARDUINO_NRF52840_CIRCUITPLAY float temp = CircuitPlayground.temperature(); memcpy(buf, &temp, 4); +#endif return 4; } uint16_t measure_light_sensor(uint8_t* buf, uint16_t bufsize) { +#if defined ARDUINO_NRF52840_CIRCUITPLAY float lux = CircuitPlayground.lightSensor(); memcpy(buf, &lux, 4); +#endif return 4; } uint16_t measure_accel(uint8_t* buf, uint16_t bufsize) { float accel[3]; + +#if defined ARDUINO_NRF52840_CIRCUITPLAY accel[0] = CircuitPlayground.motionX(); accel[1] = CircuitPlayground.motionY(); accel[2] = CircuitPlayground.motionZ(); +#endif memcpy(buf, accel, sizeof(accel)); return sizeof(accel); @@ -79,7 +120,19 @@ void setup() Serial.println("Bluefruit52 BLEUART Example"); Serial.println("---------------------------\n"); +#if defined ARDUINO_NRF52840_CIRCUITPLAY CircuitPlayground.begin(); +#else + + // Button + pinMode(PIN_BUTTON1, INPUT_PULLUP); + pinMode(PIN_BUTTON2, INPUT_PULLUP); + + // Buzzer Speaker + pinMode(PIN_BUZZER, OUTPUT); +#endif + + // Setup the BLE LED to be enabled on CONNECT // Note: This is actually the default behaviour, but provided @@ -92,8 +145,8 @@ void setup() Bluefruit.configPrphBandwidth(BANDWIDTH_MAX); Bluefruit.begin(); - Bluefruit.setTxPower(4); // Check bluefruit.h for supported values - Bluefruit.setName("Bluefruit52"); + Bluefruit.setTxPower(8); // Check bluefruit.h for supported values + Bluefruit.setName(DEVICE_NAME); //Bluefruit.setName(getMcuUniqueID()); // useful testing with multiple central connections Bluefruit.Periph.setConnectCallback(connect_callback); Bluefruit.Periph.setDisconnectCallback(disconnect_callback); @@ -127,7 +180,7 @@ void setup() bleButton.setMeasureCallback(measure_button); bleButton.setPeriod(0); // only notify if there is changes with buttons - bleTone.begin(CPLAY_BUZZER); + bleTone.begin(PIN_BUZZER); strip.begin(); blePixel.begin(&strip); @@ -160,9 +213,8 @@ void startAdv(void) Bluefruit.Advertising.addManufacturerData(&mfr_adv, sizeof(mfr_adv)); - // Secondary Scan Response packet (optional) - // Since there is no room for 'Name' in Advertising packet - Bluefruit.ScanResponse.addName(); + // Add name to advertising, since there is enough room + Bluefruit.Advertising.addName(); /* Start Advertising * - Enable auto advertising if disconnected From d16b63d4c299d3515decc454c06a6a793a967753 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 17 Feb 2020 13:14:56 +0700 Subject: [PATCH 04/21] light works --- .../.cluenrf52840.test.only | 0 .../bluefruit_playground.ino | 20 ++++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/.cluenrf52840.test.only diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/.cluenrf52840.test.only b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/.cluenrf52840.test.only new file mode 100644 index 00000000..e69de29b diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino index 9cfe7b22..65d99847 100644 --- a/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino +++ b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino @@ -47,11 +47,11 @@ BLEAdafruitAddressablePixel blePixel; #elif defined ARDUINO_NRF52840_CLUE - + #include #define DEVICE_NAME "CLUE" #define NEOPIXEL_COUNT 1 - + Adafruit_APDS9960 apds9960; #else #error "Board is not supported" #endif @@ -73,7 +73,6 @@ uint16_t measure_button(uint8_t* buf, uint16_t bufsize) // No slide switch button |= ( digitalRead(PIN_BUTTON1) ? 0x00 : 0x02 ); button |= ( digitalRead(PIN_BUTTON2) ? 0x00 : 0x04 ); - #endif memcpy(buf, &button, 4); @@ -91,10 +90,18 @@ uint16_t measure_temperature(uint8_t* buf, uint16_t bufsize) uint16_t measure_light_sensor(uint8_t* buf, uint16_t bufsize) { + float lux; + #if defined ARDUINO_NRF52840_CIRCUITPLAY - float lux = CircuitPlayground.lightSensor(); - memcpy(buf, &lux, 4); + lux = CircuitPlayground.lightSensor(); +#else + uint16_t r, g, b, c; + apds9960.getColorData(&r, &g, &b, &c); + + lux = c; #endif + + memcpy(buf, &lux, 4); return 4; } @@ -130,6 +137,9 @@ void setup() // Buzzer Speaker pinMode(PIN_BUZZER, OUTPUT); + + apds9960.begin(); + apds9960.enableColor(true); #endif From da841fa4865ab57d8d0bee70c1b805988f65e27b Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 17 Feb 2020 13:30:57 +0700 Subject: [PATCH 05/21] accel works --- .../bluefruit_playground.ino | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino index 65d99847..2c63e164 100644 --- a/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino +++ b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino @@ -48,10 +48,13 @@ BLEAdafruitAddressablePixel blePixel; #elif defined ARDUINO_NRF52840_CLUE #include + #include + #define DEVICE_NAME "CLUE" #define NEOPIXEL_COUNT 1 Adafruit_APDS9960 apds9960; + Adafruit_LSM6DS33 lsm6ds33; #else #error "Board is not supported" #endif @@ -107,16 +110,25 @@ uint16_t measure_light_sensor(uint8_t* buf, uint16_t bufsize) uint16_t measure_accel(uint8_t* buf, uint16_t bufsize) { - float accel[3]; + float* accel_buf = (float*) buf; #if defined ARDUINO_NRF52840_CIRCUITPLAY - accel[0] = CircuitPlayground.motionX(); - accel[1] = CircuitPlayground.motionY(); - accel[2] = CircuitPlayground.motionZ(); + accel_buf[0] = CircuitPlayground.motionX(); + accel_buf[1] = CircuitPlayground.motionY(); + accel_buf[2] = CircuitPlayground.motionZ(); +#else + + sensors_event_t accel, gyro, temp; + (void) gyro; (void) temp; + + lsm6ds33.getEvent(&accel, &gyro, &temp); + + accel_buf[0] = accel.acceleration.x; + accel_buf[1] = accel.acceleration.y; + accel_buf[2] = accel.acceleration.z; #endif - memcpy(buf, accel, sizeof(accel)); - return sizeof(accel); + return 3*sizeof(float); // 12 } void setup() @@ -138,8 +150,12 @@ void setup() // Buzzer Speaker pinMode(PIN_BUZZER, OUTPUT); + // Light sensor apds9960.begin(); apds9960.enableColor(true); + + // Accelerometer + lsm6ds33.begin_I2C(); #endif From 8c5c66ef17e520d4e6c987d23d2ec740ffc25a15 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 17 Feb 2020 13:52:29 +0700 Subject: [PATCH 06/21] temp work --- .../bluefruit_playground/bluefruit_playground.ino | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino index 2c63e164..843fe976 100644 --- a/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino +++ b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino @@ -49,12 +49,14 @@ BLEAdafruitAddressablePixel blePixel; #elif defined ARDUINO_NRF52840_CLUE #include #include + #include #define DEVICE_NAME "CLUE" #define NEOPIXEL_COUNT 1 Adafruit_APDS9960 apds9960; Adafruit_LSM6DS33 lsm6ds33; + Adafruit_BMP280 bmp280; #else #error "Board is not supported" #endif @@ -84,10 +86,14 @@ uint16_t measure_button(uint8_t* buf, uint16_t bufsize) uint16_t measure_temperature(uint8_t* buf, uint16_t bufsize) { + float temp; #if defined ARDUINO_NRF52840_CIRCUITPLAY - float temp = CircuitPlayground.temperature(); - memcpy(buf, &temp, 4); + temp = CircuitPlayground.temperature(); +#else + temp = bmp280.readTemperature(); #endif + + memcpy(buf, &temp, 4); return 4; } @@ -156,10 +162,11 @@ void setup() // Accelerometer lsm6ds33.begin_I2C(); + + // Pressure + Temperature + bmp280.begin(); #endif - - // Setup the BLE LED to be enabled on CONNECT // Note: This is actually the default behaviour, but provided // here in case you want to control this LED manually via PIN 19 From 6784efc4a19c47c081485b43c75001afbeb2477b Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 17 Feb 2020 14:05:07 +0700 Subject: [PATCH 07/21] clean up --- .../bluefruit_playground.ino | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino index 843fe976..3a124775 100644 --- a/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino +++ b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino @@ -58,6 +58,7 @@ BLEAdafruitAddressablePixel blePixel; Adafruit_LSM6DS33 lsm6ds33; Adafruit_BMP280 bmp280; #else + #error "Board is not supported" #endif @@ -72,12 +73,13 @@ uint16_t measure_button(uint8_t* buf, uint16_t bufsize) button |= ( CircuitPlayground.leftButton() ? 0x02 : 0x00 ); button |= ( CircuitPlayground.rightButton() ? 0x04 : 0x00 ); -#else +#elif defined ARDUINO_NRF52840_CLUE // Button is active LOW on most board except CPlay // No slide switch button |= ( digitalRead(PIN_BUTTON1) ? 0x00 : 0x02 ); button |= ( digitalRead(PIN_BUTTON2) ? 0x00 : 0x04 ); + #endif memcpy(buf, &button, 4); @@ -87,10 +89,13 @@ uint16_t measure_button(uint8_t* buf, uint16_t bufsize) uint16_t measure_temperature(uint8_t* buf, uint16_t bufsize) { float temp; + #if defined ARDUINO_NRF52840_CIRCUITPLAY temp = CircuitPlayground.temperature(); -#else + +#elif defined ARDUINO_NRF52840_CLUE temp = bmp280.readTemperature(); + #endif memcpy(buf, &temp, 4); @@ -122,7 +127,8 @@ uint16_t measure_accel(uint8_t* buf, uint16_t bufsize) accel_buf[0] = CircuitPlayground.motionX(); accel_buf[1] = CircuitPlayground.motionY(); accel_buf[2] = CircuitPlayground.motionZ(); -#else + +#elif defined ARDUINO_NRF52840_CLUE sensors_event_t accel, gyro, temp; (void) gyro; (void) temp; @@ -132,6 +138,7 @@ uint16_t measure_accel(uint8_t* buf, uint16_t bufsize) accel_buf[0] = accel.acceleration.x; accel_buf[1] = accel.acceleration.y; accel_buf[2] = accel.acceleration.z; + #endif return 3*sizeof(float); // 12 @@ -147,7 +154,8 @@ void setup() #if defined ARDUINO_NRF52840_CIRCUITPLAY CircuitPlayground.begin(); -#else + +#elif defined ARDUINO_NRF52840_CLUE // Button pinMode(PIN_BUTTON1, INPUT_PULLUP); From 8330bd9c1128622444a39d15c09288994592f968 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 17 Feb 2020 14:34:02 +0700 Subject: [PATCH 08/21] use USB_PRODUCT string for default bledis model --- boards.txt | 6 +++--- .../bluefruit_playground/bluefruit_playground.ino | 1 - libraries/Bluefruit52Lib/src/services/BLEDis.cpp | 6 +++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/boards.txt b/boards.txt index f789cb30..30fece90 100644 --- a/boards.txt +++ b/boards.txt @@ -144,7 +144,7 @@ feather52840sense.build.board=NRF52840_FEATHER_SENSE feather52840sense.build.core=nRF5 feather52840sense.build.variant=feather_nrf52840_sense feather52840sense.build.usb_manufacturer="Adafruit LLC" -feather52840sense.build.usb_product="Feather Bluefruit Sense" +feather52840sense.build.usb_product="Feather nRF52840 Sense" feather52840sense.build.extra_flags=-DNRF52840_XXAA {build.flags.usb} feather52840sense.build.ldscript=nrf52840_s140_v6.ld feather52840sense.build.vid=0x239A @@ -251,7 +251,7 @@ cplaynrf52840.build.board=NRF52840_CIRCUITPLAY cplaynrf52840.build.core=nRF5 cplaynrf52840.build.variant=circuitplayground_nrf52840 cplaynrf52840.build.usb_manufacturer="Adafruit LLC" -cplaynrf52840.build.usb_product="Adafruit Circuit Playground Bluefruit" +cplaynrf52840.build.usb_product="Circuit Playground Bluefruit" cplaynrf52840.build.extra_flags=-DNRF52840_XXAA {build.flags.usb} cplaynrf52840.build.ldscript=nrf52840_s140_v6.ld cplaynrf52840.build.vid=0x239A @@ -305,7 +305,7 @@ cluenrf52840.build.board=NRF52840_CLUE cluenrf52840.build.core=nRF5 cluenrf52840.build.variant=clue_nrf52840 cluenrf52840.build.usb_manufacturer="Adafruit LLC" -cluenrf52840.build.usb_product="Adafruit Clue" +cluenrf52840.build.usb_product="CLUE" cluenrf52840.build.extra_flags=-DNRF52840_XXAA {build.flags.usb} cluenrf52840.build.ldscript=nrf52840_s140_v6.ld cluenrf52840.build.vid=0x239A diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino index 3a124775..4efb324f 100644 --- a/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino +++ b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino @@ -197,7 +197,6 @@ void setup() // Configure and Start Device Information Service bledis.setManufacturer("Adafruit Industries"); - bledis.setModel("Bluefruit Feather52"); bledis.begin(); // Configure and Start BLE Uart Service diff --git a/libraries/Bluefruit52Lib/src/services/BLEDis.cpp b/libraries/Bluefruit52Lib/src/services/BLEDis.cpp index 0ca3f92b..d573d229 100644 --- a/libraries/Bluefruit52Lib/src/services/BLEDis.cpp +++ b/libraries/Bluefruit52Lib/src/services/BLEDis.cpp @@ -43,10 +43,10 @@ BLEDis::BLEDis(void) memclr(_strarr, sizeof(_strarr)); memclr(_strarr_length, sizeof(_strarr_length)); -#ifdef NRF52840_XXAA - this->setModel("Bluefruit Feather nRF52840"); +#ifdef USB_PRODUCT + this->setModel(USB_PRODUCT); #else - this->setModel("Bluefruit Feather nRF52832"); + this->setModel("Feather nRF52832"); #endif this->setSoftwareRev(ARDUINO_BSP_VERSION); From 74c91a82157318007b714708587571ac06f48406 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 18 Feb 2020 11:07:47 +0700 Subject: [PATCH 09/21] Add Gyro sensor --- .../src/BLEAdafruitService.h | 11 +-- .../src/services/BLEAdafruitAccel.h | 4 +- .../src/services/BLEAdafruitGyro.cpp | 74 +++++++++++++++++++ .../src/services/BLEAdafruitGyro.h | 38 ++++++++++ .../src/services/BLEAdafruitLightSensor.h | 2 - 5 files changed, 119 insertions(+), 10 deletions(-) create mode 100644 libraries/BLEAdafruitService/src/services/BLEAdafruitGyro.cpp create mode 100644 libraries/BLEAdafruitService/src/services/BLEAdafruitGyro.h diff --git a/libraries/BLEAdafruitService/src/BLEAdafruitService.h b/libraries/BLEAdafruitService/src/BLEAdafruitService.h index 0fb56bbe..57867ac9 100644 --- a/libraries/BLEAdafruitService/src/BLEAdafruitService.h +++ b/libraries/BLEAdafruitService/src/BLEAdafruitService.h @@ -28,13 +28,14 @@ #include "bluefruit_common.h" #include "BLECharacteristic.h" #include "BLEService.h" - #include "services/BLEAdafruitSensor.h" -#include "services/BLEAdafruitTemperature.h" + #include "services/BLEAdafruitAccel.h" -#include "services/BLEAdafruitLightSensor.h" -#include "services/BLEAdafruitButton.h" -#include "services/BLEAdafruitTone.h" #include "services/BLEAdafruitAddressablePixel.h" +#include "services/BLEAdafruitButton.h" +#include "services/BLEAdafruitGyro.h" +#include "services/BLEAdafruitLightSensor.h" +#include "services/BLEAdafruitTemperature.h" +#include "services/BLEAdafruitTone.h" #endif /* BLEADAFRUITSERVICE_H_ */ diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitAccel.h b/libraries/BLEAdafruitService/src/services/BLEAdafruitAccel.h index 45ed51cc..28c3ab65 100644 --- a/libraries/BLEAdafruitService/src/services/BLEAdafruitAccel.h +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitAccel.h @@ -23,7 +23,7 @@ */ #ifndef BLEADAFRUITACCEL_H_ -#define BLEADAFRUITACCEL_H_ +#define BLEADAFRUITGYRO_H_ class BLEAdafruitAccel : public BLEAdafruitSensor { @@ -31,8 +31,6 @@ class BLEAdafruitAccel : public BLEAdafruitSensor static const uint8_t UUID128_SERVICE[16]; static const uint8_t UUID128_CHR_DATA[16]; - BLECharacteristic Accel; - BLEAdafruitAccel(void); virtual err_t begin(void); }; diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitGyro.cpp b/libraries/BLEAdafruitService/src/services/BLEAdafruitGyro.cpp new file mode 100644 index 00000000..9172a6c3 --- /dev/null +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitGyro.cpp @@ -0,0 +1,74 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2019 Ha Thach (tinyusb.org) for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "BLEAdafruitService.h" + +//--------------------------------------------------------------------+ +// MACRO TYPEDEF CONSTANT ENUM DECLARATION +//--------------------------------------------------------------------+ + + +/* All Adafruit Service/Characteristic UUID128 share the same Base UUID: + * ADAFxxx-C332-42A8-93BD-25E905756CB8 + * + * Shared Characteristics + * - Measurement Period 0001 | int32_t | Read + Write | + * ms between measurements, -1: stop reading, 0: update when changes + * + * Accelerometer service 0400 + * - Accel 0401 | float[3] | Read + Notify | x, y, z + * - Measurement Period 0001 + */ + +const uint8_t BLEAdafruitGyro::UUID128_SERVICE[16] = +{ + 0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93, + 0xA8, 0x42, 0x32, 0xC3, 0x00, 0x04, 0xAF, 0xAD +}; + +const uint8_t BLEAdafruitGyro::UUID128_CHR_DATA[16] = +{ + 0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93, + 0xA8, 0x42, 0x32, 0xC3, 0x01, 0x04, 0xAF, 0xAD +}; + +// Constructor +BLEAdafruitGyro::BLEAdafruitGyro(void) + : BLEAdafruitSensor(UUID128_SERVICE, UUID128_CHR_DATA) +{ + +} + +err_t BLEAdafruitGyro::begin (void) +{ + // Setup Measurement Characteristic + _measurement.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY); + _measurement.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS); + _measurement.setFixedLen(4*3); // float[3] + + // Invoke base class begin(), this will add Service, Measurement and Period characteristics + VERIFY_STATUS( BLEAdafruitSensor::begin(1000) ); + + return ERROR_NONE; +} diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitGyro.h b/libraries/BLEAdafruitService/src/services/BLEAdafruitGyro.h new file mode 100644 index 00000000..9d8f1d24 --- /dev/null +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitGyro.h @@ -0,0 +1,38 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2019 Ha Thach (tinyusb.org) for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef BLEADAFRUITACCEL_H_ +#define BLEADAFRUITGYRO_H_ + +class BLEAdafruitGyro : public BLEAdafruitSensor +{ + public: + static const uint8_t UUID128_SERVICE[16]; + static const uint8_t UUID128_CHR_DATA[16]; + + BLEAdafruitGyro(void); + virtual err_t begin(void); +}; + +#endif /* BLEADAFRUITACCEL_H_ */ diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitLightSensor.h b/libraries/BLEAdafruitService/src/services/BLEAdafruitLightSensor.h index bcf4200d..cba64da0 100644 --- a/libraries/BLEAdafruitService/src/services/BLEAdafruitLightSensor.h +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitLightSensor.h @@ -31,8 +31,6 @@ class BLEAdafruitLightSensor : public BLEAdafruitSensor static const uint8_t UUID128_SERVICE[16]; static const uint8_t UUID128_CHR_DATA[16]; - BLECharacteristic Lux; - BLEAdafruitLightSensor(void); virtual err_t begin(void); }; From 0333b2adc2b2afa58d4d8c0ff85c3975fddbf7d2 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 18 Feb 2020 11:24:14 +0700 Subject: [PATCH 10/21] add Magnetic service, add default period for sensor services --- .../src/BLEAdafruitService.h | 1 + .../src/services/BLEAdafruitAccel.cpp | 2 +- .../src/services/BLEAdafruitAccel.h | 3 +- .../src/services/BLEAdafruitButton.cpp | 2 +- .../src/services/BLEAdafruitButton.h | 1 + .../src/services/BLEAdafruitGyro.cpp | 6 +- .../src/services/BLEAdafruitGyro.h | 5 +- .../src/services/BLEAdafruitLightSensor.cpp | 2 +- .../src/services/BLEAdafruitLightSensor.h | 1 + .../src/services/BLEAdafruitMagnetic.cpp | 74 +++++++++++++++++++ .../src/services/BLEAdafruitMagnetic.h | 39 ++++++++++ .../src/services/BLEAdafruitTemperature.cpp | 2 +- .../src/services/BLEAdafruitTemperature.h | 1 + 13 files changed, 129 insertions(+), 10 deletions(-) create mode 100644 libraries/BLEAdafruitService/src/services/BLEAdafruitMagnetic.cpp create mode 100644 libraries/BLEAdafruitService/src/services/BLEAdafruitMagnetic.h diff --git a/libraries/BLEAdafruitService/src/BLEAdafruitService.h b/libraries/BLEAdafruitService/src/BLEAdafruitService.h index 57867ac9..894def7c 100644 --- a/libraries/BLEAdafruitService/src/BLEAdafruitService.h +++ b/libraries/BLEAdafruitService/src/BLEAdafruitService.h @@ -35,6 +35,7 @@ #include "services/BLEAdafruitButton.h" #include "services/BLEAdafruitGyro.h" #include "services/BLEAdafruitLightSensor.h" +#include "services/BLEAdafruitMagnetic.h" #include "services/BLEAdafruitTemperature.h" #include "services/BLEAdafruitTone.h" diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitAccel.cpp b/libraries/BLEAdafruitService/src/services/BLEAdafruitAccel.cpp index 044163b8..ef97572e 100644 --- a/libraries/BLEAdafruitService/src/services/BLEAdafruitAccel.cpp +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitAccel.cpp @@ -68,7 +68,7 @@ err_t BLEAdafruitAccel::begin (void) _measurement.setFixedLen(4*3); // Invoke base class begin(), this will add Service, Measurement and Period characteristics - VERIFY_STATUS( BLEAdafruitSensor::begin(1000) ); + VERIFY_STATUS( BLEAdafruitSensor::begin(DEFAULT_PERIOD) ); return ERROR_NONE; } diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitAccel.h b/libraries/BLEAdafruitService/src/services/BLEAdafruitAccel.h index 28c3ab65..47830aec 100644 --- a/libraries/BLEAdafruitService/src/services/BLEAdafruitAccel.h +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitAccel.h @@ -23,13 +23,14 @@ */ #ifndef BLEADAFRUITACCEL_H_ -#define BLEADAFRUITGYRO_H_ +#define BLEADAFRUITACCEL_H_ class BLEAdafruitAccel : public BLEAdafruitSensor { public: static const uint8_t UUID128_SERVICE[16]; static const uint8_t UUID128_CHR_DATA[16]; + static const int32_t DEFAULT_PERIOD = 1000; BLEAdafruitAccel(void); virtual err_t begin(void); diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitButton.cpp b/libraries/BLEAdafruitService/src/services/BLEAdafruitButton.cpp index 11ff0c19..6006d0d3 100644 --- a/libraries/BLEAdafruitService/src/services/BLEAdafruitButton.cpp +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitButton.cpp @@ -67,7 +67,7 @@ err_t BLEAdafruitButton::begin(void) _measurement.setFixedLen(4); // Invoke base class begin(), this will add Service, Measurement and Period characteristics - VERIFY_STATUS( BLEAdafruitSensor::begin(100) ); + VERIFY_STATUS( BLEAdafruitSensor::begin(DEFAULT_PERIOD) ); return ERROR_NONE; } diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitButton.h b/libraries/BLEAdafruitService/src/services/BLEAdafruitButton.h index 2bdc40e3..e9ee4de6 100644 --- a/libraries/BLEAdafruitService/src/services/BLEAdafruitButton.h +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitButton.h @@ -30,6 +30,7 @@ class BLEAdafruitButton : public BLEAdafruitSensor public: static const uint8_t UUID128_SERVICE[16]; static const uint8_t UUID128_CHR_DATA[16]; + static const int32_t DEFAULT_PERIOD = 0; BLEAdafruitButton(void); virtual err_t begin(void); diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitGyro.cpp b/libraries/BLEAdafruitService/src/services/BLEAdafruitGyro.cpp index 9172a6c3..3d5577fa 100644 --- a/libraries/BLEAdafruitService/src/services/BLEAdafruitGyro.cpp +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitGyro.cpp @@ -36,8 +36,8 @@ * - Measurement Period 0001 | int32_t | Read + Write | * ms between measurements, -1: stop reading, 0: update when changes * - * Accelerometer service 0400 - * - Accel 0401 | float[3] | Read + Notify | x, y, z + * Gyroscope service 0400 + * - Gyro 0401 | float[3] | Read + Notify | x, y, z * - Measurement Period 0001 */ @@ -68,7 +68,7 @@ err_t BLEAdafruitGyro::begin (void) _measurement.setFixedLen(4*3); // float[3] // Invoke base class begin(), this will add Service, Measurement and Period characteristics - VERIFY_STATUS( BLEAdafruitSensor::begin(1000) ); + VERIFY_STATUS( BLEAdafruitSensor::begin(DEFAULT_PERIOD) ); return ERROR_NONE; } diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitGyro.h b/libraries/BLEAdafruitService/src/services/BLEAdafruitGyro.h index 9d8f1d24..29eb6063 100644 --- a/libraries/BLEAdafruitService/src/services/BLEAdafruitGyro.h +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitGyro.h @@ -22,7 +22,7 @@ * THE SOFTWARE. */ -#ifndef BLEADAFRUITACCEL_H_ +#ifndef BLEADAFRUITGYRO_H_ #define BLEADAFRUITGYRO_H_ class BLEAdafruitGyro : public BLEAdafruitSensor @@ -30,9 +30,10 @@ class BLEAdafruitGyro : public BLEAdafruitSensor public: static const uint8_t UUID128_SERVICE[16]; static const uint8_t UUID128_CHR_DATA[16]; + static const int32_t DEFAULT_PERIOD = 1000; BLEAdafruitGyro(void); virtual err_t begin(void); }; -#endif /* BLEADAFRUITACCEL_H_ */ +#endif /* BLEADAFRUITGYRO_H_ */ diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitLightSensor.cpp b/libraries/BLEAdafruitService/src/services/BLEAdafruitLightSensor.cpp index 1238e194..c949eb74 100644 --- a/libraries/BLEAdafruitService/src/services/BLEAdafruitLightSensor.cpp +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitLightSensor.cpp @@ -68,7 +68,7 @@ err_t BLEAdafruitLightSensor::begin (void) _measurement.setFixedLen(4); // Invoke base class begin(), this will add Service, Measurement and Period characteristics - VERIFY_STATUS( BLEAdafruitSensor::begin(1000) ); + VERIFY_STATUS( BLEAdafruitSensor::begin(DEFAULT_PERIOD) ); return ERROR_NONE; } diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitLightSensor.h b/libraries/BLEAdafruitService/src/services/BLEAdafruitLightSensor.h index cba64da0..a803a950 100644 --- a/libraries/BLEAdafruitService/src/services/BLEAdafruitLightSensor.h +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitLightSensor.h @@ -30,6 +30,7 @@ class BLEAdafruitLightSensor : public BLEAdafruitSensor public: static const uint8_t UUID128_SERVICE[16]; static const uint8_t UUID128_CHR_DATA[16]; + static const int32_t DEFAULT_PERIOD = 1000; BLEAdafruitLightSensor(void); virtual err_t begin(void); diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitMagnetic.cpp b/libraries/BLEAdafruitService/src/services/BLEAdafruitMagnetic.cpp new file mode 100644 index 00000000..1f45f121 --- /dev/null +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitMagnetic.cpp @@ -0,0 +1,74 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2019 Ha Thach (tinyusb.org) for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "BLEAdafruitService.h" + +//--------------------------------------------------------------------+ +// MACRO TYPEDEF CONSTANT ENUM DECLARATION +//--------------------------------------------------------------------+ + + +/* All Adafruit Service/Characteristic UUID128 share the same Base UUID: + * ADAFxxx-C332-42A8-93BD-25E905756CB8 + * + * Shared Characteristics + * - Measurement Period 0001 | int32_t | Read + Write | + * ms between measurements, -1: stop reading, 0: update when changes + * + * Magnetic service 0500 + * - Magnetic 0501 | float[3] | Read + Notify | x, y, z + * - Measurement Period 0001 + */ + +const uint8_t BLEAdafruitMagnetic::UUID128_SERVICE[16] = +{ + 0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93, + 0xA8, 0x42, 0x32, 0xC3, 0x00, 0x05, 0xAF, 0xAD +}; + +const uint8_t BLEAdafruitMagnetic::UUID128_CHR_DATA[16] = +{ + 0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93, + 0xA8, 0x42, 0x32, 0xC3, 0x01, 0x05, 0xAF, 0xAD +}; + +// Constructor +BLEAdafruitMagnetic::BLEAdafruitMagnetic(void) + : BLEAdafruitSensor(UUID128_SERVICE, UUID128_CHR_DATA) +{ + +} + +err_t BLEAdafruitMagnetic::begin (void) +{ + // Setup Measurement Characteristic + _measurement.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY); + _measurement.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS); + _measurement.setFixedLen(4*3); // float[3] + + // Invoke base class begin(), this will add Service, Measurement and Period characteristics + VERIFY_STATUS( BLEAdafruitSensor::begin(DEFAULT_PERIOD) ); + + return ERROR_NONE; +} diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitMagnetic.h b/libraries/BLEAdafruitService/src/services/BLEAdafruitMagnetic.h new file mode 100644 index 00000000..d8eddb89 --- /dev/null +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitMagnetic.h @@ -0,0 +1,39 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2019 Ha Thach (tinyusb.org) for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef BLEADAFRUITMAGNETIC_H_ +#define BLEADAFRUITMAGNETIC_H_ + +class BLEAdafruitMagnetic : public BLEAdafruitSensor +{ + public: + static const uint8_t UUID128_SERVICE[16]; + static const uint8_t UUID128_CHR_DATA[16]; + static const int32_t DEFAULT_PERIOD = 1000; + + BLEAdafruitMagnetic(void); + virtual err_t begin(void); +}; + +#endif /* BLEADAFRUITMAGNETIC_H_ */ diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitTemperature.cpp b/libraries/BLEAdafruitService/src/services/BLEAdafruitTemperature.cpp index f9667152..ca16ebc8 100644 --- a/libraries/BLEAdafruitService/src/services/BLEAdafruitTemperature.cpp +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitTemperature.cpp @@ -67,7 +67,7 @@ err_t BLEAdafruitTemperature::begin (void) _measurement.setFixedLen(4); // Invoke base class begin(), this will add Service, Measurement and Period characteristics - VERIFY_STATUS( BLEAdafruitSensor::begin(1000) ); + VERIFY_STATUS( BLEAdafruitSensor::begin(DEFAULT_PERIOD) ); return ERROR_NONE; } diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitTemperature.h b/libraries/BLEAdafruitService/src/services/BLEAdafruitTemperature.h index 7ab8b837..d4228fc0 100644 --- a/libraries/BLEAdafruitService/src/services/BLEAdafruitTemperature.h +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitTemperature.h @@ -30,6 +30,7 @@ class BLEAdafruitTemperature : public BLEAdafruitSensor public: static const uint8_t UUID128_SERVICE[16]; static const uint8_t UUID128_CHR_DATA[16]; + static const int32_t DEFAULT_PERIOD = 1000; BLEAdafruitTemperature(); virtual err_t begin(void); From cfe4d099cfa421548d265f909cd3a00dfdcf231e Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 18 Feb 2020 12:08:53 +0700 Subject: [PATCH 11/21] clean up --- .../bluefruit_playground.ino | 101 +++++++++++------- 1 file changed, 60 insertions(+), 41 deletions(-) diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino index 4efb324f..d1fa0d65 100644 --- a/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino +++ b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino @@ -33,20 +33,23 @@ BLEBas blebas; // battery BLEAdafruitTemperature bleTemp; BLEAdafruitAccel bleAccel; BLEAdafruitLightSensor bleLight; +BLEAdafruitGyro bleGyro; +BLEAdafruitMagnetic bleMagnetic; + BLEAdafruitButton bleButton; BLEAdafruitTone bleTone; BLEAdafruitAddressablePixel blePixel; // Circuit Playground Bluefruit -#if defined ARDUINO_NRF52840_CIRCUITPLAY +#if defined( ARDUINO_NRF52840_CIRCUITPLAY ) #include #define DEVICE_NAME "CPlay" #define NEOPIXEL_COUNT 10 -#elif defined ARDUINO_NRF52840_CLUE +#elif defined( ARDUINO_NRF52840_CLUE ) || defined( ARDUINO_NRF52840_FEATHER_SENSE ) #include #include #include @@ -64,28 +67,6 @@ BLEAdafruitAddressablePixel blePixel; Adafruit_NeoPixel strip = Adafruit_NeoPixel(NEOPIXEL_COUNT, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800); -uint16_t measure_button(uint8_t* buf, uint16_t bufsize) -{ - uint32_t button = 0; - -#if defined ARDUINO_NRF52840_CIRCUITPLAY - button |= ( CircuitPlayground.slideSwitch() ? 0x01 : 0x00 ); - button |= ( CircuitPlayground.leftButton() ? 0x02 : 0x00 ); - button |= ( CircuitPlayground.rightButton() ? 0x04 : 0x00 ); - -#elif defined ARDUINO_NRF52840_CLUE - // Button is active LOW on most board except CPlay - - // No slide switch - button |= ( digitalRead(PIN_BUTTON1) ? 0x00 : 0x02 ); - button |= ( digitalRead(PIN_BUTTON2) ? 0x00 : 0x04 ); - -#endif - - memcpy(buf, &button, 4); - return 4; -} - uint16_t measure_temperature(uint8_t* buf, uint16_t bufsize) { float temp; @@ -102,23 +83,6 @@ uint16_t measure_temperature(uint8_t* buf, uint16_t bufsize) return 4; } -uint16_t measure_light_sensor(uint8_t* buf, uint16_t bufsize) -{ - float lux; - -#if defined ARDUINO_NRF52840_CIRCUITPLAY - lux = CircuitPlayground.lightSensor(); -#else - uint16_t r, g, b, c; - apds9960.getColorData(&r, &g, &b, &c); - - lux = c; -#endif - - memcpy(buf, &lux, 4); - return 4; -} - uint16_t measure_accel(uint8_t* buf, uint16_t bufsize) { float* accel_buf = (float*) buf; @@ -144,6 +108,55 @@ uint16_t measure_accel(uint8_t* buf, uint16_t bufsize) return 3*sizeof(float); // 12 } +uint16_t measure_light_sensor(uint8_t* buf, uint16_t bufsize) +{ + float lux; + +#if defined ARDUINO_NRF52840_CIRCUITPLAY + lux = CircuitPlayground.lightSensor(); +#else + uint16_t r, g, b, c; + apds9960.getColorData(&r, &g, &b, &c); + + lux = c; +#endif + + memcpy(buf, &lux, 4); + return 4; +} + +uint16_t measure_gyro(uint8_t* buf, uint16_t bufsize) +{ + +} + +uint16_t measure_magnetic(uint8_t* buf, uint16_t bufsize) +{ + +} + +uint16_t measure_button(uint8_t* buf, uint16_t bufsize) +{ + uint32_t button = 0; + +#if defined ARDUINO_NRF52840_CIRCUITPLAY + button |= ( CircuitPlayground.slideSwitch() ? 0x01 : 0x00 ); + button |= ( CircuitPlayground.leftButton() ? 0x02 : 0x00 ); + button |= ( CircuitPlayground.rightButton() ? 0x04 : 0x00 ); + +#elif defined ARDUINO_NRF52840_CLUE + // Button is active LOW on most board except CPlay + + // No slide switch + button |= ( digitalRead(PIN_BUTTON1) ? 0x00 : 0x02 ); + button |= ( digitalRead(PIN_BUTTON2) ? 0x00 : 0x04 ); + +#endif + + memcpy(buf, &button, 4); + return 4; +} + void setup() { Serial.begin(115200); @@ -215,6 +228,12 @@ void setup() bleLight.begin(); bleLight.setMeasureCallback(measure_light_sensor); + +// bleGyro.begin(); +// bleGyro.setMeasureCallback(measure_gyro); +// +// bleMagnetic.begin(); +// bleMagnetic.setMeasureCallback(measure_magnetic); bleButton.begin(); bleButton.setMeasureCallback(measure_button); From a6b5768cef5a2883f88edd4222e98ca604ca7723 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 19 Feb 2020 01:28:14 +0700 Subject: [PATCH 12/21] clean up --- .../bluefruit_playground.ino | 180 ++++++++++-------- 1 file changed, 104 insertions(+), 76 deletions(-) diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino index d1fa0d65..3e802b48 100644 --- a/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino +++ b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino @@ -14,8 +14,9 @@ /* This sketch demonstrate the BLE Adafruit Service that is used with * "Adafruit Bluefruit Playground" app. Supported boards are - * - Circuit Playground Bluefruit (https://www.adafruit.com/product/4333) - * - CLUE nRF52840 (https://www.adafruit.com/product/4500) + * - Circuit Playground Bluefruit : https://www.adafruit.com/product/4333 + * - CLUE nRF52840 : https://www.adafruit.com/product/4500 + * - Feather Sense : https://www.adafruit.com/product/4516 */ #include @@ -41,44 +42,17 @@ BLEAdafruitTone bleTone; BLEAdafruitAddressablePixel blePixel; -// Circuit Playground Bluefruit -#if defined( ARDUINO_NRF52840_CIRCUITPLAY ) - #include +#if defined(ARDUINO_NRF52840_CIRCUITPLAY) +//------------- Circuit Playground Bluefruit -------------// - #define DEVICE_NAME "CPlay" - #define NEOPIXEL_COUNT 10 +#include - -#elif defined( ARDUINO_NRF52840_CLUE ) || defined( ARDUINO_NRF52840_FEATHER_SENSE ) - #include - #include - #include - - #define DEVICE_NAME "CLUE" - #define NEOPIXEL_COUNT 1 - - Adafruit_APDS9960 apds9960; - Adafruit_LSM6DS33 lsm6ds33; - Adafruit_BMP280 bmp280; -#else - - #error "Board is not supported" -#endif - -Adafruit_NeoPixel strip = Adafruit_NeoPixel(NEOPIXEL_COUNT, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800); +#define DEVICE_NAME "CPlay" +#define NEOPIXEL_COUNT 10 uint16_t measure_temperature(uint8_t* buf, uint16_t bufsize) { - float temp; - -#if defined ARDUINO_NRF52840_CIRCUITPLAY - temp = CircuitPlayground.temperature(); - -#elif defined ARDUINO_NRF52840_CLUE - temp = bmp280.readTemperature(); - -#endif - + float temp = CircuitPlayground.temperature(); memcpy(buf, &temp, 4); return 4; } @@ -87,40 +61,17 @@ uint16_t measure_accel(uint8_t* buf, uint16_t bufsize) { float* accel_buf = (float*) buf; -#if defined ARDUINO_NRF52840_CIRCUITPLAY accel_buf[0] = CircuitPlayground.motionX(); accel_buf[1] = CircuitPlayground.motionY(); accel_buf[2] = CircuitPlayground.motionZ(); -#elif defined ARDUINO_NRF52840_CLUE - - sensors_event_t accel, gyro, temp; - (void) gyro; (void) temp; - - lsm6ds33.getEvent(&accel, &gyro, &temp); - - accel_buf[0] = accel.acceleration.x; - accel_buf[1] = accel.acceleration.y; - accel_buf[2] = accel.acceleration.z; - -#endif - return 3*sizeof(float); // 12 } uint16_t measure_light_sensor(uint8_t* buf, uint16_t bufsize) { float lux; - -#if defined ARDUINO_NRF52840_CIRCUITPLAY lux = CircuitPlayground.lightSensor(); -#else - uint16_t r, g, b, c; - apds9960.getColorData(&r, &g, &b, &c); - - lux = c; -#endif - memcpy(buf, &lux, 4); return 4; } @@ -139,28 +90,102 @@ uint16_t measure_button(uint8_t* buf, uint16_t bufsize) { uint32_t button = 0; -#if defined ARDUINO_NRF52840_CIRCUITPLAY button |= ( CircuitPlayground.slideSwitch() ? 0x01 : 0x00 ); button |= ( CircuitPlayground.leftButton() ? 0x02 : 0x00 ); button |= ( CircuitPlayground.rightButton() ? 0x04 : 0x00 ); -#elif defined ARDUINO_NRF52840_CLUE - // Button is active LOW on most board except CPlay - - // No slide switch - button |= ( digitalRead(PIN_BUTTON1) ? 0x00 : 0x02 ); - button |= ( digitalRead(PIN_BUTTON2) ? 0x00 : 0x04 ); - -#endif - memcpy(buf, &button, 4); return 4; } +#elif defined(ARDUINO_NRF52840_CLUE) || defined(ARDUINO_NRF52840_FEATHER_SENSE) +//------------- CLUE & Feather Sense -------------// + +#include +#include +#include + +#if defined(ARDUINO_NRF52840_CLUE) + #define DEVICE_NAME "CLUE" +#else + #define DEVICE_NAME "Sense" +#endif + +#define NEOPIXEL_COUNT 1 + +Adafruit_APDS9960 apds9960; +Adafruit_LSM6DS33 lsm6ds33; +Adafruit_BMP280 bmp280; + +uint16_t measure_temperature(uint8_t* buf, uint16_t bufsize) +{ + float temp = bmp280.readTemperature(); + memcpy(buf, &temp, 4); + return 4; +} + +uint16_t measure_accel(uint8_t* buf, uint16_t bufsize) +{ + float* accel_buf = (float*) buf; + + sensors_event_t accel, gyro, temp; + (void) gyro; (void) temp; + + lsm6ds33.getEvent(&accel, &gyro, &temp); + + accel_buf[0] = accel.acceleration.x; + accel_buf[1] = accel.acceleration.y; + accel_buf[2] = accel.acceleration.z; + + return 3*sizeof(float); // 12 +} + +uint16_t measure_light_sensor(uint8_t* buf, uint16_t bufsize) +{ + float lux; + + uint16_t r, g, b, c; + apds9960.getColorData(&r, &g, &b, &c); + + lux = c; + + memcpy(buf, &lux, 4); + return 4; +} + +uint16_t measure_gyro(uint8_t* buf, uint16_t bufsize) +{ + +} + +uint16_t measure_magnetic(uint8_t* buf, uint16_t bufsize) +{ + +} + +uint16_t measure_button(uint8_t* buf, uint16_t bufsize) +{ + // Button is active LOW on most board except CPlay + // No slide switch + + uint32_t button = 0; + button |= ( digitalRead(PIN_BUTTON1) ? 0x00 : 0x02 ); + button |= ( digitalRead(PIN_BUTTON2) ? 0x00 : 0x04 ); + + memcpy(buf, &button, 4); + return 4; +} + +#else + #error "Board is not supported" +#endif + +Adafruit_NeoPixel strip = Adafruit_NeoPixel(NEOPIXEL_COUNT, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800); + +//------------- Setup -------------// void setup() { Serial.begin(115200); - //while ( !Serial ) delay(10); // for nrf52840 with native usb Serial.println("Bluefruit52 BLEUART Example"); Serial.println("---------------------------\n"); @@ -168,7 +193,7 @@ void setup() #if defined ARDUINO_NRF52840_CIRCUITPLAY CircuitPlayground.begin(); -#elif defined ARDUINO_NRF52840_CLUE +#else // Button pinMode(PIN_BUTTON1, INPUT_PULLUP); @@ -229,12 +254,6 @@ void setup() bleLight.begin(); bleLight.setMeasureCallback(measure_light_sensor); -// bleGyro.begin(); -// bleGyro.setMeasureCallback(measure_gyro); -// -// bleMagnetic.begin(); -// bleMagnetic.setMeasureCallback(measure_magnetic); - bleButton.begin(); bleButton.setMeasureCallback(measure_button); bleButton.setPeriod(0); // only notify if there is changes with buttons @@ -244,6 +263,15 @@ void setup() strip.begin(); blePixel.begin(&strip); + // CPB doesn't support these on-board sensor +#ifndef ARDUINO_NRF52840_CIRCUITPLAY +// bleGyro.begin(); +// bleGyro.setMeasureCallback(measure_gyro); +// +// bleMagnetic.begin(); +// bleMagnetic.setMeasureCallback(measure_magnetic); +#endif + // Set up and start advertising startAdv(); From 1da8d1c9194df301326798337155870a33c9c2e8 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 19 Feb 2020 02:22:27 +0700 Subject: [PATCH 13/21] incorrect set button period to 0, cause issue creating timer --- libraries/BLEAdafruitService/src/services/BLEAdafruitButton.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitButton.h b/libraries/BLEAdafruitService/src/services/BLEAdafruitButton.h index e9ee4de6..f0e3fa78 100644 --- a/libraries/BLEAdafruitService/src/services/BLEAdafruitButton.h +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitButton.h @@ -30,7 +30,7 @@ class BLEAdafruitButton : public BLEAdafruitSensor public: static const uint8_t UUID128_SERVICE[16]; static const uint8_t UUID128_CHR_DATA[16]; - static const int32_t DEFAULT_PERIOD = 0; + static const int32_t DEFAULT_PERIOD = 100; BLEAdafruitButton(void); virtual err_t begin(void); From 7d7cb855e52a754bec2229732bfd52e386d0e38f Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 19 Feb 2020 12:13:53 +0700 Subject: [PATCH 14/21] clean up --- .../BLEAdafruitService/src/services/BLEAdafruitAccel.h | 6 +++--- .../src/services/BLEAdafruitAddressablePixel.h | 6 +++--- .../BLEAdafruitService/src/services/BLEAdafruitButton.h | 6 +++--- libraries/BLEAdafruitService/src/services/BLEAdafruitGyro.h | 6 +++--- .../src/services/BLEAdafruitLightSensor.h | 6 +++--- .../BLEAdafruitService/src/services/BLEAdafruitMagnetic.h | 6 +++--- .../BLEAdafruitService/src/services/BLEAdafruitSensor.h | 6 +++--- .../src/services/BLEAdafruitTemperature.h | 6 +++--- libraries/BLEAdafruitService/src/services/BLEAdafruitTone.h | 6 +++--- 9 files changed, 27 insertions(+), 27 deletions(-) diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitAccel.h b/libraries/BLEAdafruitService/src/services/BLEAdafruitAccel.h index 47830aec..14087b6b 100644 --- a/libraries/BLEAdafruitService/src/services/BLEAdafruitAccel.h +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitAccel.h @@ -22,8 +22,8 @@ * THE SOFTWARE. */ -#ifndef BLEADAFRUITACCEL_H_ -#define BLEADAFRUITACCEL_H_ +#ifndef BLEADAFRUIT_ACCEL_H_ +#define BLEADAFRUIT_ACCEL_H_ class BLEAdafruitAccel : public BLEAdafruitSensor { @@ -36,4 +36,4 @@ class BLEAdafruitAccel : public BLEAdafruitSensor virtual err_t begin(void); }; -#endif /* BLEADAFRUITACCEL_H_ */ +#endif /* BLEADAFRUIT_ACCEL_H_ */ diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitAddressablePixel.h b/libraries/BLEAdafruitService/src/services/BLEAdafruitAddressablePixel.h index ec666933..7281d642 100644 --- a/libraries/BLEAdafruitService/src/services/BLEAdafruitAddressablePixel.h +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitAddressablePixel.h @@ -22,8 +22,8 @@ * THE SOFTWARE. */ -#ifndef BLEADAFRUITADDRESSABLEPIXEL_H_ -#define BLEADAFRUITADDRESSABLEPIXEL_H_ +#ifndef BLEADAFRUIT_ADDRESSABLEPIXEL_H_ +#define BLEADAFRUIT_ADDRESSABLEPIXEL_H_ #include "Adafruit_NeoPixel.h" @@ -54,4 +54,4 @@ class BLEAdafruitAddressablePixel : public BLEService -#endif /* BLEADAFRUITADDRESSABLEPIXEL_H_ */ +#endif /* BLEADAFRUIT_ADDRESSABLEPIXEL_H_ */ diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitButton.h b/libraries/BLEAdafruitService/src/services/BLEAdafruitButton.h index f0e3fa78..330ce1c8 100644 --- a/libraries/BLEAdafruitService/src/services/BLEAdafruitButton.h +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitButton.h @@ -22,8 +22,8 @@ * THE SOFTWARE. */ -#ifndef BLE_ADAFRUIT_BUTTON_H_ -#define BLE_ADAFRUIT_BUTTON_H_ +#ifndef BLEADAFRUIT_BUTTON_H_ +#define BLEADAFRUIT_BUTTON_H_ class BLEAdafruitButton : public BLEAdafruitSensor { @@ -36,4 +36,4 @@ class BLEAdafruitButton : public BLEAdafruitSensor virtual err_t begin(void); }; -#endif /* BLE_ADAFRUIT_BUTTON_H_ */ +#endif /* BLEADAFRUIT_BUTTON_H_ */ diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitGyro.h b/libraries/BLEAdafruitService/src/services/BLEAdafruitGyro.h index 29eb6063..2f4b522f 100644 --- a/libraries/BLEAdafruitService/src/services/BLEAdafruitGyro.h +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitGyro.h @@ -22,8 +22,8 @@ * THE SOFTWARE. */ -#ifndef BLEADAFRUITGYRO_H_ -#define BLEADAFRUITGYRO_H_ +#ifndef BLEADAFRUIT_GYRO_H_ +#define BLEADAFRUIT_GYRO_H_ class BLEAdafruitGyro : public BLEAdafruitSensor { @@ -36,4 +36,4 @@ class BLEAdafruitGyro : public BLEAdafruitSensor virtual err_t begin(void); }; -#endif /* BLEADAFRUITGYRO_H_ */ +#endif /* BLEADAFRUIT_GYRO_H_ */ diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitLightSensor.h b/libraries/BLEAdafruitService/src/services/BLEAdafruitLightSensor.h index a803a950..bdb901f6 100644 --- a/libraries/BLEAdafruitService/src/services/BLEAdafruitLightSensor.h +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitLightSensor.h @@ -22,8 +22,8 @@ * THE SOFTWARE. */ -#ifndef BLE_ADAFRUIT_LIGHT_SENSOR_H_ -#define BLE_ADAFRUIT_LIGHT_SENSOR_H_ +#ifndef BLEADAFRUIT_LIGHT_SENSOR_H_ +#define BLEADAFRUIT_LIGHT_SENSOR_H_ class BLEAdafruitLightSensor : public BLEAdafruitSensor { @@ -36,4 +36,4 @@ class BLEAdafruitLightSensor : public BLEAdafruitSensor virtual err_t begin(void); }; -#endif /* BLE_ADAFRUIT_LIGHT_SENSOR_H_ */ +#endif /* BLEADAFRUIT_LIGHT_SENSOR_H_ */ diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitMagnetic.h b/libraries/BLEAdafruitService/src/services/BLEAdafruitMagnetic.h index d8eddb89..fdfc7c68 100644 --- a/libraries/BLEAdafruitService/src/services/BLEAdafruitMagnetic.h +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitMagnetic.h @@ -22,8 +22,8 @@ * THE SOFTWARE. */ -#ifndef BLEADAFRUITMAGNETIC_H_ -#define BLEADAFRUITMAGNETIC_H_ +#ifndef BLEADAFRUIT_MAGNETIC_H_ +#define BLEADAFRUIT_MAGNETIC_H_ class BLEAdafruitMagnetic : public BLEAdafruitSensor { @@ -36,4 +36,4 @@ class BLEAdafruitMagnetic : public BLEAdafruitSensor virtual err_t begin(void); }; -#endif /* BLEADAFRUITMAGNETIC_H_ */ +#endif /* BLEADAFRUIT_MAGNETIC_H_ */ diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitSensor.h b/libraries/BLEAdafruitService/src/services/BLEAdafruitSensor.h index fe5c5e4f..6359b734 100644 --- a/libraries/BLEAdafruitService/src/services/BLEAdafruitSensor.h +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitSensor.h @@ -22,8 +22,8 @@ * THE SOFTWARE. */ -#ifndef BLE_ADAFRUIT_SENSOR_H_ -#define BLE_ADAFRUIT_SENSOR_H_ +#ifndef BLEADAFRUIT_SENSOR_H_ +#define BLEADAFRUIT_SENSOR_H_ class BLEAdafruitSensor : public BLEService { @@ -54,4 +54,4 @@ class BLEAdafruitSensor : public BLEService static void sensor_data_cccd_cb(uint16_t conn_hdl, BLECharacteristic* chr, uint16_t value); }; -#endif /* BLE_ADAFRUIT_SENSOR_H_ */ +#endif /* BLEADAFRUIT_SENSOR_H_ */ diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitTemperature.h b/libraries/BLEAdafruitService/src/services/BLEAdafruitTemperature.h index d4228fc0..1a61142d 100644 --- a/libraries/BLEAdafruitService/src/services/BLEAdafruitTemperature.h +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitTemperature.h @@ -22,8 +22,8 @@ * THE SOFTWARE. */ -#ifndef BLEADAFRUITTEMPERATURE_H_ -#define BLEADAFRUITTEMPERATURE_H_ +#ifndef BLEADAFRUIT_TEMPERATURE_H_ +#define BLEADAFRUIT_TEMPERATURE_H_ class BLEAdafruitTemperature : public BLEAdafruitSensor { @@ -36,4 +36,4 @@ class BLEAdafruitTemperature : public BLEAdafruitSensor virtual err_t begin(void); }; -#endif /* BLEADAFRUITTEMPERATURE_H_ */ +#endif /* BLEADAFRUIT_TEMPERATURE_H_ */ diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitTone.h b/libraries/BLEAdafruitService/src/services/BLEAdafruitTone.h index 4ea3b2a4..37dbd2d3 100644 --- a/libraries/BLEAdafruitService/src/services/BLEAdafruitTone.h +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitTone.h @@ -22,8 +22,8 @@ * THE SOFTWARE. */ -#ifndef BLEADAFRUITTONE_H_ -#define BLEADAFRUITTONE_H_ +#ifndef BLEADAFRUIT_TONE_H_ +#define BLEADAFRUIT_TONE_H_ class BLEAdafruitTone : public BLEService { @@ -41,4 +41,4 @@ class BLEAdafruitTone : public BLEService static void tone_write_cb(uint16_t conn_hdl, BLECharacteristic* chr, uint8_t* data, uint16_t len); }; -#endif /* BLEADAFRUITTONE_H_ */ +#endif /* BLEADAFRUIT_TONE_H_ */ From d5418108247001063aa414b942d7a63b4749583e Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 19 Feb 2020 12:17:57 +0700 Subject: [PATCH 15/21] add humid service --- .../src/BLEAdafruitService.h | 1 + .../src/services/BLEAdafruitHumid.cpp | 74 +++++++++++++++++++ .../src/services/BLEAdafruitHumid.h | 39 ++++++++++ 3 files changed, 114 insertions(+) create mode 100644 libraries/BLEAdafruitService/src/services/BLEAdafruitHumid.cpp create mode 100644 libraries/BLEAdafruitService/src/services/BLEAdafruitHumid.h diff --git a/libraries/BLEAdafruitService/src/BLEAdafruitService.h b/libraries/BLEAdafruitService/src/BLEAdafruitService.h index 894def7c..deee3264 100644 --- a/libraries/BLEAdafruitService/src/BLEAdafruitService.h +++ b/libraries/BLEAdafruitService/src/BLEAdafruitService.h @@ -34,6 +34,7 @@ #include "services/BLEAdafruitAddressablePixel.h" #include "services/BLEAdafruitButton.h" #include "services/BLEAdafruitGyro.h" +#include "services/BLEAdafruitHumid.h" #include "services/BLEAdafruitLightSensor.h" #include "services/BLEAdafruitMagnetic.h" #include "services/BLEAdafruitTemperature.h" diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitHumid.cpp b/libraries/BLEAdafruitService/src/services/BLEAdafruitHumid.cpp new file mode 100644 index 00000000..39e9c2a0 --- /dev/null +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitHumid.cpp @@ -0,0 +1,74 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2019 Ha Thach (tinyusb.org) for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "BLEAdafruitService.h" + +//--------------------------------------------------------------------+ +// MACRO TYPEDEF CONSTANT ENUM DECLARATION +//--------------------------------------------------------------------+ + + +/* All Adafruit Service/Characteristic UUID128 share the same Base UUID: + * ADAFxxx-C332-42A8-93BD-25E905756CB8 + * + * Shared Characteristics + * - Measurement Period 0001 | int32_t | Read + Write | + * ms between measurements, -1: stop reading, 0: update when changes + * + * Humidity service 0700 + * - Humid 0701 | float[3] | Read + Notify | x, y, z + * - Measurement Period 0001 + */ + +const uint8_t BLEAdafruitHumid::UUID128_SERVICE[16] = +{ + 0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93, + 0xA8, 0x42, 0x32, 0xC3, 0x00, 0x07, 0xAF, 0xAD +}; + +const uint8_t BLEAdafruitHumid::UUID128_CHR_DATA[16] = +{ + 0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93, + 0xA8, 0x42, 0x32, 0xC3, 0x01, 0x07, 0xAF, 0xAD +}; + +// Constructor +BLEAdafruitHumid::BLEAdafruitHumid(void) + : BLEAdafruitSensor(UUID128_SERVICE, UUID128_CHR_DATA) +{ + +} + +err_t BLEAdafruitHumid::begin (void) +{ + // Setup Measurement Characteristic + _measurement.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY); + _measurement.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS); + _measurement.setFixedLen(4); + + // Invoke base class begin(), this will add Service, Measurement and Period characteristics + VERIFY_STATUS( BLEAdafruitSensor::begin(DEFAULT_PERIOD) ); + + return ERROR_NONE; +} diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitHumid.h b/libraries/BLEAdafruitService/src/services/BLEAdafruitHumid.h new file mode 100644 index 00000000..7a9067d9 --- /dev/null +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitHumid.h @@ -0,0 +1,39 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2019 Ha Thach (tinyusb.org) for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef BLEADAFRUIT_HUMID_H_ +#define BLEADAFRUIT_HUMID_H_ + +class BLEAdafruitHumid : public BLEAdafruitSensor +{ + public: + static const uint8_t UUID128_SERVICE[16]; + static const uint8_t UUID128_CHR_DATA[16]; + static const int32_t DEFAULT_PERIOD = 1000; + + BLEAdafruitHumid(void); + virtual err_t begin(void); +}; + +#endif /* BLEADAFRUIT_HUMID_H_ */ From fe724dd302db075f7709866da3723857ad66e047 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 19 Feb 2020 14:41:30 +0700 Subject: [PATCH 16/21] added Baro SD is running out of memory due to the high number of services --- .../src/BLEAdafruitService.h | 1 + .../src/services/BLEAdafruitBaro.cpp | 74 ++++++++++++ .../src/services/BLEAdafruitBaro.h | 39 +++++++ .../bluefruit_playground.ino | 106 +++++++++++++----- 4 files changed, 190 insertions(+), 30 deletions(-) create mode 100644 libraries/BLEAdafruitService/src/services/BLEAdafruitBaro.cpp create mode 100644 libraries/BLEAdafruitService/src/services/BLEAdafruitBaro.h diff --git a/libraries/BLEAdafruitService/src/BLEAdafruitService.h b/libraries/BLEAdafruitService/src/BLEAdafruitService.h index deee3264..a2b34e58 100644 --- a/libraries/BLEAdafruitService/src/BLEAdafruitService.h +++ b/libraries/BLEAdafruitService/src/BLEAdafruitService.h @@ -32,6 +32,7 @@ #include "services/BLEAdafruitAccel.h" #include "services/BLEAdafruitAddressablePixel.h" +#include "services/BLEAdafruitBaro.h" #include "services/BLEAdafruitButton.h" #include "services/BLEAdafruitGyro.h" #include "services/BLEAdafruitHumid.h" diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitBaro.cpp b/libraries/BLEAdafruitService/src/services/BLEAdafruitBaro.cpp new file mode 100644 index 00000000..dae8a210 --- /dev/null +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitBaro.cpp @@ -0,0 +1,74 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2019 Ha Thach (tinyusb.org) for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "BLEAdafruitService.h" + +//--------------------------------------------------------------------+ +// MACRO TYPEDEF CONSTANT ENUM DECLARATION +//--------------------------------------------------------------------+ + + +/* All Adafruit Service/Characteristic UUID128 share the same Base UUID: + * ADAFxxx-C332-42A8-93BD-25E905756CB8 + * + * Shared Characteristics + * - Measurement Period 0001 | int32_t | Read + Write | + * ms between measurements, -1: stop reading, 0: update when changes + * + * Barometric service 0800 + * - Pressure 0801 | float[3] | Read + Notify | x, y, z + * - Measurement Period 0001 + */ + +const uint8_t BLEAdafruitBaro::UUID128_SERVICE[16] = +{ + 0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93, + 0xA8, 0x42, 0x32, 0xC3, 0x00, 0x08, 0xAF, 0xAD +}; + +const uint8_t BLEAdafruitBaro::UUID128_CHR_DATA[16] = +{ + 0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93, + 0xA8, 0x42, 0x32, 0xC3, 0x01, 0x08, 0xAF, 0xAD +}; + +// Constructor +BLEAdafruitBaro::BLEAdafruitBaro(void) + : BLEAdafruitSensor(UUID128_SERVICE, UUID128_CHR_DATA) +{ + +} + +err_t BLEAdafruitBaro::begin (void) +{ + // Setup Measurement Characteristic + _measurement.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY); + _measurement.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS); + _measurement.setFixedLen(4); + + // Invoke base class begin(), this will add Service, Measurement and Period characteristics + VERIFY_STATUS( BLEAdafruitSensor::begin(DEFAULT_PERIOD) ); + + return ERROR_NONE; +} diff --git a/libraries/BLEAdafruitService/src/services/BLEAdafruitBaro.h b/libraries/BLEAdafruitService/src/services/BLEAdafruitBaro.h new file mode 100644 index 00000000..8dea7266 --- /dev/null +++ b/libraries/BLEAdafruitService/src/services/BLEAdafruitBaro.h @@ -0,0 +1,39 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2019 Ha Thach (tinyusb.org) for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef BLEADAFRUIT_BARO_H_ +#define BLEADAFRUIT_BARO_H_ + +class BLEAdafruitBaro : public BLEAdafruitSensor +{ + public: + static const uint8_t UUID128_SERVICE[16]; + static const uint8_t UUID128_CHR_DATA[16]; + static const int32_t DEFAULT_PERIOD = 1000; + + BLEAdafruitBaro(void); + virtual err_t begin(void); +}; + +#endif /* BLEADAFRUIT_BARO_H_ */ diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino index 3e802b48..0bd0960b 100644 --- a/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino +++ b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino @@ -34,16 +34,13 @@ BLEBas blebas; // battery BLEAdafruitTemperature bleTemp; BLEAdafruitAccel bleAccel; BLEAdafruitLightSensor bleLight; -BLEAdafruitGyro bleGyro; -BLEAdafruitMagnetic bleMagnetic; - BLEAdafruitButton bleButton; BLEAdafruitTone bleTone; BLEAdafruitAddressablePixel blePixel; -#if defined(ARDUINO_NRF52840_CIRCUITPLAY) //------------- Circuit Playground Bluefruit -------------// +#if defined(ARDUINO_NRF52840_CIRCUITPLAY) #include @@ -68,7 +65,7 @@ uint16_t measure_accel(uint8_t* buf, uint16_t bufsize) return 3*sizeof(float); // 12 } -uint16_t measure_light_sensor(uint8_t* buf, uint16_t bufsize) +uint16_t measure_light(uint8_t* buf, uint16_t bufsize) { float lux; lux = CircuitPlayground.lightSensor(); @@ -98,12 +95,14 @@ uint16_t measure_button(uint8_t* buf, uint16_t bufsize) return 4; } -#elif defined(ARDUINO_NRF52840_CLUE) || defined(ARDUINO_NRF52840_FEATHER_SENSE) //------------- CLUE & Feather Sense -------------// +#elif defined(ARDUINO_NRF52840_CLUE) || defined(ARDUINO_NRF52840_FEATHER_SENSE) #include #include +#include #include +#include #if defined(ARDUINO_NRF52840_CLUE) #define DEVICE_NAME "CLUE" @@ -113,9 +112,17 @@ uint16_t measure_button(uint8_t* buf, uint16_t bufsize) #define NEOPIXEL_COUNT 1 -Adafruit_APDS9960 apds9960; -Adafruit_LSM6DS33 lsm6ds33; -Adafruit_BMP280 bmp280; + +BLEAdafruitGyro bleGyro; +BLEAdafruitMagnetic bleMagnetic; +BLEAdafruitHumid bleHumid; +BLEAdafruitBaro bleBaro; + +Adafruit_APDS9960 apds9960; // Proximity, Light, Gesture, Color +Adafruit_LSM6DS33 lsm6ds33; // Gyro and Accel +Adafruit_LIS3MDL lis3mdl; // Magnetometer +Adafruit_BMP280 bmp280; // Temperature, Barometric +Adafruit_SHT31 sht30; // Humid uint16_t measure_temperature(uint8_t* buf, uint16_t bufsize) { @@ -126,21 +133,21 @@ uint16_t measure_temperature(uint8_t* buf, uint16_t bufsize) uint16_t measure_accel(uint8_t* buf, uint16_t bufsize) { - float* accel_buf = (float*) buf; + float* float_buf = (float*) buf; sensors_event_t accel, gyro, temp; (void) gyro; (void) temp; lsm6ds33.getEvent(&accel, &gyro, &temp); - accel_buf[0] = accel.acceleration.x; - accel_buf[1] = accel.acceleration.y; - accel_buf[2] = accel.acceleration.z; + float_buf[0] = accel.acceleration.x; + float_buf[1] = accel.acceleration.y; + float_buf[2] = accel.acceleration.z; - return 3*sizeof(float); // 12 + return 12; } -uint16_t measure_light_sensor(uint8_t* buf, uint16_t bufsize) +uint16_t measure_light(uint8_t* buf, uint16_t bufsize) { float lux; @@ -155,12 +162,32 @@ uint16_t measure_light_sensor(uint8_t* buf, uint16_t bufsize) uint16_t measure_gyro(uint8_t* buf, uint16_t bufsize) { + float* float_buf = (float*) buf; + sensors_event_t accel, gyro, temp; + (void) accel; (void) temp; + + lsm6ds33.getEvent(&accel, &gyro, &temp); + + float_buf[0] = gyro.gyro.x; + float_buf[1] = gyro.gyro.y; + float_buf[2] = gyro.gyro.z; + + return 12; } uint16_t measure_magnetic(uint8_t* buf, uint16_t bufsize) { + float* float_buf = (float*) buf; + sensors_event_t mag; + lis3mdl.getEvent(&mag); + + float_buf[0] = mag.magnetic.x; + float_buf[1] = mag.magnetic.y; + float_buf[2] = mag.magnetic.z; + + return 12; } uint16_t measure_button(uint8_t* buf, uint16_t bufsize) @@ -176,6 +203,20 @@ uint16_t measure_button(uint8_t* buf, uint16_t bufsize) return 4; } +uint16_t measure_humid(uint8_t* buf, uint16_t bufsize) +{ + float humid = sht30.readHumidity(); + memcpy(buf, &humid, 4); + return 4; +} + +uint16_t measure_baro(uint8_t* buf, uint16_t bufsize) +{ + float baro = bmp280.readPressure()/100; + memcpy(buf, &baro, 4); + return 4; +} + #else #error "Board is not supported" #endif @@ -185,11 +226,6 @@ Adafruit_NeoPixel strip = Adafruit_NeoPixel(NEOPIXEL_COUNT, PIN_NEOPIXEL, NEO_GR //------------- Setup -------------// void setup() { - Serial.begin(115200); - - Serial.println("Bluefruit52 BLEUART Example"); - Serial.println("---------------------------\n"); - #if defined ARDUINO_NRF52840_CIRCUITPLAY CircuitPlayground.begin(); @@ -202,17 +238,21 @@ void setup() // Buzzer Speaker pinMode(PIN_BUZZER, OUTPUT); - // Light sensor apds9960.begin(); apds9960.enableColor(true); - // Accelerometer lsm6ds33.begin_I2C(); - - // Pressure + Temperature bmp280.begin(); + lis3mdl.begin_I2C(); + sht30.begin(0x44); #endif + Serial.begin(115200); + while(!Serial) delay(10); // wait for native USB + + Serial.println("Bluefruit Playground Example"); + Serial.println("---------------------------\n"); + // Setup the BLE LED to be enabled on CONNECT // Note: This is actually the default behaviour, but provided // here in case you want to control this LED manually via PIN 19 @@ -252,7 +292,7 @@ void setup() bleAccel.setMeasureCallback(measure_accel); bleLight.begin(); - bleLight.setMeasureCallback(measure_light_sensor); + bleLight.setMeasureCallback(measure_light); bleButton.begin(); bleButton.setMeasureCallback(measure_button); @@ -265,11 +305,17 @@ void setup() // CPB doesn't support these on-board sensor #ifndef ARDUINO_NRF52840_CIRCUITPLAY -// bleGyro.begin(); -// bleGyro.setMeasureCallback(measure_gyro); -// -// bleMagnetic.begin(); -// bleMagnetic.setMeasureCallback(measure_magnetic); + bleGyro.begin(); + bleGyro.setMeasureCallback(measure_gyro); + + bleMagnetic.begin(); + bleMagnetic.setMeasureCallback(measure_magnetic); + + bleHumid.begin(); + bleHumid.setMeasureCallback(measure_humid); + + bleBaro.begin(); + bleBaro.setMeasureCallback(measure_baro); #endif // Set up and start advertising From 9329328befa780b4e8e324c863757ec53314a661 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 19 Feb 2020 14:52:35 +0700 Subject: [PATCH 17/21] increase attr table size for 840 to from 0xC00 to 0x1000 --- libraries/Bluefruit52Lib/src/bluefruit.cpp | 10 +--------- libraries/Bluefruit52Lib/src/bluefruit.h | 7 ++++++- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/libraries/Bluefruit52Lib/src/bluefruit.cpp b/libraries/Bluefruit52Lib/src/bluefruit.cpp index d17f66e4..13afc4bc 100644 --- a/libraries/Bluefruit52Lib/src/bluefruit.cpp +++ b/libraries/Bluefruit52Lib/src/bluefruit.cpp @@ -122,10 +122,7 @@ static void nrf_error_cb(uint32_t id, uint32_t pc, uint32_t info) LOG_LV1("SD Err", "assert at %s : %d", assert_info->p_file_name, assert_info->line_num); } - while(1) - { - yield(); - } + while(1) yield(); #endif } @@ -189,11 +186,6 @@ AdafruitBluefruit::AdafruitBluefruit(void) .kdist_own = { .enc = 1, .id = 1}, .kdist_peer = { .enc = 1, .id = 1}, }); - -COMMENT_OUT( - _auth_type = BLE_GAP_AUTH_KEY_TYPE_NONE; - varclr(_pin); -) } void AdafruitBluefruit::configServiceChanged(bool changed) diff --git a/libraries/Bluefruit52Lib/src/bluefruit.h b/libraries/Bluefruit52Lib/src/bluefruit.h index 94d18dcc..521dea5c 100644 --- a/libraries/Bluefruit52Lib/src/bluefruit.h +++ b/libraries/Bluefruit52Lib/src/bluefruit.h @@ -36,7 +36,12 @@ #define BLE_GATT_ATT_MTU_MAX 247 #define BLE_MAX_CONNECTION 20 // SD support up to 20 connections -#define CFG_SD_ATTR_TABLE_SIZE 0xC00 +// Allocate more memory for GATT table for 840 +#ifdef NRF52840_XXAA + #define CFG_SD_ATTR_TABLE_SIZE 0x1000 +#else + #define CFG_SD_ATTR_TABLE_SIZE 0xC00 +#endif #include "BLEUuid.h" #include "BLEAdvertising.h" From 05dd24c2324379bce0e45492e593fff791b14fb8 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 19 Feb 2020 15:23:41 +0700 Subject: [PATCH 18/21] clean up --- .../Peripheral/bluefruit_playground/bluefruit_playground.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino index 0bd0960b..3b99709b 100644 --- a/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino +++ b/libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino @@ -248,7 +248,7 @@ void setup() #endif Serial.begin(115200); - while(!Serial) delay(10); // wait for native USB +// while(!Serial) delay(10); // wait for native USB Serial.println("Bluefruit Playground Example"); Serial.println("---------------------------\n"); From 28fe0ac7fe5c191af042f5b11e509c729e0b3060 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 19 Feb 2020 15:56:06 +0700 Subject: [PATCH 19/21] add clue support to image_upload example --- .../Peripheral/image_upload/image_upload.ino | 99 +++++++++++-------- 1 file changed, 56 insertions(+), 43 deletions(-) diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/image_upload/image_upload.ino b/libraries/Bluefruit52Lib/examples/Peripheral/image_upload/image_upload.ino index 2a62056f..2aea5e09 100644 --- a/libraries/Bluefruit52Lib/examples/Peripheral/image_upload/image_upload.ino +++ b/libraries/Bluefruit52Lib/examples/Peripheral/image_upload/image_upload.ino @@ -18,53 +18,55 @@ /* This sketch demonstrates the "Image Upload" feature of Bluefruit Mobile App. * Following TFT Display are supported - * - https://www.adafruit.com/product/3315 - * - https://www.adafruit.com/product/3651 - * - https://www.adafruit.com/product/4367 + * - TFT 3.5" : FeatherWing https://www.adafruit.com/product/3651 + * - TFT 2.4" : FeatherWing https://www.adafruit.com/product/3315 + * - TFT Gizmo : https://www.adafruit.com/product/4367 + * - Adafruit CLUE : https://www.adafruit.com/product/4500 */ -#define TFT_35_FEATHERWING 1 -#define TFT_24_FEATHERWING 2 -#define TFT_GIZMO 3 -// [Configurable] Please select one of above supported Display to match your hardware setup -#define TFT_IN_USE TFT_35_FEATHERWING - - -#if defined(ARDUINO_NRF52832_FEATHER) - // Feather nRF52832 - #define TFT_DC 11 - #define TFT_CS 31 - -#elif defined(ARDUINO_NRF52840_CIRCUITPLAY) - // Circuit Playground Bluefruit for use with TFT 1.5" GIZMO - #define TFT_DC 1 - #define TFT_CS 0 +#if defined(ARDUINO_NRF52840_CIRCUITPLAY) + // Circuit Playground Bluefruit use with TFT GIZMO #define TFT_BACKLIGHT A3 -#else - // Default for others - #define TFT_DC 10 - #define TFT_CS 9 -#endif - - -#if TFT_IN_USE == TFT_35_FEATHERWING - #include "Adafruit_HX8357.h" - Adafruit_HX8357 tft = Adafruit_HX8357(TFT_CS, TFT_DC); - -#elif TFT_IN_USE == TFT_24_FEATHERWING - #include - Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC); - -#elif TFT_IN_USE == TFT_GIZMO #include "Adafruit_ST7789.h" - Adafruit_ST7789 tft = Adafruit_ST7789(&SPI, TFT_CS, TFT_DC, -1); - -#else - #error "TFT display is not supported" -#endif + Adafruit_ST7789 tft = Adafruit_ST7789(&SPI, 0, 1, -1); // CS = 0, DC = 1 +#elif defined(ARDUINO_NRF52840_CLUE) + // CLUE use on-board TFT + #include "Adafruit_ST7789.h" + Adafruit_ST7789 tft = Adafruit_ST7789(&SPI1, 31, 32, 33); // CS = 31, DC = 32, RST = 33 + +#else + #define TFT_35_FEATHERWING 1 + #define TFT_24_FEATHERWING 2 + + // [Configurable] For other boards please select which external display to match your hardware setup + #define TFT_IN_USE TFT_35_FEATHERWING + + #if defined(ARDUINO_NRF52832_FEATHER) + // Feather nRF52832 pin map is different from others + #define TFT_DC 11 + #define TFT_CS 31 + #else + // Default for others + #define TFT_DC 10 + #define TFT_CS 9 + #endif // 832 + + #if TFT_IN_USE == TFT_35_FEATHERWING + #include "Adafruit_HX8357.h" + Adafruit_HX8357 tft = Adafruit_HX8357(TFT_CS, TFT_DC); + #elif TFT_IN_USE == TFT_24_FEATHERWING + #include + Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC); + #else + #error "TFT display is not supported" + #endif // TFT + +#endif // board variants + +// Universal color #define COLOR_WHITE 0xFFFF #define COLOR_BLACK 0x0000 #define COLOR_YELLOW 0xFFE0 @@ -110,11 +112,22 @@ void setup() { Serial.begin(115200); -#if TFT_IN_USE == TFT_GIZMO +#if defined(ARDUINO_NRF52840_CIRCUITPLAY) tft.init(240, 240); tft.setRotation(2); - pinMode(TFT_BACKLIGHT, OUTPUT); - digitalWrite(TFT_BACKLIGHT, HIGH); // Backlight on + + // turn backlight on + uint8_t backlight = A3; + pinMode(backlight, OUTPUT); + digitalWrite(backlight, HIGH); + +#elif defined(ARDUINO_NRF52840_CLUE) + tft.init(240, 240); + tft.setRotation(1); + + // Screen refresh rate control (datasheet 9.2.18, FRCTRL2) + uint8_t rtna = 0x01; + tft.sendCommand(0xC6, &rtna, 1);; #else tft.begin(); From a4ca3807be34296f1c5072d65aacc3ae381ed340 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 19 Feb 2020 15:56:42 +0700 Subject: [PATCH 20/21] clean up --- .../examples/Peripheral/image_upload/image_upload.ino | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/image_upload/image_upload.ino b/libraries/Bluefruit52Lib/examples/Peripheral/image_upload/image_upload.ino index 2aea5e09..b6905922 100644 --- a/libraries/Bluefruit52Lib/examples/Peripheral/image_upload/image_upload.ino +++ b/libraries/Bluefruit52Lib/examples/Peripheral/image_upload/image_upload.ino @@ -24,7 +24,6 @@ * - Adafruit CLUE : https://www.adafruit.com/product/4500 */ - #if defined(ARDUINO_NRF52840_CIRCUITPLAY) // Circuit Playground Bluefruit use with TFT GIZMO #define TFT_BACKLIGHT A3 From a6a7bcdf804dde7a1bd338926e12dd7a3b2e618b Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 19 Feb 2020 16:26:26 +0700 Subject: [PATCH 21/21] install dependency Adafruit_ST7789 --- .github/workflows/githubci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/githubci.yml b/.github/workflows/githubci.yml index 4816c2be..497a5e81 100644 --- a/.github/workflows/githubci.yml +++ b/.github/workflows/githubci.yml @@ -52,7 +52,7 @@ jobs: rm -r $HOME/$BSP_PATH/* ln -s $GITHUB_WORKSPACE $HOME/$BSP_PATH/$BSP_VERSION # Install library dependency - arduino-cli lib install "Adafruit GFX Library" "Adafruit SSD1306" "Adafruit ILI9341" "Adafruit HX8357 Library" "Adafruit EPD" + arduino-cli lib install "Adafruit GFX Library" "Adafruit SSD1306" "Adafruit ILI9341" "Adafruit HX8357 Library" "Adafruit ST7735 and ST7789 Library" "Adafruit EPD" arduino-cli lib install "Adafruit Circuit Playground" "Adafruit NeoPixel" "Adafruit NeoMatrix" "MIDI Library" "Firmata" - name: Build examples