Skip to content

Commit d74e01f

Browse files
authored
Merge pull request #2473 from kattni/feather-rp2040-rfm-dvi
Adding Templated Essentials code for RP4040 RFM and DVI Feathers.
2 parents e3d4a71 + e6d5615 commit d74e01f

File tree

15 files changed

+375
-2
lines changed

15 files changed

+375
-2
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# SPDX-FileCopyrightText: 2023 Kattni Rembor for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
"""
4+
CircuitPython I2S Tone playback example.
5+
Plays a tone for one second on, one second off, in a loop.
6+
"""
7+
import time
8+
import array
9+
import math
10+
import audiocore
11+
import board
12+
import audiobusio
13+
14+
audio = audiobusio.I2SOut(board.A0, board.A1, board.A2)
15+
16+
tone_volume = 0.1 # Increase this to increase the volume of the tone.
17+
frequency = 440 # Set this to the Hz of the tone you want to generate.
18+
length = 8000 // frequency
19+
sine_wave = array.array("h", [0] * length)
20+
for i in range(length):
21+
sine_wave[i] = int((math.sin(math.pi * 2 * i / length)) * tone_volume * (2 ** 15 - 1))
22+
sine_wave_sample = audiocore.RawSample(sine_wave)
23+
24+
while True:
25+
audio.play(sine_wave_sample, loop=True)
26+
time.sleep(1)
27+
audio.stop()
28+
time.sleep(1)
Binary file not shown.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# SPDX-FileCopyrightText: 2023 Kattni Rembor for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
"""
4+
CircuitPython I2S WAV file playback.
5+
Plays a WAV file once.
6+
"""
7+
import audiocore
8+
import board
9+
import audiobusio
10+
11+
audio = audiobusio.I2SOut(board.A0, board.A1, board.A2)
12+
13+
with open("StreetChicken.wav", "rb") as wave_file:
14+
wav = audiocore.WaveFile(wave_file)
15+
16+
print("Playing wav file!")
17+
audio.play(wav)
18+
while audio.playing:
19+
pass
20+
21+
print("Done!")
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# SPDX-FileCopyrightText: 2023 Kattni Rembor for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
"""
4+
CircuitPython Essentials Storage CP Filesystem boot.py file
5+
"""
6+
import board
7+
import digitalio
8+
import storage
9+
10+
button = digitalio.DigitalInOut(board.BUTTON)
11+
button.switch_to_input(pull=digitalio.Pull.UP)
12+
13+
# If the button is connected to ground, the filesystem is writable by CircuitPython
14+
storage.remount("/", readonly=button.value)
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2022 Dan Halbert for Adafruit Industries
2+
# SPDX-FileCopyrightText: Copyright (c) 2023 Kattni Rembor for Adafruit Industries
3+
#
4+
# SPDX-License-Identifier: MIT
5+
"""
6+
CircuitPython asyncio example for two NeoPixel rings and one button.
7+
"""
8+
import asyncio
9+
import board
10+
import neopixel
11+
import keypad
12+
from rainbowio import colorwheel
13+
14+
button_pin = board.BUTTON # The pin the button is connected to.
15+
num_pixels = 16 # The number of NeoPixels on a single ring.
16+
brightness = 0.2 # The LED brightness.
17+
18+
# Set up NeoPixel rings.
19+
ring_one = neopixel.NeoPixel(board.A1, num_pixels, brightness=brightness, auto_write=False)
20+
ring_two = neopixel.NeoPixel(board.A2, num_pixels, brightness=brightness, auto_write=False)
21+
22+
23+
class AnimationControls:
24+
"""The controls to allow you to vary the rainbow and blink animations."""
25+
def __init__(self):
26+
self.reverse = False
27+
self.wait = 0.0
28+
self.delay = 0.5
29+
30+
31+
async def rainbow_cycle(controls):
32+
"""Rainbow cycle animation on ring one."""
33+
while True:
34+
for j in range(255, -1, -1) if controls.reverse else range(0, 256, 1):
35+
for i in range(num_pixels):
36+
rc_index = (i * 256 // num_pixels) + j
37+
ring_one[i] = colorwheel(rc_index & 255)
38+
ring_one.show()
39+
await asyncio.sleep(controls.wait)
40+
41+
42+
async def blink(controls):
43+
"""Blink animation on ring two."""
44+
while True:
45+
ring_two.fill((0, 0, 255))
46+
ring_two.show()
47+
await asyncio.sleep(controls.delay)
48+
ring_two.fill((0, 0, 0))
49+
ring_two.show()
50+
await asyncio.sleep(controls.delay)
51+
await asyncio.sleep(controls.wait)
52+
53+
54+
async def monitor_button(button, controls):
55+
"""Monitor button that reverses rainbow direction and changes blink speed.
56+
Assume button is active low.
57+
"""
58+
with keypad.Keys((button,), value_when_pressed=False, pull=True) as key:
59+
while True:
60+
key_event = key.events.get()
61+
if key_event:
62+
if key_event.pressed:
63+
controls.reverse = True
64+
controls.delay = 0.1
65+
elif key_event.released:
66+
controls.reverse = False
67+
controls.delay = 0.5
68+
await asyncio.sleep(0)
69+
70+
71+
async def main():
72+
animation_controls = AnimationControls()
73+
button_task = asyncio.create_task(monitor_button(button_pin, animation_controls))
74+
animation_task = asyncio.create_task(rainbow_cycle(animation_controls))
75+
blink_task = asyncio.create_task(blink(animation_controls))
76+
77+
# This will run forever, because no tasks ever finish.
78+
await asyncio.gather(button_task, animation_task, blink_task)
79+
80+
asyncio.run(main())
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# SPDX-FileCopyrightText: 2023 Kattni Rembor for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
"""
4+
CircuitPython Capacitive Touch Pin Example - Print to the serial console when one pin is touched.
5+
"""
6+
import time
7+
import board
8+
import touchio
9+
10+
touch = touchio.TouchIn(board.A3)
11+
12+
while True:
13+
if touch.value:
14+
print("Pin touched!")
15+
time.sleep(0.1)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# SPDX-FileCopyrightText: 2023 Kattni Rembor for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
"""
4+
CircuitPython Capacitive Two Touch Pin Example - Print to the serial console when a pin is touched.
5+
"""
6+
import time
7+
import board
8+
import touchio
9+
10+
touch_one = touchio.TouchIn(board.A3)
11+
touch_two = touchio.TouchIn(board.D24)
12+
13+
while True:
14+
if touch_one.value:
15+
print("Pin one touched!")
16+
if touch_two.value:
17+
print("Pin two touched!")
18+
time.sleep(0.1)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# SPDX-FileCopyrightText: 2023 Kattni Rembor for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
"""
4+
CircuitPython I2S Tone playback example.
5+
Plays a tone for one second on, one
6+
second off, in a loop.
7+
"""
8+
import time
9+
import array
10+
import math
11+
import audiocore
12+
import board
13+
import audiobusio
14+
15+
audio = audiobusio.I2SOut(board.A0, board.A1, board.A2)
16+
17+
tone_volume = 0.1 # Increase this to increase the volume of the tone.
18+
frequency = 440 # Set this to the Hz of the tone you want to generate.
19+
length = 8000 // frequency
20+
sine_wave = array.array("h", [0] * length)
21+
for i in range(length):
22+
sine_wave[i] = int((math.sin(math.pi * 2 * i / length)) * tone_volume * (2 ** 15 - 1))
23+
sine_wave_sample = audiocore.RawSample(sine_wave)
24+
25+
while True:
26+
audio.play(sine_wave_sample, loop=True)
27+
time.sleep(1)
28+
audio.stop()
29+
time.sleep(1)
Binary file not shown.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# SPDX-FileCopyrightText: 2023 Kattni Rembor for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
"""
4+
CircuitPython I2S WAV file playback.
5+
Plays a WAV file once.
6+
"""
7+
import audiocore
8+
import board
9+
import audiobusio
10+
11+
audio = audiobusio.I2SOut(board.A0, board.A1, board.A2)
12+
13+
with open("StreetChicken.wav", "rb") as wave_file:
14+
wav = audiocore.WaveFile(wave_file)
15+
16+
print("Playing wav file!")
17+
audio.play(wav)
18+
while audio.playing:
19+
pass
20+
21+
print("Done!")
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# SPDX-FileCopyrightText: 2023 Kattni Rembor for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
"""
4+
CircuitPython Essentials Storage CP Filesystem boot.py file
5+
"""
6+
import board
7+
import digitalio
8+
import storage
9+
10+
button = digitalio.DigitalInOut(board.BUTTON)
11+
button.switch_to_input(pull=digitalio.Pull.UP)
12+
13+
# If the OBJECT_NAME is connected to ground, the filesystem is writable by CircuitPython
14+
storage.remount("/", readonly=button.value)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# SPDX-FileCopyrightText: 2023 Kattni Rembor for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
"""
4+
CircuitPython Essentials Storage CP Filesystem code.py file
5+
"""
6+
import time
7+
import board
8+
import digitalio
9+
import microcontroller
10+
11+
led = digitalio.DigitalInOut(board.LED)
12+
led.switch_to_output()
13+
14+
try:
15+
with open("/temperature.txt", "a") as temp_log:
16+
while True:
17+
# The microcontroller temperature in Celsius. Include the
18+
# math to do the C to F conversion here, if desired.
19+
temperature = microcontroller.cpu.temperature
20+
21+
# Write the temperature to the temperature.txt file every 10 seconds.
22+
temp_log.write('{0:.2f}\n'.format(temperature))
23+
temp_log.flush()
24+
25+
# Blink the LED on every write...
26+
led.value = True
27+
time.sleep(1) # ...for one second.
28+
led.value = False # Then turn it off...
29+
time.sleep(9) # ...for the other 9 seconds.
30+
31+
except OSError as e: # When the filesystem is NOT writable by CircuitPython...
32+
delay = 0.5 # ...blink the LED every half second.
33+
if e.args[0] == 28: # If the file system is full...
34+
delay = 0.15 # ...blink the LED every 0.15 seconds!
35+
while True:
36+
led.value = not led.value
37+
time.sleep(delay)
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2022 Dan Halbert for Adafruit Industries
2+
# SPDX-FileCopyrightText: Copyright (c) 2023 Kattni Rembor for Adafruit Industries
3+
#
4+
# SPDX-License-Identifier: MIT
5+
"""
6+
CircuitPython asyncio example for two NeoPixel rings and one button.
7+
"""
8+
import asyncio
9+
import board
10+
import neopixel
11+
import keypad
12+
from rainbowio import colorwheel
13+
14+
button_pin = board.BUTTON # The pin the button is connected to.
15+
num_pixels = 16 # The number of NeoPixels on a single ring.
16+
brightness = 0.2 # The LED brightness.
17+
18+
# Set up NeoPixel rings.
19+
ring_one = neopixel.NeoPixel(board.A1, num_pixels, brightness=brightness, auto_write=False)
20+
ring_two = neopixel.NeoPixel(board.A2, num_pixels, brightness=brightness, auto_write=False)
21+
22+
23+
class AnimationControls:
24+
"""The controls to allow you to vary the rainbow and blink animations."""
25+
def __init__(self):
26+
self.reverse = False
27+
self.wait = 0.0
28+
self.delay = 0.5
29+
30+
31+
async def rainbow_cycle(controls):
32+
"""Rainbow cycle animation on ring one."""
33+
while True:
34+
for j in range(255, -1, -1) if controls.reverse else range(0, 256, 1):
35+
for i in range(num_pixels):
36+
rc_index = (i * 256 // num_pixels) + j
37+
ring_one[i] = colorwheel(rc_index & 255)
38+
ring_one.show()
39+
await asyncio.sleep(controls.wait)
40+
41+
42+
async def blink(controls):
43+
"""Blink animation on ring two."""
44+
while True:
45+
ring_two.fill((0, 0, 255))
46+
ring_two.show()
47+
await asyncio.sleep(controls.delay)
48+
ring_two.fill((0, 0, 0))
49+
ring_two.show()
50+
await asyncio.sleep(controls.delay)
51+
await asyncio.sleep(controls.wait)
52+
53+
54+
async def monitor_button(button, controls):
55+
"""Monitor button that reverses rainbow direction and changes blink speed.
56+
Assume button is active low.
57+
"""
58+
with keypad.Keys((button,), value_when_pressed=False, pull=True) as key:
59+
while True:
60+
key_event = key.events.get()
61+
if key_event:
62+
if key_event.pressed:
63+
controls.reverse = True
64+
controls.delay = 0.1
65+
elif key_event.released:
66+
controls.reverse = False
67+
controls.delay = 0.5
68+
await asyncio.sleep(0)
69+
70+
71+
async def main():
72+
animation_controls = AnimationControls()
73+
button_task = asyncio.create_task(monitor_button(button_pin, animation_controls))
74+
animation_task = asyncio.create_task(rainbow_cycle(animation_controls))
75+
blink_task = asyncio.create_task(blink(animation_controls))
76+
77+
# This will run forever, because no tasks ever finish.
78+
await asyncio.gather(button_task, animation_task, blink_task)
79+
80+
asyncio.run(main())

CircuitPython_Templates/cap_touch_pin_script/code.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
1+
# SPDX-FileCopyrightText: 2021-2023 Kattni Rembor for Adafruit Industries
22
# SPDX-License-Identifier: MIT
33
"""
44
CircuitPython Touch-Compatible Pin Identification Script
@@ -45,6 +45,14 @@ def get_pin_names():
4545
"ACCELEROMETER_SCL",
4646
"MICROPHONE_CLOCK",
4747
"MICROPHONE_DATA",
48+
"RFM_RST",
49+
"RFM_CS",
50+
"RFM_IO0",
51+
"RFM_IO1",
52+
"RFM_IO2",
53+
"RFM_IO3",
54+
"RFM_IO4",
55+
"RFM_IO5",
4856
]
4957
pins = [
5058
pin

0 commit comments

Comments
 (0)