Skip to content

Commit 7e5fd71

Browse files
authored
Merge branch 'master' into fix-pyportal-mqtt-sensor-node
2 parents 01f4c91 + 284171e commit 7e5fd71

File tree

101 files changed

+30061
-21
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+30061
-21
lines changed

Adafruit_ESP32_Arduino_Demos/SerialESPPassthrough/SerialESPPassthrough.ino

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ unsigned long baud = 115200;
2727
defined(ADAFRUIT_FEATHER_M0_EXPRESS) || \
2828
defined(ARDUINO_AVR_FEATHER32U4) || \
2929
defined(ARDUINO_NRF52840_FEATHER) || \
30-
defined(ADAFRUIT_ITSYBITSY_M0_EXPRESS) || \
30+
defined(ADAFRUIT_ITSYBITSY_M0) || \
3131
defined(ADAFRUIT_ITSYBITSY_M4_EXPRESS) || \
32-
defined(ARDUINO_AVR_ITSYBITSY32U4_3V)
32+
defined(ARDUINO_AVR_ITSYBITSY32U4_3V) || \
33+
defined(ARDUINO_NRF52_ITSYBITSY)
3334
// Configure the pins used for the ESP32 connection
3435
#define SerialESP32 Serial1
3536
#define SPIWIFI SPI // The SPI port
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
#include <Adafruit_APDS9960.h>
2+
#include <Adafruit_BMP280.h>
3+
#include <Adafruit_LIS3MDL.h>
4+
#include <Adafruit_LSM6DS33.h>
5+
#include <Adafruit_SHT31.h>
6+
#include <Adafruit_Sensor.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+
Serial.begin(115200);
30+
// while (!Serial) delay(10);
31+
Serial.println("Feather Sense Sensor Demo");
32+
33+
// initialize the sensors
34+
apds9960.begin();
35+
apds9960.enableProximity(true);
36+
apds9960.enableColor(true);
37+
bmp280.begin();
38+
lis3mdl.begin_I2C();
39+
lsm6ds33.begin_I2C();
40+
sht30.begin();
41+
PDM.onReceive(onPDMdata);
42+
PDM.begin(1, 16000);
43+
}
44+
45+
void loop(void) {
46+
proximity = apds9960.readProximity();
47+
while (!apds9960.colorDataReady()) {
48+
delay(5);
49+
}
50+
apds9960.getColorData(&r, &g, &b, &c);
51+
52+
temperature = bmp280.readTemperature();
53+
pressure = bmp280.readPressure();
54+
altitude = bmp280.readAltitude(1013.25);
55+
56+
lis3mdl.read();
57+
magnetic_x = lis3mdl.x;
58+
magnetic_y = lis3mdl.y;
59+
magnetic_z = lis3mdl.z;
60+
61+
sensors_event_t accel;
62+
sensors_event_t gyro;
63+
sensors_event_t temp;
64+
lsm6ds33.getEvent(&accel, &gyro, &temp);
65+
accel_x = accel.acceleration.x;
66+
accel_y = accel.acceleration.y;
67+
accel_z = accel.acceleration.z;
68+
gyro_x = gyro.gyro.x;
69+
gyro_y = gyro.gyro.y;
70+
gyro_z = gyro.gyro.z;
71+
72+
humidity = sht30.readHumidity();
73+
74+
samplesRead = 0;
75+
mic = getPDMwave(4000);
76+
77+
Serial.println("\nFeather Sense Sensor Demo");
78+
Serial.println("---------------------------------------------");
79+
Serial.print("Proximity: ");
80+
Serial.println(apds9960.readProximity());
81+
Serial.print("Red: ");
82+
Serial.print(r);
83+
Serial.print(" Green: ");
84+
Serial.print(g);
85+
Serial.print(" Blue :");
86+
Serial.print(b);
87+
Serial.print(" Clear: ");
88+
Serial.println(c);
89+
Serial.print("Temperature: ");
90+
Serial.print(temperature);
91+
Serial.println(" C");
92+
Serial.print("Barometric pressure: ");
93+
Serial.println(pressure);
94+
Serial.print("Altitude: ");
95+
Serial.print(altitude);
96+
Serial.println(" m");
97+
Serial.print("Magnetic: ");
98+
Serial.print(magnetic_x);
99+
Serial.print(" ");
100+
Serial.print(magnetic_y);
101+
Serial.print(" ");
102+
Serial.print(magnetic_z);
103+
Serial.println(" uTesla");
104+
Serial.print("Acceleration: ");
105+
Serial.print(accel_x);
106+
Serial.print(" ");
107+
Serial.print(accel_y);
108+
Serial.print(" ");
109+
Serial.print(accel_z);
110+
Serial.println(" m/s^2");
111+
Serial.print("Gyro: ");
112+
Serial.print(gyro_x);
113+
Serial.print(" ");
114+
Serial.print(gyro_y);
115+
Serial.print(" ");
116+
Serial.print(gyro_z);
117+
Serial.println(" dps");
118+
Serial.print("Humidity: ");
119+
Serial.print(humidity);
120+
Serial.println(" %");
121+
Serial.print("Mic: ");
122+
Serial.println(mic);
123+
delay(300);
124+
}
125+
126+
/*****************************************************************/
127+
int32_t getPDMwave(int32_t samples) {
128+
short minwave = 30000;
129+
short maxwave = -30000;
130+
131+
while (samples > 0) {
132+
if (!samplesRead) {
133+
yield();
134+
continue;
135+
}
136+
for (int i = 0; i < samplesRead; i++) {
137+
minwave = min(sampleBuffer[i], minwave);
138+
maxwave = max(sampleBuffer[i], maxwave);
139+
samples--;
140+
}
141+
// clear the read count
142+
samplesRead = 0;
143+
}
144+
return maxwave - minwave;
145+
}
146+
147+
void onPDMdata() {
148+
// query the number of bytes available
149+
int bytesAvailable = PDM.available();
150+
151+
// read into the sample buffer
152+
PDM.read(sampleBuffer, bytesAvailable);
153+
154+
// 16-bit, 2 bytes per sample
155+
samplesRead = bytesAvailable / 2;
156+
}

