Skip to content

Commit 750a56f

Browse files
committed
2 parents df1f30b + 4a2591a commit 750a56f

Some content is hidden

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

47 files changed

+96307
-5
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)

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)
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
import time
2+
import displayio
3+
import terminalio
4+
from adafruit_clue import clue
5+
from adafruit_display_text import label
6+
import adafruit_imageload
7+
from adafruit_ble import BLERadio
8+
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
9+
from adafruit_ble.services.nordic import UARTService
10+
11+
#--| User Config |---------------------------------------------------
12+
MY_NAME = "ME"
13+
FRIENDS_NAME = "FRIEND"
14+
#--| User Config |---------------------------------------------------
15+
16+
WAIT_FOR_DOUBLE = 0.05
17+
DEBOUNCE = 0.25
18+
19+
# Define Morse Code dictionary
20+
morse_code = {
21+
".-" : "A", "-..." : "B", "-.-." : "C", "-.." : "D", "." : "E",
22+
"..-." : "F", "--." : "G", "...." : "H", ".." : "I", ".---" : "J",
23+
"-.-" : "K", ".-.." : "L", "--" : "M", "-." : "N", "---" : "O",
24+
".--." : "P", "--.-" : "Q", ".-." : "R", "..." : "S", "-" : "T",
25+
"..-" : "U", "...-" : "V", ".--" : "W", "-..-" : "X", "-.--" : "Y",
26+
"--.." : "Z",
27+
}
28+
29+
# BLE Radio Stuff
30+
ble = BLERadio()
31+
uart_service = UARTService()
32+
advertisement = ProvideServicesAdvertisement(uart_service)
33+
ble._adapter.name = MY_NAME #pylint: disable=protected-access
34+
35+
# Display Stuff
36+
display = clue.display
37+
disp_group = displayio.Group()
38+
display.show(disp_group)
39+
40+
# Background BMP with the Morse Code cheat sheet
41+
bmp, pal = adafruit_imageload.load("morse_bg.bmp",
42+
bitmap=displayio.Bitmap,
43+
palette=displayio.Palette)
44+
disp_group.append(displayio.TileGrid(bmp, pixel_shader=pal))
45+
46+
# Incoming messages show up here
47+
in_label = label.Label(terminalio.FONT, text='A'*18, scale=2,
48+
color=0x000000)
49+
in_label.anchor_point = (0.5, 0)
50+
in_label.anchored_position = (65, 12)
51+
disp_group.append(in_label)
52+
53+
# Outging messages show up here
54+
out_label = label.Label(terminalio.FONT, text='B'*18, scale=2,
55+
color=0x000000)
56+
out_label.anchor_point = (0.5, 0)
57+
out_label.anchored_position = (65, 190)
58+
disp_group.append(out_label)
59+
60+
# Morse Code entry happens here
61+
edit_label = label.Label(terminalio.FONT, text='....', scale=2,
62+
color=0x000000)
63+
edit_label.anchor_point = (0.5, 0)
64+
edit_label.anchored_position = (105, 222)
65+
disp_group.append(edit_label)
66+
67+
def scan_and_connect():
68+
'''
69+
Advertise self while scanning for friend. If friend is found, can
70+
connect by pressing A+B buttons. If friend connects first, then
71+
just stop.
72+
73+
Return is a UART object that can be used for read/write.
74+
'''
75+
76+
print("Advertising.")
77+
central = False
78+
ble.start_advertising(advertisement)
79+
80+
print("Waiting.")
81+
friend = None
82+
while not ble.connected:
83+
84+
if friend is None:
85+
print("Scanning.")
86+
in_label.text = out_label.text = "Scanning..."
87+
for adv in ble.start_scan():
88+
if ble.connected:
89+
# Friend connected with us, we're done
90+
ble.stop_scan()
91+
break
92+
if adv.complete_name == FRIENDS_NAME:
93+
# Found friend, can stop scanning
94+
ble.stop_scan()
95+
friend = adv
96+
print("Found", friend.complete_name)
97+
in_label.text = "Found {}".format(friend.complete_name)
98+
out_label.text = "A+B to connect"
99+
break
100+
else:
101+
if clue.button_a and clue.button_b:
102+
# Connect to friend
103+
print("Connecting to", friend.complete_name)
104+
ble.connect(friend)
105+
central = True
106+
107+
# We're now connected, one way or the other
108+
print("Stopping advertising.")
109+
ble.stop_advertising()
110+
111+
# Return a UART object to use
112+
if central:
113+
print("Central - using my UART service.")
114+
return uart_service
115+
else:
116+
print("Peripheral - connecting to their UART service.")
117+
for connection in ble.connections:
118+
if UARTService not in connection:
119+
continue
120+
return connection[UARTService]
121+
122+
#--------------------------
123+
# The main application loop
124+
#--------------------------
125+
while True:
126+
127+
# Establish initial connection
128+
uart = scan_and_connect()
129+
130+
print("Connected.")
131+
132+
code = ''
133+
in_label.text = out_label.text = ' '*18
134+
edit_label.text = ' '*4
135+
done = False
136+
137+
# Run the chat while connected
138+
while ble.connected:
139+
140+
# Check for incoming message
141+
incoming_bytes = uart.in_waiting
142+
if incoming_bytes:
143+
bytes_in = uart.read(incoming_bytes)
144+
print("Received: ", bytes_in)
145+
in_label.text = in_label.text[incoming_bytes:] + bytes_in.decode()
146+
147+
# DOT (or done)
148+
if clue.button_a:
149+
start = time.monotonic()
150+
while time.monotonic() - start < WAIT_FOR_DOUBLE:
151+
if clue.button_b:
152+
done = True
153+
if not done and len(code) < 4:
154+
print('.', end='')
155+
code += '.'
156+
edit_label.text = "{:4s}".format(code)
157+
time.sleep(DEBOUNCE)
158+
159+
# DASH (or done)
160+
if clue.button_b:
161+
start = time.monotonic()
162+
while time.monotonic() - start < WAIT_FOR_DOUBLE:
163+
if clue.button_a:
164+
done = True
165+
if not done and len(code) < 4:
166+
print('-', end='')
167+
code += '-'
168+
edit_label.text = "{:4s}".format(code)
169+
time.sleep(DEBOUNCE)
170+
171+
# Turn Morse Code into letter and send
172+
if done:
173+
letter = morse_code.get(code, ' ')
174+
print(' >', letter)
175+
out_label.text = out_label.text[1:] + letter
176+
uart.write(str.encode(letter))
177+
code = ''
178+
edit_label.text = ' '*4
179+
done = False
180+
time.sleep(DEBOUNCE)
181+
182+
print("Disconnected.")

