@@ -34,16 +34,13 @@ BLEBas blebas; // battery
3434BLEAdafruitTemperature bleTemp;
3535BLEAdafruitAccel bleAccel;
3636BLEAdafruitLightSensor bleLight;
37- BLEAdafruitGyro bleGyro;
38- BLEAdafruitMagnetic bleMagnetic;
39-
4037BLEAdafruitButton bleButton;
4138BLEAdafruitTone bleTone;
4239
4340BLEAdafruitAddressablePixel 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
120127uint16_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
127134uint16_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
156163uint16_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
161179uint16_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
166193uint16_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 -------------//
186227void 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