Skip to content

Commit c4d275f

Browse files
author
Kevin J Walters
committed
2 parents 8ef1682 + 65d591c commit c4d275f

File tree

172 files changed

+292362
-27
lines changed

Some content is hidden

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

172 files changed

+292362
-27
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ Hue_Controller/secrets.h
33
.idea
44
*.DS_Store
55
CircuitPython_Logger/secrets\.py
6+
.python-version

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ cache:
1515

1616
env:
1717
global:
18-
- ARDUINO_IDE_VERSION="1.8.7"
18+
- ARDUINO_IDE_VERSION="1.8.11"
1919
- PRETTYNAME="Adafruit Learning System Guides"
2020
- PLATFORM_CHECK_ONLY_ON_FILE=true
2121

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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 int(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+
31+
# Set this to sea level pressure in hectoPascals at your location for accurate altitude reading.
32+
bmp280.sea_level_pressure = 1013.25
33+
34+
while True:
35+
samples = array.array('H', [0] * 160)
36+
microphone.record(samples, len(samples))
37+
38+
print("\nFeather Sense Sensor Demo")
39+
print("---------------------------------------------")
40+
print("Proximity:", apds9960.proximity)
41+
print("Red: {}, Green: {}, Blue: {}, Clear: {}".format(*apds9960.color_data))
42+
print("Temperature: {:.1f} C".format(bmp280.temperature))
43+
print("Barometric pressure:", bmp280.pressure)
44+
print("Altitude: {:.1f} m".format(bmp280.altitude))
45+
print("Magnetic: {:.3f} {:.3f} {:.3f} uTesla".format(*lis3mdl.magnetic))
46+
print("Acceleration: {:.2f} {:.2f} {:.2f} m/s^2".format(*lsm6ds33.acceleration))
47+
print("Gyro: {:.2f} {:.2f} {:.2f} dps".format(*lsm6ds33.gyro))
48+
print("Humidity: {:.1f} %".format(sht31d.relative_humidity))
49+
print("Sound level:", normalized_rms(samples))
50+
time.sleep(0.3)
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
"""
2+
Heart Rate Trainer
3+
Read heart rate data from a heart rate peripheral using the standard BLE
4+
Heart Rate service.
5+
Displays BPM value to Seven Segment FeatherWing
6+
Displays percentage of max heart rate on another 7Seg FeatherWing
7+
"""
8+
9+
import time
10+
import board
11+
12+
import adafruit_ble
13+
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
14+
from adafruit_ble.services.standard.device_info import DeviceInfoService
15+
from adafruit_ble_heart_rate import HeartRateService
16+
17+
from adafruit_ht16k33.segments import Seg7x4
18+
19+
from digitalio import DigitalInOut, Direction
20+
21+
# Feather on-board status LEDs setup
22+
red_led = DigitalInOut(board.RED_LED)
23+
red_led.direction = Direction.OUTPUT
24+
red_led.value = True
25+
26+
blue_led = DigitalInOut(board.BLUE_LED)
27+
blue_led.direction = Direction.OUTPUT
28+
blue_led.value = False
29+
30+
# target heart rate for interval training
31+
# Change this number depending on your max heart rate, usually figured
32+
# as (220 - your age).
33+
max_rate = 180
34+
35+
# Seven Segment FeatherWing setup
36+
i2c = board.I2C()
37+
display_A = Seg7x4(i2c, address=0x70) # this will be the BPM display
38+
display_A.fill(0) # Clear the display
39+
# Second display has A0 address jumpered
40+
display_B = Seg7x4(i2c, address=0x71) # this will be the % target display
41+
display_B.fill(0) # Clear the display
42+
43+
# display_A "b.P.M."
44+
display_A.set_digit_raw(0, 0b11111100)
45+
display_A.set_digit_raw(1, 0b11110011)
46+
display_A.set_digit_raw(2, 0b00110011)
47+
display_A.set_digit_raw(3, 0b10100111)
48+
# display_B "Prct"
49+
display_B.set_digit_raw(0, 0b01110011)
50+
display_B.set_digit_raw(1, 0b01010000)
51+
display_B.set_digit_raw(2, 0b01011000)
52+
display_B.set_digit_raw(3, 0b01000110)
53+
time.sleep(3)
54+
55+
display_A.fill(0)
56+
for h in range(4):
57+
display_A.set_digit_raw(h, 0b10000000)
58+
# display_B show maximum heart rate value
59+
display_B.fill(0)
60+
display_B.print(max_rate)
61+
time.sleep(2)
62+
63+
# PyLint can't find BLERadio for some reason so special case it here.
64+
ble = adafruit_ble.BLERadio() # pylint: disable=no-member
65+
66+
hr_connection = None
67+
68+
def display_SCAN():
69+
display_A.fill(0)
70+
display_A.set_digit_raw(0, 0b01101101)
71+
display_A.set_digit_raw(1, 0b00111001)
72+
display_A.set_digit_raw(2, 0b01110111)
73+
display_A.set_digit_raw(3, 0b00110111)
74+
75+
76+
def display_bLE():
77+
display_B.fill(0)
78+
display_B.set_digit_raw(0, 0b00000000)
79+
display_B.set_digit_raw(1, 0b01111100)
80+
display_B.set_digit_raw(2, 0b00111000)
81+
display_B.set_digit_raw(3, 0b01111001)
82+
83+
def display_dots(): # "...."
84+
for j in range(4):
85+
display_A.set_digit_raw(j, 0b10000000)
86+
display_B.set_digit_raw(j, 0b10000000)
87+
88+
def display_dashes(): # "----"
89+
for k in range(4):
90+
display_A.set_digit_raw(k, 0b01000000)
91+
display_B.set_digit_raw(k, 0b01000000)
92+
93+
# Start with a fresh connection.
94+
if ble.connected:
95+
display_SCAN()
96+
display_bLE()
97+
time.sleep(1)
98+
99+
for connection in ble.connections:
100+
if HeartRateService in connection:
101+
connection.disconnect()
102+
break
103+
104+
while True:
105+
print("Scanning...")
106+
red_led.value = True
107+
blue_led.value = False
108+
display_SCAN()
109+
display_bLE()
110+
time.sleep(1)
111+
112+
113+
for adv in ble.start_scan(ProvideServicesAdvertisement, timeout=5):
114+
if HeartRateService in adv.services:
115+
print("found a HeartRateService advertisement")
116+
hr_connection = ble.connect(adv)
117+
display_dots()
118+
time.sleep(2)
119+
print("Connected")
120+
blue_led.value = True
121+
red_led.value = False
122+
break
123+
124+
# Stop scanning whether or not we are connected.
125+
ble.stop_scan()
126+
print("Stopped scan")
127+
red_led.value = False
128+
blue_led.value = True
129+
time.sleep(0.5)
130+
131+
if hr_connection and hr_connection.connected:
132+
print("Fetch connection")
133+
if DeviceInfoService in hr_connection:
134+
dis = hr_connection[DeviceInfoService]
135+
try:
136+
manufacturer = dis.manufacturer
137+
except AttributeError:
138+
manufacturer = "(Manufacturer Not specified)"
139+
try:
140+
model_number = dis.model_number
141+
except AttributeError:
142+
model_number = "(Model number not specified)"
143+
print("Device:", manufacturer, model_number)
144+
else:
145+
print("No device information")
146+
hr_service = hr_connection[HeartRateService]
147+
print("Location:", hr_service.location)
148+
149+
while hr_connection.connected:
150+
values = hr_service.measurement_values
151+
print(values) # returns the full heart_rate data set
152+
if values:
153+
bpm = (values.heart_rate)
154+
if bpm is not 0:
155+
pct_target = (round(100*(bpm/max_rate)))
156+
display_A.fill(0) # clear the display
157+
display_B.fill(0)
158+
if values.heart_rate is 0:
159+
display_dashes()
160+
else:
161+
display_A.fill(0)
162+
display_B.print(pct_target)
163+
time.sleep(0.1)
164+
display_A.print(bpm)
165+
166+
time.sleep(0.9)
167+
display_A.set_digit_raw(0, 0b00000000)

BLE_Sensornet/clue_sensornet.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""This uses the CLUE as a Bluetooth LE sensor node."""
2+
3+
import time
4+
from adafruit_clue import clue
5+
import adafruit_ble_broadcastnet
6+
7+
print("This is BroadcastNet CLUE sensor:", adafruit_ble_broadcastnet.device_address)
8+
9+
while True:
10+
measurement = adafruit_ble_broadcastnet.AdafruitSensorMeasurement()
11+
12+
measurement.temperature = clue.temperature
13+
measurement.pressure = clue.pressure
14+
measurement.relative_humidity = clue.humidity
15+
measurement.acceleration = clue.acceleration
16+
measurement.magnetic = clue.magnetic
17+
18+
print(measurement)
19+
adafruit_ble_broadcastnet.broadcast(measurement)
20+
time.sleep(60)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""This uses the Feather Sense as a Bluetooth LE sensor node."""
2+
3+
import time
4+
import adafruit_ble_broadcastnet
5+
import board
6+
import adafruit_lsm6ds # accelerometer
7+
import adafruit_sht31d # humidity sensor
8+
import adafruit_bmp280 # barometric sensor
9+
import adafruit_lis3mdl # magnetic sensor
10+
11+
i2c = board.I2C()
12+
13+
sense_accel = adafruit_lsm6ds.LSM6DS33(i2c)
14+
sense_humid = adafruit_sht31d.SHT31D(i2c)
15+
sense_barometric = adafruit_bmp280.Adafruit_BMP280_I2C(i2c)
16+
sense_magnet = adafruit_lis3mdl.LIS3MDL(i2c)
17+
18+
print("This is BroadcastNet Feather Sense sensor:", adafruit_ble_broadcastnet.device_address)
19+
20+
while True:
21+
measurement = adafruit_ble_broadcastnet.AdafruitSensorMeasurement()
22+
23+
measurement.temperature = sense_barometric.temperature
24+
measurement.pressure = sense_barometric.pressure
25+
measurement.relative_humidity = sense_humid.relative_humidity
26+
measurement.acceleration = sense_accel.acceleration
27+
measurement.magnetic = sense_magnet.magnetic
28+
29+
# print(measurement)
30+
adafruit_ble_broadcastnet.broadcast(measurement)
31+
time.sleep(60)

BLE_Synth/cpb_amp_code.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
'''BLE Synth
2+
File for the Circuit Playground Bluefruit
3+
Amp Portion'''
4+
from adafruit_circuitplayground.bluefruit import cpb
5+
from adafruit_led_animation.animation import Comet, AnimationGroup,\
6+
AnimationSequence
7+
import adafruit_led_animation.color as color
8+
from adafruit_ble import BLERadio
9+
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
10+
from adafruit_ble.services.nordic import UARTService
11+
from adafruit_bluefruit_connect.packet import Packet
12+
from adafruit_bluefruit_connect.color_packet import ColorPacket
13+
from adafruit_bluefruit_connect.button_packet import ButtonPacket
14+
15+
# easily call for NeoPixels to be off
16+
off = (0, 0, 0)
17+
# state to debounce on CPB end
18+
tone = False
19+
20+
# Setup for comet animation
21+
COMET_SPEED = 0.04 # Lower numbers increase the animation speed
22+
CPB_COMET_TAIL_LENGTH = 5 # The length of the comet on the Circuit Playground Bluefruit
23+
CPB_COMET_BOUNCE = False # Set to True to make the comet "bounce" the opposite direction on CPB
24+
25+
animations = AnimationSequence(
26+
AnimationGroup(
27+
Comet(cpb.pixels, COMET_SPEED, off, tail_length=CPB_COMET_TAIL_LENGTH,
28+
bounce=CPB_COMET_BOUNCE)))
29+
30+
# note frequencies
31+
C4 = 261.63
32+
Csharp4 = 277.18
33+
D4 = 293.66
34+
Dsharp4 = 311.13
35+
E4 = 329.63
36+
F4 = 349.23
37+
Fsharp4 = 369.99
38+
G4 = 392
39+
Gsharp4 = 415.3
40+
A4 = 440
41+
Asharp4 = 466.16
42+
B4 = 493.88
43+
44+
# note array
45+
note = [C4, Csharp4, D4, Dsharp4, E4, F4,
46+
Fsharp4, G4, Gsharp4, A4, Asharp4, B4]
47+
48+
# colors to recieve from color packet & for neopixels
49+
color_C = color.RED
50+
color_Csharp = color.ORANGE
51+
color_D = color.YELLOW
52+
color_Dsharp = color.GREEN
53+
color_E = color.TEAL
54+
color_F = color.CYAN
55+
color_Fsharp = color.BLUE
56+
color_G = color.PURPLE
57+
color_Gsharp = color.MAGENTA
58+
color_A = color.GOLD
59+
color_Asharp = color.PINK
60+
color_B = color.WHITE
61+
62+
# color array
63+
color = [color_C, color_Csharp, color_D, color_Dsharp, color_E,
64+
color_F, color_Fsharp, color_G, color_Gsharp, color_A,
65+
color_Asharp, color_B]
66+
67+
# Setup BLE connection
68+
ble = BLERadio()
69+
uart = UARTService()
70+
advertisement = ProvideServicesAdvertisement(uart)
71+
72+
while True:
73+
# connect via BLE
74+
ble.start_advertising(advertisement) # Start advertising.
75+
was_connected = False
76+
while not was_connected or ble.connected:
77+
if ble.connected: # If BLE is connected...
78+
was_connected = True
79+
# start animations
80+
animations.animate()
81+
# look for packets
82+
if uart.in_waiting:
83+
try:
84+
packet = Packet.from_stream(uart) # Create the packet object.
85+
except ValueError:
86+
continue
87+
# if it's a color packet:
88+
if isinstance(packet, ColorPacket):
89+
for i in range(12):
90+
colors = color[i]
91+
notes = note[i]
92+
# if the packet matches one of our colors:
93+
if packet.color == colors and not tone:
94+
# animate with that color
95+
animations.color = colors
96+
# play matching note
97+
cpb.start_tone(notes)
98+
tone = True
99+
# if it's a button packet aka feather's button has been released:
100+
elif isinstance(packet, ButtonPacket) and packet.pressed:
101+
if packet.button == ButtonPacket.RIGHT and tone:
102+
tone = False
103+
# stop playing the note
104+
cpb.stop_tone()
105+
# turn off the neopixels but keep animation active
106+
animations.color = off

0 commit comments

Comments
 (0)