Skip to content

Commit fe724dd

Browse files
committed
added Baro
SD is running out of memory due to the high number of services
1 parent d541810 commit fe724dd

File tree

4 files changed

+190
-30
lines changed

4 files changed

+190
-30
lines changed

libraries/BLEAdafruitService/src/BLEAdafruitService.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#include "services/BLEAdafruitAccel.h"
3434
#include "services/BLEAdafruitAddressablePixel.h"
35+
#include "services/BLEAdafruitBaro.h"
3536
#include "services/BLEAdafruitButton.h"
3637
#include "services/BLEAdafruitGyro.h"
3738
#include "services/BLEAdafruitHumid.h"
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2019 Ha Thach (tinyusb.org) for Adafruit Industries
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
#include "BLEAdafruitService.h"
26+
27+
//--------------------------------------------------------------------+
28+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
29+
//--------------------------------------------------------------------+
30+
31+
32+
/* All Adafruit Service/Characteristic UUID128 share the same Base UUID:
33+
* ADAFxxx-C332-42A8-93BD-25E905756CB8
34+
*
35+
* Shared Characteristics
36+
* - Measurement Period 0001 | int32_t | Read + Write |
37+
* ms between measurements, -1: stop reading, 0: update when changes
38+
*
39+
* Barometric service 0800
40+
* - Pressure 0801 | float[3] | Read + Notify | x, y, z
41+
* - Measurement Period 0001
42+
*/
43+
44+
const uint8_t BLEAdafruitBaro::UUID128_SERVICE[16] =
45+
{
46+
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
47+
0xA8, 0x42, 0x32, 0xC3, 0x00, 0x08, 0xAF, 0xAD
48+
};
49+
50+
const uint8_t BLEAdafruitBaro::UUID128_CHR_DATA[16] =
51+
{
52+
0xB8, 0x6c, 0x75, 0x05, 0xE9, 0x25, 0xBD, 0x93,
53+
0xA8, 0x42, 0x32, 0xC3, 0x01, 0x08, 0xAF, 0xAD
54+
};
55+
56+
// Constructor
57+
BLEAdafruitBaro::BLEAdafruitBaro(void)
58+
: BLEAdafruitSensor(UUID128_SERVICE, UUID128_CHR_DATA)
59+
{
60+
61+
}
62+
63+
err_t BLEAdafruitBaro::begin (void)
64+
{
65+
// Setup Measurement Characteristic
66+
_measurement.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY);
67+
_measurement.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
68+
_measurement.setFixedLen(4);
69+
70+
// Invoke base class begin(), this will add Service, Measurement and Period characteristics
71+
VERIFY_STATUS( BLEAdafruitSensor::begin(DEFAULT_PERIOD) );
72+
73+
return ERROR_NONE;
74+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2019 Ha Thach (tinyusb.org) for Adafruit Industries
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
#ifndef BLEADAFRUIT_BARO_H_
26+
#define BLEADAFRUIT_BARO_H_
27+
28+
class BLEAdafruitBaro : public BLEAdafruitSensor
29+
{
30+
public:
31+
static const uint8_t UUID128_SERVICE[16];
32+
static const uint8_t UUID128_CHR_DATA[16];
33+
static const int32_t DEFAULT_PERIOD = 1000;
34+
35+
BLEAdafruitBaro(void);
36+
virtual err_t begin(void);
37+
};
38+
39+
#endif /* BLEADAFRUIT_BARO_H_ */

libraries/Bluefruit52Lib/examples/Peripheral/bluefruit_playground/bluefruit_playground.ino

Lines changed: 76 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,13 @@ BLEBas blebas; // battery
3434
BLEAdafruitTemperature bleTemp;
3535
BLEAdafruitAccel bleAccel;
3636
BLEAdafruitLightSensor bleLight;
37-
BLEAdafruitGyro bleGyro;
38-
BLEAdafruitMagnetic bleMagnetic;
39-
4037
BLEAdafruitButton bleButton;
4138
BLEAdafruitTone bleTone;
4239

4340
BLEAdafruitAddressablePixel blePixel;
4441

45-
#if defined(ARDUINO_NRF52840_CIRCUITPLAY)
4642
//------------- Circuit Playground Bluefruit -------------//
43+
#if defined(ARDUINO_NRF52840_CIRCUITPLAY)
4744

