The Challenger RP2040 SubGHz boards also have their own Circuitpython image that when downloaded and flashed can be very easily used to send and receive data packets. The image already have the Adafruit RFM69 python library built in so creating your apps couldn’t be simpler.
Below is an example of sending and receiving data from point to point between two devices.
NOTE ! – This example is not applicable for the LoRa boards. If you were looking for examples on how to use Circuitpython with our LoRa boards please check here.
# SPDX-FileCopyrightText: 2020 Jerry Needell for Adafruit Industries
# SPDX-License-Identifier: MIT
# Modified 2022 to directly work with Challenger RP2040 SubGHz boards
# Example to send a packet periodically between addressed nodes
import time
import board
import busio
import digitalio
import adafruit_rfm69
# set the time interval (seconds) for sending packets
transmit_interval = 10
# Define radio parameters.
RADIO_FREQ_MHZ = 868.0 # Frequency of the radio in Mhz. Must match your
# module! Can be a value like 915.0, 433.0, etc.
# Define pins connected to the chip.
CS = digitalio.DigitalInOut(board.RFM69HCW_CS)
RESET = digitalio.DigitalInOut(board.RFM69HCW_RST)
# Initialize SPI bus.
spi = busio.SPI(board.RFM69HCW_SCK, MOSI=board.RFM69HCW_SDO, MISO=board.RFM69HCW_SDI)
# Initialze RFM radio
rfm69 = adafruit_rfm69.RFM69(spi, CS, RESET, RADIO_FREQ_MHZ)
# Optionally set an encryption key (16 byte AES key). MUST match both
# on the transmitter and receiver (or be set to None to disable/the default).
rfm69.encryption_key = (
b"\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
)
# set node addresses
rfm69.node = 1
rfm69.destination = 2
# initialize counter
counter = 0
# send a broadcast message from my_node with ID = counter
rfm69.send(
bytes("Startup message {} from node {}".format(counter, rfm69.node), "UTF-8")
)
# Wait to receive packets.
print("Waiting for packets...")
now = time.monotonic()
while True:
# Look for a new packet: only accept if addresses to my_node
packet = rfm69.receive(with_header=True)
# If no packet was received during the timeout then None is returned.
if packet is not None:
# Received a packet!
# Print out the raw bytes of the packet:
print("Received (raw header):", [hex(x) for x in packet[0:4]])
print("Received (raw payload): {0}".format(packet[4:]))
print("Received RSSI: {0}".format(rfm69.last_rssi))
if time.monotonic() - now > transmit_interval:
now = time.monotonic()
counter = counter + 1
# send a mesage to destination_node from my_node
rfm69.send(
bytes(
"message number {} from node {}".format(counter, rfm69.node), "UTF-8"
),
keep_listening=True,
)
button_pressed = None
Documentation on how to use the Adafruit RFM69 library can be found here https://docs.circuitpython.org/projects/rfm69/en/latest/api.html
0 Comments for “Using Circuitpython on the Challenger RP2040 SubGHz to send and receive data packets.”