Skip to content

Commit cdd795a

Browse files
committed
Merge remote-tracking branch 'adafruit/master'
2 parents 89e2a0a + 68c37d8 commit cdd795a

272 files changed

Lines changed: 271201 additions & 313 deletions

File tree

Some content is hidden

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

.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

Binary file not shown.

Adafruit_pIRKey/NEC_keyboard_example.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
import adafruit_dotstar
1111
import pulseio
1212
import board
13+
import usb_hid
1314

1415
led = adafruit_dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1)
1516

1617
# The keyboard object!
1718
time.sleep(1) # Sleep for a bit to avoid a race condition on some systems
18-
keyboard = Keyboard()
19+
keyboard = Keyboard(usb_hid.devices)
1920
keyboard_layout = KeyboardLayoutUS(keyboard) # We're in the US :)
2021

2122
# our infrared pulse decoder helpers

Adafruit_pIRKey/raw_code_keyboard/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
import adafruit_dotstar
99
import adafruit_irremote
1010
import time
11+
import usb_hid
1112

1213
# The keyboard object!
1314
time.sleep(1) # Sleep for a bit to avoid a race condition on some systems
14-
keyboard = Keyboard()
15+
keyboard = Keyboard(usb_hid.devices)
1516
keyboard_layout = KeyboardLayoutUS(keyboard) # We're in the US :)
1617

1718
led = adafruit_dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1)

Arcade_Button_Control_Box/Arcade_Button_Control_Box.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from adafruit_hid.keyboard import Keyboard
55
from adafruit_hid.keycode import Keycode
66
import board
7+
import usb_hid
78

89
# A simple neat keyboard demo in circuitpython
910

@@ -16,7 +17,7 @@
1617
controlkey = Keycode.LEFT_CONTROL
1718

1819
# the keyboard object!
19-
kbd = Keyboard()
20+
kbd = Keyboard(usb_hid.devices)
2021
# our array of button objects
2122
buttons = []
2223
leds = []

AutoSunglasses/code.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414

1515
import time
1616
import board
17-
import simpleio
17+
import pulseio
1818
from adafruit_circuitplayground.express import cpx
19+
from adafruit_motor import servo
1920

20-
servo = simpleio.Servo(board.A1)
21+
pwm = pulseio.PWMOut(board.A1, duty_cycle=2 ** 15, frequency=50)
22+
my_servo = servo.Servo(pwm)
2123

2224
cpx.pixels.fill((0, 0, 0))
23-
servo.angle = 90
25+
my_servo.angle = 90
2426

2527
while True:
2628
light_level = cpx.light
@@ -30,8 +32,8 @@
3032
else:
3133
cpx.pixels.fill((0, 0, 0))
3234
if light_level < 200:
33-
servo.angle = 90
35+
my_servo.angle = 90
3436
else:
35-
servo.angle = 0
37+
my_servo.angle = 0
3638

3739
time.sleep(0.25)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# CircuitPython NeoPixel Color Picker Example
2+
3+
import board
4+
import neopixel
5+
from adafruit_ble import BLERadio
6+
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
7+
from adafruit_ble.services.nordic import UARTService
8+
from adafruit_bluefruit_connect.packet import Packet
9+
from adafruit_bluefruit_connect.color_packet import ColorPacket
10+
11+
ble = BLERadio()
12+
uart_service = UARTService()
13+
advertisement = ProvideServicesAdvertisement(uart_service)
14+
15+
pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=0.1)
16+
17+
while True:
18+
# Advertise when not connected.
19+
ble.start_advertising(advertisement)
20+
while not ble.connected:
21+
pass
22+
23+
while ble.connected:
24+
packet = Packet.from_stream(uart_service)
25+
if isinstance(packet, ColorPacket):
26+
print(packet.color)
27+
pixels.fill(packet.color)

BLE_Crickit_Light_Switch/ble_crickit_light_switch.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# BLE Crickit Light Switch
22
# Use with the Adafruit BlueFruit LE Connect app
3-
# Works with CircuitPython 4.0.0-beta.1 and later
3+
# Works with CircuitPython 5.0.0-beta.0 and later
44
# running on an nRF52840 Feather board and Crickit FeatherWing
55
# micro servo, 3D printed switch actuator
66

@@ -10,7 +10,10 @@
1010
import digitalio
1111

1212
from adafruit_crickit import crickit
13-
from adafruit_ble.uart import UARTServer
13+
14+
from adafruit_ble import BLERadio
15+
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
16+
from adafruit_ble.services.nordic import UARTService
1417

1518
from adafruit_bluefruit_connect.packet import Packet
1619
# Only the packet classes that are imported will be known to Packet.
@@ -22,7 +25,9 @@
2225
blue_led.direction = digitalio.Direction.OUTPUT
2326
red_led.direction = digitalio.Direction.OUTPUT
2427

25-
uart_server = UARTServer()
28+
ble = BLERadio()
29+
uart_service = UARTService()
30+
advertisement = ProvideServicesAdvertisement(uart_service)
2631

2732
UP_ANGLE = 180
2833
NEUTRAL_ANGLE = 120
@@ -35,17 +40,17 @@
3540
print("Use Adafruit Bluefruit app to connect")
3641
while True:
3742
blue_led.value = False
38-
uart_server.start_advertising()
43+
ble.start_advertising(advertisement)
3944