4845
#include <Adafruit_CircuitPlayground.h>
4946

@@ -68,7 +65,7 @@ uint16_t measure_accel(uint8_t* buf, uint16_t bufsize)
6865
return 3*sizeof(float); // 12
6966
}
7067

71-
uint16_t measure_light_sensor(uint8_t* buf, uint16_t bufsize)
68+
uint16_t measure_light(uint8_t* buf, uint16_t bufsize)
7269
{
7370
float lux;
7471
lux = CircuitPlayground.lightSensor();
@@ -98,12 +95,14 @@ uint16_t measure_button(uint8_t* buf, uint16_t bufsize)
9895
return 4;
9996
}
10097

101-
#elif defined(ARDUINO_NRF52840_CLUE) || defined(ARDUINO_NRF52840_FEATHER_SENSE)
10298
//------------- CLUE & Feather Sense -------------//
99+
#elif defined(ARDUINO_NRF52840_CLUE) || defined(ARDUINO_NRF52840_FEATHER_SENSE)
103100

104101
#include <Adafruit_APDS9960.h>
105102
#include <Adafruit_LSM6DS33.h>
103+
#include <Adafruit_LIS3MDL.h>
106104
#include <Adafruit_BMP280.h>
105+
#include <Adafruit_SHT31.h>
107106

108107
#if defined(ARDUINO_NRF52840_CLUE)
109108
#define DEVICE_NAME "CLUE"
@@ -113,9 +112,17 @@ uint16_t measure_button(uint8_t* buf, uint16_t bufsize)
113112

114113
#define NEOPIXEL_COUNT 1
115114

116-
Adafruit_APDS9960 apds9960;
117-
Adafruit_LSM6DS33 lsm6ds33;
118-
Adafruit_BMP280 bmp280;
115+
116+
BLEAdafruitGyro bleGyro;
117+
BLEAdafruitMagnetic bleMagnetic;
118+
BLEAdafruitHumid bleHumid;
119+
BLEAdafruitBaro bleBaro;
120+
121+
Adafruit_APDS9960 apds9960; // Proximity, Light, Gesture, Color
122+
Adafruit_LSM6DS33 lsm6ds33; // Gyro and Accel
123+
Adafruit_LIS3MDL lis3mdl; // Magnetometer
124+
Adafruit_BMP280 bmp280; // Temperature, Barometric
125+
Adafruit_SHT31 sht30; // Humid
119126

