Skip to content

Commit ff6594c

Browse files
committed
add Arduino Feather Sense demo
1 parent cd37f84 commit ff6594c

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
#include <Adafruit_Sensor.h>
2+
#include <Adafruit_APDS9960.h>
3+
#include <Adafruit_BMP280.h>
4+
#include <Adafruit_LIS3MDL.h>
5+
#include <Adafruit_LSM6DS33.h>
6+
#include <Adafruit_SHT31.h>
7+
#include <PDM.h>
8+
9+
Adafruit_APDS9960 apds9960; // proximity, light, color, gesture
10+
Adafruit_BMP280 bmp280; // temperautre, barometric pressure
11+
Adafruit_LIS3MDL lis3mdl; // magnetometer
12+
Adafruit_LSM6DS33 lsm6ds33; // accelerometer, gyroscope
13+
Adafruit_SHT31 sht30; // humidity
14+
15+
uint8_t proximity;
16+
uint16_t r, g, b, c;
17+
float temperature, pressure, altitude;
18+
float magnetic_x, magnetic_y, magnetic_z;
19+
float accel_x, accel_y, accel_z;
20+
float gyro_x, gyro_y, gyro_z;
21+
float humidity;
22+
int32_t mic;
23+
24+
extern PDMClass PDM;
25+
short sampleBuffer[256]; // buffer to read samples into, each sample is 16-bits
26+
volatile int samplesRead; // number of samples read
27+
28+
void setup(void)
29+
{
30+
Serial.begin(115200);
31+
//while (!Serial) delay(10);
32+
Serial.println("Feather Sense Sensor Demo");
33+
34+
// initialize the sensors
35+
apds9960.begin(); apds9960.enableProximity(true); apds9960.enableColor(true);
36+
bmp280.begin();
37+
lis3mdl.begin_I2C();
38+
lsm6ds33.begin_I2C();
39+
sht30.begin();
40+
PDM.onReceive(onPDMdata);
41+
PDM.begin(1, 16000);
42+
}
43+
44+
45+
void loop(void)
46+
{
47+
proximity = apds9960.readProximity();
48+
while(!apds9960.colorDataReady()){
49+
delay(5);
50+
}
51+
apds9960.getColorData(&r, &g, &b, &c);
52+
53+
temperature = bmp280.readTemperature();
54+
pressure = bmp280.readPressure();
55+
altitude = bmp280.readAltitude(1013.25);
56+
57+
lis3mdl.read();
58+
magnetic_x = lis3mdl.x;
59+
magnetic_y = lis3mdl.y;
60+
magnetic_z = lis3mdl.z;
61+
62+
sensors_event_t accel;
63+
sensors_event_t gyro;
64+
sensors_event_t temp;
65+
lsm6ds33.getEvent(&accel, &gyro, &temp);
66+
accel_x = accel.acceleration.x;
67+
accel_y = accel.acceleration.y;
68+
accel_z = accel.acceleration.z;
69+
gyro_x = gyro.gyro.x;
70+
gyro_y = gyro.gyro.y;
71+
gyro_z = gyro.gyro.z;
72+
73+
humidity = sht30.readHumidity();
74+
75+
samplesRead = 0;
76+
mic = getPDMwave(4000);
77+
78+
Serial.println("\nFeather Sense Sensor Demo");
79+
Serial.println("---------------------------------------------");
80+
Serial.print("Proximity: "); Serial.println(apds9960.readProximity());
81+
Serial.print("Red: "); Serial.print(r); Serial.print(" Green: "); Serial.print(g); Serial.print(" Blue :"); Serial.print(b); Serial.print(" Clear: "); Serial.println(c);
82+
Serial.print("Temperature: "); Serial.print(temperature); Serial.println(" C");
83+
Serial.print("Barometric pressure: "); Serial.println(pressure);
84+
Serial.print("Altitude: "); Serial.print(altitude); Serial.println(" m");
85+
Serial.print("Magnetic: "); Serial.print(magnetic_x); Serial.print(" "); Serial.print(magnetic_y); Serial.print(" "); Serial.print(magnetic_z); Serial.println(" uTesla");
86+
Serial.print("Acceleration: "); Serial.print(accel_x); Serial.print(" "); Serial.print(accel_y); Serial.print(" "); Serial.print(accel_z); Serial.println(" m/s^2");
87+
Serial.print("Gyro: "); Serial.print(gyro_x); Serial.print(" "); Serial.print(gyro_y); Serial.print(" "); Serial.print(gyro_z); Serial.println(" dps");
88+
Serial.print("Humidity: "); Serial.print(humidity); Serial.println(" %");
89+
Serial.print("Mic: "); Serial.println(mic);
90+
delay(300);
91+
}
92+
93+
94+
/*****************************************************************/
95+
int32_t getPDMwave(int32_t samples) {
96+
short minwave = 30000;
97+
short maxwave = -30000;
98+
99+
while (samples > 0) {
100+
if (!samplesRead) {
101+
yield();
102+
continue;
103+
}
104+
for (int i = 0; i < samplesRead; i++) {
105+
minwave = min(sampleBuffer[i], minwave);
106+
maxwave = max(sampleBuffer[i], maxwave);
107+
samples--;
108+
}
109+
// clear the read count
110+
samplesRead = 0;
111+
}
112+
return maxwave-minwave;
113+
}
114+
115+
void onPDMdata() {
116+
// query the number of bytes available
117+
int bytesAvailable = PDM.available();
118+
119+
// read into the sample buffer
120+
PDM.read(sampleBuffer, bytesAvailable);
121+
122+
// 16-bit, 2 bytes per sample
123+
samplesRead = bytesAvailable / 2;
124+
}

0 commit comments

Comments
 (0)