Skip to content

Commit 15d739a

Browse files
Merge branch 'adafruit:main' into main
2 parents 7715542 + 75d867c commit 15d739a

23 files changed

Lines changed: 417 additions & 90 deletions

File tree

BLE_Colorific/colorific.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929

3030
# Get bulb address from command parameters.
3131
if len(sys.argv) != 2:
32-
print 'Error must specify bulb address as parameter!'
33-
print 'Usage: sudo python colorific.py <bulb address>'
34-
print 'Example: sudo python colorific.py 5C:31:3E:F2:16:13'
32+
print ('Error must specify bulb address as parameter!')
33+
print ('Usage: sudo python colorific.py <bulb address>')
34+
print ('Example: sudo python colorific.py 5C:31:3E:F2:16:13')
3535
sys.exit(1)
3636
bulb = sys.argv[1]
3737

@@ -47,7 +47,7 @@
4747
hue = hue_min
4848

4949
# Enter main loop.
50-
print 'Press Ctrl-C to quit.'
50+
print ('Press Ctrl-C to quit.')
5151
last = time.time()
5252
while True:
5353
# Get amount of time elapsed since last update, then compute hue delta.

BLE_Colorific/flux.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030

3131
# Get bulb address from command parameters.
3232
if len(sys.argv) != 2:
33-
print 'Error must specify bulb address as parameter!'
34-
print 'Usage: sudo python colorific.py <bulb address>'
35-
print 'Example: sudo python colorific.py 5C:31:3E:F2:16:13'
33+
print ('Error must specify bulb address as parameter!')
34+
print ('Usage: sudo python colorific.py <bulb address>')
35+
print ('Example: sudo python colorific.py 5C:31:3E:F2:16:13')
3636
sys.exit(1)
3737
bulb = sys.argv[1]
3838

@@ -48,7 +48,7 @@
4848
hue = hue_min
4949

5050
# Enter main loop.
51-
print 'Press Ctrl-C to quit.'
51+
print ('Press Ctrl-C to quit.')
5252
last = time.time()
5353
while True:
5454
# Get amount of time elapsed since last update, then compute hue delta.
@@ -64,7 +64,7 @@
6464
# Set light color by sending color change packet over BLE.
6565
# 56RRGGBB00f0aa
6666
line = 'char-write-cmd 0x002e 56{0:02X}{1:02X}{2:02X}00f0aa'.format(r, g, b)
67-
print line
67+
print (line)
6868
gatt.sendline(line)
6969
# Wait a short period of time and setup for the next loop iteration.
7070
time.sleep(SLEEP_SEC)

CircuitPython_Templates/audio_find_pins/code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def get_unique_pins():
3131
"DOTSTAR_DATA",
3232
"APA102_SCK",
3333
"APA102_MOSI",
34-
"L",
34+
"LED",
3535
"SWITCH",
3636
"BUTTON",
3737
]

CircuitPython_Templates/cap_touch_pin_script/.circuitpython.skip

Lines changed: 0 additions & 1 deletion
This file was deleted.

CircuitPython_Templates/cap_touch_pin_script/code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def is_touch_capable(pin_name):
1717
else:
1818
return False # Otherwise, the pins are invalid.
1919
except TypeError: # Error returned when checking a non-pin object in dir(board).
20-
pass # Passes over non-pin objects in dir(board).
20+
return False # Invalid if non-pin objects in dir(board).
2121

2222

2323
def get_pin_names():

CircuitPython_Templates/i2c_find_pins/code.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,27 @@ def is_hardware_i2c(scl, sda):
1616

1717