120127
uint16_t measure_temperature(uint8_t* buf, uint16_t bufsize)
121128
{
@@ -126,21 +133,21 @@ uint16_t measure_temperature(uint8_t* buf, uint16_t bufsize)
126133

127134
uint16_t measure_accel(uint8_t* buf, uint16_t bufsize)
128135
{
129-
float* accel_buf = (float*) buf;
136+
float* float_buf = (float*) buf;
130137

131138
sensors_event_t accel, gyro, temp;
132139
(void) gyro; (void) temp;
133140

134141
lsm6ds33.getEvent(&accel, &gyro, &temp);
135142

136-
accel_buf[0] = accel.acceleration.x;
137-
accel_buf[1] = accel.acceleration.y;
138-
accel_buf[2] = accel.acceleration.z;
143+
float_buf[0] = accel.acceleration.x;
144+
float_buf[1] = accel.acceleration.y;
145+
float_buf[2] = accel.acceleration.z;
139146

140-
return 3*sizeof(float); // 12
147+
return 12;
141148
}
142149

143-
uint16_t measure_light_sensor(uint8_t* buf, uint16_t bufsize)
150+
uint16_t measure_light(uint8_t* buf, uint16_t bufsize)
144151
{
145152
float lux;
146153

@@ -155,12 +162,32 @@ uint16_t measure_light_sensor(uint8_t* buf, uint16_t bufsize)
155162

156163
uint16_t measure_gyro(uint8_t* buf, uint16_t bufsize)
157164
{
165+
float* float_buf = (float*) buf;
158166

167+
sensors_event_t accel, gyro, temp;
168+
(void) accel; (void) temp;
169+
170+
lsm6ds33.getEvent(&accel, &gyro, &temp);
171+
172+
float_buf[0] = gyro.gyro.x;
173+
float_buf[1] = gyro.gyro.y;
174+
float_buf[2] = gyro.gyro.z;
175+
176+
return 12;
159177
}
160178

161179
uint16_t measure_magnetic(uint8_t* buf, uint16_t bufsize)
162180
{
181+
float* float_buf = (float*) buf;
163182

183+
sensors_event_t mag;
184+
lis3mdl.getEvent(&mag);
185+
186+
float_buf[0] = mag.magnetic.x;
187+
float_buf[1] = mag.magnetic.y;
188+
float_buf[2] = mag.magnetic.z;
189+
190+
return 12;
164191
}
165192

166193
uint16_t measure_button(uint8_t* buf, uint16_t bufsize)
@@ -176,6 +203,20 @@ uint16_t measure_button(uint8_t* buf, uint16_t bufsize)
176203
return 4;
177204
}
178205

206+
uint16_t measure_humid(uint8_t* buf, uint16_t bufsize)
207+
{
208+
float humid = sht30.readHumidity();
209+
memcpy(buf, &humid, 4);
210+
return 4;
211+
}
212+
213+
uint16_t measure_baro(uint8_t* buf, uint16_t bufsize)
214+
{
215+
float baro = bmp280.readPressure()/100;
216+
memcpy(buf, &baro, 4);
217+
return 4;
218+
}
219+
179220
#else
180221
#error "Board is not supported"
181222
#endif
@@ -185,11 +226,6 @@ Adafruit_NeoPixel strip = Adafruit_NeoPixel(NEOPIXEL_COUNT, PIN_NEOPIXEL, NEO_GR
185226
//------------- Setup -------------//
186227
void setup()
187228
{
188-
Serial.begin(115200);
189-
190-
Serial.println("Bluefruit52 BLEUART Example");
191-
Serial.println("---------------------------\n");
192-
193229
#if defined ARDUINO_NRF52840_CIRCUITPLAY
194230
CircuitPlayground.begin();
195231

@@ -202,17 +238,21 @@ void setup()
202238
// Buzzer Speaker
203239
pinMode(PIN_BUZZER, OUTPUT);
204240

205-
// Light sensor
206241
apds9960.begin();
207242
apds9960.enableColor(true);
208243

209-
// Accelerometer
210244
lsm6ds33.begin_I2C();
211-
212-
// Pressure + Temperature
213245
bmp280.begin();
246+
lis3mdl.begin_I2C();
247+
sht30.begin(0x44);
214248
#endif
215249

250+
Serial.begin(115200);
251+
while(!Serial) delay(10); // wait for native USB
252+
253+
Serial.println("Bluefruit Playground Example");
254+
Serial.println("---------------------------\n");
255+
216256
// Setup the BLE LED to be enabled on CONNECT
217257
// Note: This is actually the default behaviour, but provided
218258
// here in case you want to control this LED manually via PIN 19
@@ -252,7 +292,7 @@ void setup()
252292
bleAccel.setMeasureCallback(measure_accel);
253293

254294
bleLight.begin();
255-
bleLight.setMeasureCallback(measure_light_sensor);
295+
bleLight.setMeasureCallback(measure_light);
256296

257297
bleButton.begin();
258298
bleButton.setMeasureCallback(measure_button);
@@ -265,11 +305,17 @@ void setup()
265305

266306
// CPB doesn't support these on-board sensor
267307
#ifndef ARDUINO_NRF52840_CIRCUITPLAY
268-
// bleGyro.begin();
269-
// bleGyro.setMeasureCallback(measure_gyro);
270-
//
271-
// bleMagnetic.begin();
272-
// bleMagnetic.setMeasureCallback(measure_magnetic);
308+
bleGyro.begin();
309+
bleGyro.setMeasureCallback(measure_gyro);
310+
311+
bleMagnetic.begin();
312+
bleMagnetic.setMeasureCallback(measure_magnetic);
313+
314+
bleHumid.begin();
315+
bleHumid.setMeasureCallback(measure_humid);
316+
317+
bleBaro.begin();
318+
bleBaro.setMeasureCallback(measure_baro);
273319
#endif
274320

275321
// Set up and start advertising

0 commit comments

Comments
 (0)