Skip to content

Commit 509ee94

Browse files
authored
Merge pull request #1046 from kattni/feather-sense
Feather Sense demo.
2 parents 4ba86c2 + cdf68a5 commit 509ee94

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""Sensor demo for Adafruit Feather Sense. Prints data from each of the sensors."""
2+
import time
3+
import array
4+
import math
5+
import board
6+
import audiobusio
7+
import adafruit_apds9960.apds9960
8+
import adafruit_bmp280
9+
import adafruit_lis3mdl
10+
import adafruit_lsm6ds
11+
import adafruit_sht31d
12+
13+
i2c = board.I2C()
14+
15+
apds9960 = adafruit_apds9960.apds9960.APDS9960(i2c)
16+
bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c)
17+
lis3mdl = adafruit_lis3mdl.LIS3MDL(i2c)
18+
lsm6ds33 = adafruit_lsm6ds.LSM6DS33(i2c)
19+
sht31d = adafruit_sht31d.SHT31D(i2c)
20+
microphone = audiobusio.PDMIn(board.MICROPHONE_CLOCK, board.MICROPHONE_DATA,
21+
sample_rate=16000, bit_depth=16)
22+
23+
def normalized_rms(values):
24+
minbuf = int(sum(values) / len(values))
25+
return math.sqrt(sum(float(sample - minbuf) *
26+
(sample - minbuf) for sample in values) / len(values))
27+
28+
apds9960.enable_proximity = True
29+
apds9960.enable_color = True
30+
bmp280.sea_level_pressure = 1013.25
31+
32+
while True:
33+
samples = array.array('H', [0] * 160)
34+
microphone.record(samples, len(samples))
35+
36+
print("\nFeather Sense Sensor Demo")
37+
print("---------------------------------------------")
38+
print("Proximity:", apds9960.proximity())
39+
print("Red: {}, Green: {}, Blue: {}, Clear: {}".format(*apds9960.color_data))
40+
print("Temperature: {:.1f} C".format(bmp280.temperature))
41+
print("Barometric pressure:", bmp280.pressure)
42+
print("Altitude: {:.1f} m".format(bmp280.altitude))
43+
print("Magnetic: {:.3f} {:.3f} {:.3f} uTesla".format(*lis3mdl.magnetic))
44+
print("Acceleration: {:.2f} {:.2f} {:.2f} m/s^2".format(*lsm6ds33.acceleration))
45+
print("Gyro: {:.2f} {:.2f} {:.2f} dps".format(*lsm6ds33.gyro))
46+
print("Humidity: {:.1f} %".format(sht31d.relative_humidity))
47+
print("Sound level:", normalized_rms(samples))
48+
time.sleep(0.3)

0 commit comments

Comments
 (0)