Bluetooth_Restroom_Keys/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## Code for the Adafruit Learning System guide Bluetooth Restroom Key Proximity Tracker
2+
3+
See this guide at https://learn.adafruit.com/bluetooth-restroom-key-proximity-tracker/
4+

Bluetooth_Restroom_Keys/code.py

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
"""Bluetooth Key Tracker."""
2+
from adafruit_ble import BLERadio
3+
from adafruit_led_animation.animation import Pulse, Solid
4+
import adafruit_led_animation.color as color
5+
from analogio import AnalogIn
6+
from array import array
7+
from audiobusio import I2SOut
8+
from audiocore import RawSample, WaveFile
9+
from board import BATTERY, D5, D6, D9, NEOPIXEL, RX, TX
10+
from digitalio import DigitalInOut, Direction, Pull
11+
from math import pi, sin
12+
from neopixel import NeoPixel
13+
from time import sleep
14+
15+
battery = AnalogIn(BATTERY)
16+
17+
ble = BLERadio()
18+
hit_status = [color.RED, color.ORANGE, color.AMBER, color.GREEN]
19+
20+
pixel = NeoPixel(NEOPIXEL, 1)
21+
pulse = Pulse(pixel,
22+
speed=0.01,
23+
color=color.PURPLE, # Use CYAN for Male Key
24+
period=3,
25+
min_intensity=0.0,
26+
max_intensity=0.5)
27+
28+
solid = Solid(pixel, color.GREEN)
29+
30+
reed_switch = DigitalInOut(D5)
31+
reed_switch.direction = Direction.INPUT
32+
reed_switch.pull = Pull.UP
33+
34+
amp_enable = DigitalInOut(D6)
35+
amp_enable.direction = Direction.OUTPUT
36+
amp_enable.value = False
37+
38+
39+
def play_tone():
40+
"""Generate tone and transmit to I2S amp."""
41+
length = 4000 // 440
42+
sine_wave = array("H", [0] * length)
43+
for i in range(length):
44+
sine_wave[i] = int(sin(pi * 2 * i / 18) * (2 ** 15) + 2 ** 15)
45+
46+
sample = RawSample(sine_wave, sample_rate=8000)
47+
i2s = I2SOut(TX, RX, D9)
48+
i2s.play(sample, loop=True)
49+
sleep(1)
50+
i2s.stop()
51+
sample.deinit()
52+
i2s.deinit()
53+
54+
55+
def play_message():
56+
"""Play recorded WAV message and transmit to I2S amp."""
57+
with open("d1.wav", "rb") as file:
58+
wave = WaveFile(file)
59+
i2s = I2SOut(TX, RX, D9)
60+
i2s.play(wave)
61+
while i2s.playing:
62+
pass
63+
wave.deinit()
64+
i2s.deinit()
65+
66+
67+
boundary_violations = 0
68+
69+
while True:
70+
if reed_switch.value: # Not Docked
71+
hits = 0
72+
try:
73+
advertisements = ble.start_scan(timeout=3)
74+
for advertisement in advertisements:
75+
addr = advertisement.address
76+
if (advertisement.scan_response and
77+
addr.type == addr.RANDOM_STATIC):
78+
if advertisement.complete_name == '<Your 1st beacon name here>':
79+
hits |= 0b001
80+
elif advertisement.complete_name == '<Your 2nd beacon name here>':
81+
hits |= 0b010
82+
elif advertisement.complete_name == '<Your 3rd beacon name here>':
83+
hits |= 0b100
84+
except Exception as e:
85+
print(repr(e))
86+
hit_count = len([ones for ones in bin(hits) if ones == '1'])
87+
solid.color = hit_status[hit_count]
88+
solid.animate()
89+
sleep(1)
90+
if hit_count == 0:
91+
if boundary_violations % 60 == 0: # Play message every 60 cycles
92+
amp_enable.value = True
93+
sleep(1)
94+
play_tone()
95+
sleep(1)
96+
play_message()
97+
sleep(1)
98+
amp_enable.value = False
99+
boundary_violations += 1
100+
else:
101+
boundary_violations = 0
102+
103+
else: # Docked
104+
boundary_violations = 0
105+
voltage = battery.value * 3.3 / 65535 * 2
106+
if voltage < 3.7:
107+
pulse.period = 1 # Speed up LED pulse for low battery
108+
else:
109+
pulse.period = 3
110+
pulse.animate()

0 commit comments

Comments
 (0)