CLUE_BLE_Morse_Code/morse_bg.bmp

28.3 KB
Binary file not shown.

CLUE_Beacon/bg.bmp

113 KB
Binary file not shown.

CLUE_Beacon/clue_beacon.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
"""
2+
Eddystone Beacon for CLUE
3+
This example broadcasts our Mac Address as our Eddystone ID and a link to a URL of your choice.
4+
Hold the A button to display QR code, use B button to pick URL from the list.
5+
"""
6+
7+
import time
8+
from adafruit_pybadger import pybadger
9+
import adafruit_ble
10+
from adafruit_ble_eddystone import uid, url
11+
12+
radio = adafruit_ble.BLERadio()
13+
14+
# Reuse the BLE address as our Eddystone instance id.
15+
eddystone_uid = uid.EddystoneUID(radio.address_bytes)
16+
17+
# List of URLs to broadcast here:
18+
ad_url = [("https://circuitpython.org", "CirPy"),
19+
("https://adafru.it/discord","DISCORD"),
20+
("https://forums.adafruit.com", "Forums"),
21+
("https://learn.adafruit.com", "Learn")
22+
]
23+
pick = 0 # use to increment url choices
24+
25+
pybadger.play_tone(1600, 0.25)
26+
pybadger.show_business_card(image_name="cluebeacon.bmp")
27+
28+
while True:
29+
pybadger.auto_dim_display(delay=3, movement_threshold=4)
30+
eddystone_url = url.EddystoneURL(ad_url[pick][0])
31+
32+
if pybadger.button.a and not pybadger.button.b: # Press button A to show QR code
33+
pybadger.play_tone(1200, 0.1)
34+
pybadger.brightness = 1
35+
pybadger.show_qr_code(data=ad_url[pick][0]) # Tests QR code
36+
time.sleep(0.1) # Debounce
37+
38+
elif pybadger.button.b and not pybadger.button.a: # iterate through urls to broadcast
39+
pybadger.play_tone(1600, 0.2)
40+
pick = (pick + 1) % len(ad_url)
41+
pybadger.brightness = 1
42+
pybadger.show_business_card(image_name="bg.bmp", name_string=ad_url[pick][1], name_scale=5,
43+
email_string_one="", email_string_two=ad_url[pick][0])
44+
time.sleep(0.1)
45+
46+
elif pybadger.button.a and pybadger.button.b:
47+
pybadger.play_tone(1000, 0.2)
48+
pybadger.brightness = 1
49+
pybadger.show_business_card(image_name="cluebeacon.bmp")
50+
time.sleep(0.1)
51+
52+
# Alternate between advertising our ID and our URL.
53+
radio.start_advertising(eddystone_uid)
54+
time.sleep(0.5)
55+
radio.stop_advertising()
56+
57+
radio.start_advertising(eddystone_url)
58+
time.sleep(0.5)
59+
radio.stop_advertising()
60+
61+
time.sleep(1)

CLUE_Beacon/cluebeacon.bmp

113 KB
Binary file not shown.

CLUE_Cycling_Simple/CLUE_cycling_simple.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from adafruit_ble.services.standard.device_info import DeviceInfoService
1212
from adafruit_ble_cycling_speed_and_cadence import CyclingSpeedAndCadenceService
1313

14-
clue_data = clue.simple_text_display(title="Cycle Revs", title_scale=1, text_scale=3, num_lines=3)
14+
clue_data = clue.simple_text_display(title="Cycle Revs", title_scale=1, text_scale=3)
1515

1616
# PyLint can't find BLERadio for some reason so special case it here.
1717
ble = adafruit_ble.BLERadio() # pylint: disable=no-member

0 commit comments

Comments
 (0)