40-
while not uart_server.connected:
45+
while not ble.connected:
4146
# Wait for a connection.
4247
pass
4348
blue_led.value = True # turn on blue LED when connected
44-
while uart_server.connected:
45-
if uart_server.in_waiting:
49+
while ble.connected:
50+
if uart_service.in_waiting:
4651
# Packet is arriving.
4752
red_led.value = False # turn off red LED
48-
packet = Packet.from_stream(uart_server)
53+
packet = Packet.from_stream(uart_service)
4954
if isinstance(packet, ButtonPacket) and packet.pressed:
5055
red_led.value = True # blink to show a packet has been received
5156
if packet.button == ButtonPacket.UP and angle != UP_ANGLE: # UP button pressed
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
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.brightness = 15
39+
display_A.fill(0) # Clear the display
40+
# Second display has A0 address jumpered
41+
display_B = Seg7x4(i2c, address=0x71) # this will be the % target display
42+
display_B.brightness = 15
43+
display_B.fill(0) # Clear the display
44+
45+
# display_A "b.P.M."
46+
display_A.set_digit_raw(0, 0b11111100)
47+
display_A.set_digit_raw(1, 0b11110011)
48+
display_A.set_digit_raw(2, 0b00110011)
49+
display_A.set_digit_raw(3, 0b10100111)
50+
# display_B "Prct"
51+
display_B.set_digit_raw(0, 0b01110011)
52+
display_B.set_digit_raw(1, 0b01010000)
53+
display_B.set_digit_raw(2, 0b01011000)
54+
display_B.set_digit_raw(3, 0b01000110)
55+
time.sleep(3)
56+
57+
display_A.fill(0)
58+
for h in range(4):
59+
display_A.set_digit_raw(h, 0b10000000)
60+
# display_B show maximum heart rate value
61+
display_B.fill(0)
62+
display_B.print(max_rate)
63+
time.sleep(2)
64+
65+
# PyLint can't find BLERadio for some reason so special case it here.
66+
ble = adafruit_ble.BLERadio() # pylint: disable=no-member
67+
68+
hr_connection = None
69+
70+
def display_SCAN():
71+
display_A.fill(0)
72+
display_A.set_digit_raw(0, 0b01101101)
73+
display_A.set_digit_raw(1, 0b00111001)
74+
display_A.set_digit_raw(2, 0b01110111)
75+
display_A.set_digit_raw(3, 0b00110111)
76+
77+
78+
def display_bLE():
79+
display_B.fill(0)
80+
display_B.set_digit_raw(0, 0b00000000)
81+
display_B.set_digit_raw(1, 0b01111100)
82+
display_B.set_digit_raw(2, 0b00111000)
83+
display_B.set_digit_raw(3, 0b01111001)
84+
85+
def display_dots(): # "...."
86+
for j in range(4):
87+
display_A.set_digit_raw(j, 0b10000000)
88+
display_B.set_digit_raw(j, 0b10000000)
89+
90+
def display_dashes(): # "----"
91+
for k in range(4):
92+
display_A.set_digit_raw(k, 0b01000000)
93+
display_B.set_digit_raw(k, 0b01000000)
94+
95+
# Start with a fresh connection.
96+
if ble.connected:
97+
display_SCAN()
98+
display_bLE()
99+
time.sleep(1)
100+
101+
for connection in ble.connections:
102+
if HeartRateService in connection:
103+
connection.disconnect()
104+
break
105+
106+
while True:
107+
print("Scanning...")
108+
red_led.value = True
109+
blue_led.value = False
110+
display_SCAN()
111+
display_bLE()
112+
time.sleep(1)
113+
114+
115+
for adv in ble.start_scan(ProvideServicesAdvertisement, timeout=5):
116+
if HeartRateService in adv.services:
117+
print("found a HeartRateService advertisement")
118+
hr_connection = ble.connect(adv)
119+
display_dots()
120+
time.sleep(2)
121+
print("Connected")
122+
blue_led.value = True
123+
red_led.value = False
124+
break
125+
126+
# Stop scanning whether or not we are connected.
127+
ble.stop_scan()
128+
print("Stopped scan")
129+
red_led.value = False
130+
blue_led.value = True
131+
time.sleep(0.5)
132+
133+
if hr_connection and hr_connection.connected:
134+
print("Fetch connection")
135+
if DeviceInfoService in hr_connection:
136+
dis = hr_connection[DeviceInfoService]
137+
try:
138+
manufacturer = dis.manufacturer
139+
except AttributeError:
140+
manufacturer = "(Manufacturer Not specified)"
141+
try:
142+
model_number = dis.model_number
143+
except AttributeError:
144+
model_number = "(Model number not specified)"
145+
print("Device:", manufacturer, model_number)
146+
else:
147+
print("No device information")
148+
hr_service = hr_connection[HeartRateService]
149+
print("Location:", hr_service.location)
150+
151+
while hr_connection.connected:
152+
values = hr_service.measurement_values
153+
print(values) # returns the full heart_rate data set
154+
if values:
155+
bpm = (values.heart_rate)
156+
if bpm is not 0:
157+
pct_target = (round(100*(bpm/max_rate)))
158+
display_A.fill(0) # clear the display
159+
display_B.fill(0)
160+
if values.heart_rate is 0:
161+
display_dashes()
162+
else:
163+
display_A.fill(0)
164+
display_B.print(pct_target)
165+
time.sleep(0.1)
166+
display_A.print(bpm)
167+
168+
time.sleep(0.9)
169+
display_A.set_digit_raw(0, 0b00000000)

0 commit comments

Comments
 (0)