66#include < Adafruit_BMP280.h>
77#include < Adafruit_LIS3MDL.h>
88#include < Adafruit_LSM6DS33.h>
9+ #include < Adafruit_LSM6DS3TRC.h>
910#include < Adafruit_SHT31.h>
1011#include < Adafruit_Sensor.h>
1112#include < PDM.h>
1213
1314Adafruit_APDS9960 apds9960; // proximity, light, color, gesture
1415Adafruit_BMP280 bmp280; // temperautre, barometric pressure
1516Adafruit_LIS3MDL lis3mdl; // magnetometer
16- Adafruit_LSM6DS33 lsm6ds33; // accelerometer, gyroscope
17+ Adafruit_LSM6DS3TRC lsm6ds3trc; // accelerometer, gyroscope
18+ Adafruit_LSM6DS33 lsm6ds33;
1719Adafruit_SHT31 sht30; // humidity
1820
1921uint8_t proximity;
@@ -24,11 +26,15 @@ float accel_x, accel_y, accel_z;
2426float gyro_x, gyro_y, gyro_z;
2527float humidity;
2628int32_t mic;
29+ long int accel_array[6 ];
30+ long int check_array[6 ]={0.00 , 0.00 , 0.00 , 0.00 , 0.00 , 0.00 };
2731
2832extern PDMClass PDM;
2933short sampleBuffer[256 ]; // buffer to read samples into, each sample is 16-bits
3034volatile int samplesRead; // number of samples read
3135
36+ bool new_rev = true ;
37+
3238void setup (void ) {
3339 Serial.begin (115200 );
3440 // while (!Serial) delay(10);
@@ -41,6 +47,28 @@ void setup(void) {
4147 bmp280.begin ();
4248 lis3mdl.begin_I2C ();
4349 lsm6ds33.begin_I2C ();
50+ // check for readings from LSM6DS33
51+ sensors_event_t accel;
52+ sensors_event_t gyro;
53+ sensors_event_t temp;
54+ lsm6ds33.getEvent (&accel, &gyro, &temp);
55+ accel_array[0 ] = accel.acceleration .x ;
56+ accel_array[1 ] = accel.acceleration .y ;
57+ accel_array[2 ] = accel.acceleration .z ;
58+ accel_array[3 ] = gyro.gyro .x ;
59+ accel_array[4 ] = gyro.gyro .y ;
60+ accel_array[5 ] = gyro.gyro .z ;
61+ // if all readings are empty, then new rev
62+ for (int i =0 ; i < 5 ; i++) {
63+ if (accel_array[i] != check_array[i]) {
64+ new_rev = false ;
65+ break ;
66+ }
67+ }
68+ // and we need to instantiate the LSM6DS3TRC
69+ if (new_rev) {
70+ lsm6ds3trc.begin_I2C ();
71+ }
4472 sht30.begin ();
4573 PDM.onReceive (onPDMdata);
4674 PDM.begin (1 , 16000 );
@@ -65,7 +93,12 @@ void loop(void) {
6593 sensors_event_t accel;
6694 sensors_event_t gyro;
6795 sensors_event_t temp;
68- lsm6ds33.getEvent (&accel, &gyro, &temp);
96+ if (new_rev) {
97+ lsm6ds3trc.getEvent (&accel, &gyro, &temp);
98+ }
99+ else {
100+ lsm6ds33.getEvent (&accel, &gyro, &temp);
101+ }
69102 accel_x = accel.acceleration .x ;
70103 accel_y = accel.acceleration .y ;
71104 accel_z = accel.acceleration .z ;
@@ -77,7 +110,7 @@ void loop(void) {
77110
78111 samplesRead = 0 ;
79112 mic = getPDMwave (4000 );
80-
113+
81114 Serial.println (" \n Feather Sense Sensor Demo" );
82115 Serial.println (" ---------------------------------------------" );
83116 Serial.print (" Proximity: " );
@@ -157,4 +190,4 @@ void onPDMdata() {
157190
158191 // 16-bit, 2 bytes per sample
159192 samplesRead = bytesAvailable / 2 ;
160- }
193+ }
0 commit comments