@@ -34,16 +34,13 @@ BLEBas blebas; // battery
34
34
BLEAdafruitTemperature bleTemp;
35
35
BLEAdafruitAccel bleAccel;
36
36
BLEAdafruitLightSensor bleLight;
37
- BLEAdafruitGyro bleGyro;
38
- BLEAdafruitMagnetic bleMagnetic;
39
-
40
37
BLEAdafruitButton bleButton;
41
38
BLEAdafruitTone bleTone;
42
39
43
40
BLEAdafruitAddressablePixel blePixel;
44
41
45
- #if defined(ARDUINO_NRF52840_CIRCUITPLAY)
46
42
// ------------- Circuit Playground Bluefruit -------------//
43
+ #if defined(ARDUINO_NRF52840_CIRCUITPLAY)
47
44
48
45
#include < Adafruit_CircuitPlayground.h>
49
46
@@ -68,7 +65,7 @@ uint16_t measure_accel(uint8_t* buf, uint16_t bufsize)
68
65
return 3 *sizeof (float ); // 12
69
66
}
70
67
71
- uint16_t measure_light_sensor (uint8_t * buf, uint16_t bufsize)
68
+ uint16_t measure_light (uint8_t * buf, uint16_t bufsize)
72
69
{
73
70
float lux;
74
71
lux = CircuitPlayground.lightSensor ();
@@ -98,12 +95,14 @@ uint16_t measure_button(uint8_t* buf, uint16_t bufsize)
98
95
return 4 ;
99
96
}
100
97
101
- #elif defined(ARDUINO_NRF52840_CLUE) || defined(ARDUINO_NRF52840_FEATHER_SENSE)
102
98
// ------------- CLUE & Feather Sense -------------//
99
+ #elif defined(ARDUINO_NRF52840_CLUE) || defined(ARDUINO_NRF52840_FEATHER_SENSE)
103
100
104
101
#include < Adafruit_APDS9960.h>
105
102
#include < Adafruit_LSM6DS33.h>
103
+ #include < Adafruit_LIS3MDL.h>
106
104
#include < Adafruit_BMP280.h>
105
+ #include < Adafruit_SHT31.h>
107
106
108
107
#if defined(ARDUINO_NRF52840_CLUE)
109
108
#define DEVICE_NAME " CLUE"
@@ -113,9 +112,17 @@ uint16_t measure_button(uint8_t* buf, uint16_t bufsize)
113
112
114
113
#define NEOPIXEL_COUNT 1
115
114
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
119
126
120
127
uint16_t measure_temperature (uint8_t * buf, uint16_t bufsize)
121
128
{
@@ -126,21 +133,21 @@ uint16_t measure_temperature(uint8_t* buf, uint16_t bufsize)
126
133
127
134
uint16_t measure_accel (uint8_t * buf, uint16_t bufsize)
128
135
{
129
- float * accel_buf = (float *) buf;
136
+ float * float_buf = (float *) buf;
130
137
131
138
sensors_event_t accel, gyro, temp;
132
139
(void ) gyro; (void ) temp;
133
140
134
141
lsm6ds33.getEvent (&accel, &gyro, &temp);
135
142
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 ;
139
146
140
- return 3 * sizeof ( float ); // 12
147
+ return 12 ;
141
148
}
142
149
143
- uint16_t measure_light_sensor (uint8_t * buf, uint16_t bufsize)
150
+ uint16_t measure_light (uint8_t * buf, uint16_t bufsize)
144
151
{
145
152
float lux;
146
153
@@ -155,12 +162,32 @@ uint16_t measure_light_sensor(uint8_t* buf, uint16_t bufsize)
155
162
156
163
uint16_t measure_gyro (uint8_t * buf, uint16_t bufsize)
157
164
{
165
+ float * float_buf = (float *) buf;
158
166
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 ;
159
177
}
160
178
161
179
uint16_t measure_magnetic (uint8_t * buf, uint16_t bufsize)
162
180
{
181
+ float * float_buf = (float *) buf;
163
182
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 ;
164
191
}
165
192
166
193
uint16_t measure_button (uint8_t * buf, uint16_t bufsize)
@@ -176,6 +203,20 @@ uint16_t measure_button(uint8_t* buf, uint16_t bufsize)
176
203
return 4 ;
177
204
}
178
205
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
+
179
220
#else
180
221
#error "Board is not supported"
181
222
#endif
@@ -185,11 +226,6 @@ Adafruit_NeoPixel strip = Adafruit_NeoPixel(NEOPIXEL_COUNT, PIN_NEOPIXEL, NEO_GR
185
226
// ------------- Setup -------------//
186
227
void setup ()
187
228
{
188
- Serial.begin (115200 );
189
-
190
- Serial.println (" Bluefruit52 BLEUART Example" );
191
- Serial.println (" ---------------------------\n " );
192
-
193
229
#if defined ARDUINO_NRF52840_CIRCUITPLAY
194
230
CircuitPlayground.begin ();
195
231
@@ -202,17 +238,21 @@ void setup()
202
238
// Buzzer Speaker
203
239
pinMode (PIN_BUZZER, OUTPUT);
204
240
205
- // Light sensor
206
241
apds9960.begin ();
207
242
apds9960.enableColor (true );
208
243
209
- // Accelerometer
210
244
lsm6ds33.begin_I2C ();
211
-
212
- // Pressure + Temperature
213
245
bmp280.begin ();
246
+ lis3mdl.begin_I2C ();
247
+ sht30.begin (0x44 );
214
248
#endif
215
249
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
+
216
256
// Setup the BLE LED to be enabled on CONNECT
217
257
// Note: This is actually the default behaviour, but provided
218
258
// here in case you want to control this LED manually via PIN 19
@@ -252,7 +292,7 @@ void setup()
252
292
bleAccel.setMeasureCallback (measure_accel);
253
293
254
294
bleLight.begin ();
255
- bleLight.setMeasureCallback (measure_light_sensor );
295
+ bleLight.setMeasureCallback (measure_light );
256
296
257
297
bleButton.begin ();
258
298
bleButton.setMeasureCallback (measure_button);
@@ -265,11 +305,17 @@ void setup()
265
305
266
306
// CPB doesn't support these on-board sensor
267
307
#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);
273
319
#endif
274
320
275
321
// Set up and start advertising
0 commit comments