Skip to content

Commit 00e4481

Browse files
committed
Add RFM69 send and receive demos.
1 parent 2fbba95 commit 00e4481

File tree

2 files changed

+92
-0
lines changed
  • Adafruit_Feather_RP2040_RFM69/Send_and_Receive_Demo

2 files changed

+92
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# SPDX-FileCopyrightText: 2023 Kattni Rembor for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
4+
"""
5+
CircuitPython Feather RP2040 RFM69 Packet Receive Demo
6+
7+
This demo waits for a "button" packet. When the first packet is received, the NeoPixel LED
8+
lights up red. The next packet changes it to green. The next packet changes it to blue.
9+
Subsequent button packets cycle through the same colors in the same order.
10+
11+
This example is meant to be paired with the Packet Send Demo code running
12+
on a second Feather RP2040 RFM69 board.
13+
"""
14+
15+
import board
16+
import digitalio
17+
import neopixel
18+
import adafruit_rfm69
19+
20+
# Set up NeoPixel.
21+
pixel = neopixel.NeoPixel(board.NEOPIXEL, 1)
22+
pixel.brightness = 0.5
23+
24+
# Define the possible NeoPixel colors. You can add as many colors to this list as you like!
25+
# Simply follow the format shown below. Make sure you include the comma after the color tuple!
26+
color_values = [
27+
(255, 0, 0),
28+
(0, 255, 0),
29+
(0, 0, 255),
30+
]
31+
32+
# Define radio frequency in MHz. Must match your
33+
# module. Can be a value like 915.0, 433.0, etc.
34+
RADIO_FREQ_MHZ = 915.0
35+
36+
# Define Chip Select and Reset pins for the radio module.
37+
CS = digitalio.DigitalInOut(board.RFM_CS)
38+
RESET = digitalio.DigitalInOut(board.RFM_RST)
39+
40+
# Initialise RFM69 radio
41+
rfm69 = adafruit_rfm69.RFM69(board.SPI(), CS, RESET, RADIO_FREQ_MHZ)
42+
43+
color_index = 0
44+
# Wait to receive packets.
45+
print("Waiting for packets...")
46+
while True:
47+
# Look for a new packet - wait up to 5 seconds:
48+
packet = rfm69.receive(timeout=5.0)
49+
# If no packet was received during the timeout then None is returned.
50+
if packet is not None:
51+
print("Received a packet!")
52+
# If the received packet is b'button'...
53+
if packet == b'button':
54+
# ...cycle the NeoPixel LED color through the color_values list.
55+
pixel.fill(color_values[color_index])
56+
color_index = (color_index + 1) % len(color_values)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# SPDX-FileCopyrightText: 2023 Kattni Rembor for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
4+
"""
5+
CircuitPython Feather RP2040 RFM69 Packet Send Demo
6+
7+
This demo sends a "button" packet when the Boot button is pressed.
8+
9+
This example is meant to be paired with the Packet Receive Demo code running
10+
on a second Feather RP2040 RFM69 board.
11+
"""
12+
13+
import board
14+
import digitalio
15+
import keypad
16+
import adafruit_rfm69
17+
18+
# Set up button using keypad module.
19+
button = keypad.Keys((board.BUTTON,), value_when_pressed=False)
20+
21+
# Define radio frequency in MHz. Must match your
22+
# module. Can be a value like 915.0, 433.0, etc.
23+
RADIO_FREQ_MHZ = 915.0
24+
25+
# Define Chip Select and Reset pins for the radio module.
26+
CS = digitalio.DigitalInOut(board.RFM_CS)
27+
RESET = digitalio.DigitalInOut(board.RFM_RST)
28+
29+
# Initialise RFM69 radio
30+
rfm69 = adafruit_rfm69.RFM69(board.SPI(), CS, RESET, RADIO_FREQ_MHZ)
31+
32+
while True:
33+
button_press = button.events.get()
34+
if button_press:
35+
if button_press.pressed:
36+
rfm69.send(bytes("button", "UTF-8"))

0 commit comments

Comments
 (0)