1818
def get_unique_pins():
19-
exclude = ['NEOPIXEL', 'APA102_MOSI', 'APA102_SCK']
20-
pins = [pin for pin in [
21-
getattr(board, p) for p in dir(board) if p not in exclude]
22-
if isinstance(pin, Pin)]
19+
exclude = [
20+
getattr(board, p)
21+
for p in [
22+
# This is not an exhaustive list of unexposed pins. Your results
23+
# may include other pins that you cannot easily connect to.
24+
"NEOPIXEL",
25+
"DOTSTAR_CLOCK",
26+
"DOTSTAR_DATA",
27+
"APA102_SCK",
28+
"APA102_MOSI",
29+
"LED",
30+
"SWITCH",
31+
"BUTTON",
32+
]
33+
if p in dir(board)
34+
]
35+
pins = [
36+
pin
37+
for pin in [getattr(board, p) for p in dir(board)]
38+
if isinstance(pin, Pin) and pin not in exclude
39+
]
2340
unique = []
2441
for p in pins:
2542
if p not in unique:
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
"""
2+
CircuitPython I2S Pin Combination Identification Script
3+
"""
4+
import board
5+
import audiobusio
6+
from microcontroller import Pin
7+
8+
9+
def is_hardware_i2s(bit_clock, word_select, data):
10+
try:
11+
p = audiobusio.I2SOut(bit_clock, word_select, data)
12+
p.deinit()
13+
return True
14+
except ValueError:
15+
return False
16+
17+
18+
def get_unique_pins():
19+
exclude = [
20+
getattr(board, p)
21+
for p in [
22+
# This is not an exhaustive list of unexposed pins. Your results
23+
# may include other pins that you cannot easily connect to.
24+
"NEOPIXEL",
25+
"DOTSTAR_CLOCK",
26+
"DOTSTAR_DATA",
27+
"APA102_SCK",
28+
"APA102_MOSI",
29+
"LED",
30+
"SWITCH",
31+
"BUTTON",
32+
]
33+
if p in dir(board)
34+
]
35+
pins = [
36+
pin
37+
for pin in [getattr(board, p) for p in dir(board)]
38+
if isinstance(pin, Pin) and pin not in exclude
39+
]
40+
unique = []
41+
for p in pins:
42+
if p not in unique:
43+
unique.append(p)
44+
return unique
45+
46+
47+
for bit_clock_pin in get_unique_pins():
48+
for word_select_pin in get_unique_pins():
49+
for data_pin in get_unique_pins():
50+
if bit_clock_pin is word_select_pin or bit_clock_pin is data_pin or word_select_pin \
51+
is data_pin:
52+
continue
53+
if is_hardware_i2s(bit_clock_pin, word_select_pin, data_pin):
54+
print("Bit clock pin:", bit_clock_pin, "\t Word select pin:", word_select_pin,
55+
"\t Data pin:", data_pin)
56+
else:
57+
pass
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""
2+
CircuitPython I2S MP3 playback example.
3+
Plays an MP3 once.
4+
5+
Remove this line and all of the following docstring content before submitting to the Learn repo.
6+
7+
Update the three I2S pins to match the wiring chosen for the microcontroller. If you are unsure of
8+
a proper I2S pin combination, run the pin combination script found here:
9+
https://adafru.it/i2s-pin-combo-finder
10+
11+
Update the following pin names to a viable pin combination:
12+
* BIT_CLOCK_PIN
13+
* WORD_SELECT_PIN
14+
* DATA_PIN
15+
"""
16+
import board
17+
import audiomp3
18+
import audiobusio
19+
20+
audio = audiobusio.I2SOut(board.BIT_CLOCK_PIN, board.WORD_SELECT_PIN, board.DATA_PIN)
21+
22+
mp3 = audiomp3.MP3Decoder(open("slow.mp3", "rb"))
23+
24+
audio.play(mp3)
25+
while audio.playing:
26+
pass
27+
28+
print("Done playing!")
12.4 KB
Binary file not shown.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""
2+
CircuitPython I2S Tone playback example.
3+
Plays a tone for one second on, one
4+
second off, in a loop.
5+
6+
Remove this line and all of the following docstring content before submitting to the Learn repo.
7+
8+
Update the three I2S pins to match the wiring chosen for the microcontroller. If you are unsure of
9+
a proper I2S pin combination, run the pin combination script found here:
10+
https://adafru.it/i2s-pin-combo-finder
11+
12+
Update the following pin names to a viable pin combination:
13+
* BIT_CLOCK_PIN
14+
* WORD_SELECT_PIN
15+
* DATA_PIN
16+
"""
17+
import time
18+
import array
19+
import math
20+
import audiocore
21+
import board
22+
import audiobusio
23+
24+
audio = audiobusio.I2SOut(board.BIT_CLOCK_PIN, board.WORD_SELECT_PIN, board.DATA_PIN)
25+
26+
tone_volume = 0.1 # Increase this to increase the volume of the tone.
27+
frequency = 440 # Set this to the Hz of the tone you want to generate.
28+
length = 8000 // frequency
29+
sine_wave = array.array("h", [0] * length)
30+
for i in range(length):
31+
sine_wave[i] = int((math.sin(math.pi * 2 * i / length)) * tone_volume * (2 ** 15 - 1))
32+
sine_wave_sample = audiocore.RawSample(sine_wave)
33+
34+
while True:
35+
audio.play(sine_wave_sample, loop=True)
36+
time.sleep(1)
37+
audio.stop()
38+
time.sleep(1)

0 commit comments

Comments
 (0)