CircuitPython RFM69 packet radio module. This supports basic RadioHead-compatible sending and receiving of packets with RFM69 series radios (433/915Mhz).
This is NOT for LoRa radios!
This is a ‘best effort’ at receiving data using pure Python code–there is not interrupt support so you might lose packets if they’re sent too quickly for the board to process them. You will have the most luck using this in simple low bandwidth scenarios like sending and receiving a 60 byte packet at a time–don’t try to receive many kilobytes of data at a time!
Author(s): Tony DiCola, Jerry Needell
Adafruit RFM69HCW Transceiver Radio Breakout - 868 or 915 MHz - RadioFruit (Product ID: 3070)
Adafruit RFM69HCW Transceiver Radio Breakout - 433 MHz - RadioFruit (Product ID: 3071)
Adafruit Feather M0 RFM69HCW Packet Radio - 868 or 915 MHz - RadioFruit (Product ID: 3176)
Adafruit Feather M0 RFM69HCW Packet Radio - 433 MHz - RadioFruit (Product ID: 3177)
Adafruit Radio FeatherWing - RFM69HCW 900MHz - RadioFruit (Product ID: 3229)
Adafruit Radio FeatherWing - RFM69HCW 433MHz - RadioFruit (Product ID: 3230)
Software and Dependencies:
Adafruit CircuitPython firmware for the ESP8622 and M0-based boards: https://github.com/adafruit/circuitpython/releases
Adafruit’s Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
- class adafruit_rfm69.RFM69(spi: SPI, cs: DigitalInOut, reset: DigitalInOut, frequency: int, *, sync_word: bytes = b'-\xd4', preamble_length: int = 4, encryption_key: bytes | None = None, high_power: bool = True, baudrate: int = 2000000)¶
Interface to a RFM69 series packet radio. Allows simple sending and receiving of wireless data at supported frequencies of the radio (433/915mhz).
spi (busio.SPI) – The SPI bus connected to the chip. Ensure SCK, MOSI, and MISO are connected.
cs (DigitalInOut) – A DigitalInOut object connected to the chip’s CS/chip select line.
reset (DigitalInOut) – A DigitalInOut object connected to the chip’s RST/reset line.
frequency (int) – The center frequency to configure for radio transmission and reception. Must be a frequency supported by your hardware (i.e. either 433 or 915mhz).
sync_word (bytes) – A byte string up to 8 bytes long which represents the syncronization word used by received and transmitted packets. Read the datasheet for a full understanding of this value! However by default the library will set a value that matches the RadioHead Arduino library.
preamble_length (int) – The number of bytes to pre-pend to a data packet as a preamble. This is by default 4 to match the RadioHead library.
encryption_key (bytes) – A 16 byte long string that represents the AES encryption key to use when encrypting and decrypting packets. Both the transmitter and receiver MUST have the same key value! By default no encryption key is set or used.
high_power (bool) – Indicate if the chip is a high power variant that supports boosted transmission power. The default is True as it supports the common RFM69HCW modules sold by Adafruit.
The D0/interrupt line is currently unused by this module and can remain unconnected.
Remember this library makes a best effort at receiving packets with pure Python code. Trying to receive packets too quickly will result in lost data so limit yourself to simple scenarios of sending and receiving single packets at a time.
Also note this library tries to be compatible with raw RadioHead Arduino library communication. This means the library sets up the radio modulation to match RadioHead’s default of GFSK encoding, 250kbit/s bitrate, and 250khz frequency deviation. To change this requires explicitly setting the radio’s bitrate and encoding register bits. Read the datasheet and study the init function to see an example of this–advanced users only! Advanced RadioHead features like address/node specific packets or “reliable datagram” delivery are supported however due to the limitations noted, “reliable datagram” is still subject to missed packets but with it, the sender is notified if a packe has potentially been missed.
The delay time before attemting to send an ACK. If ACKs are being missed try setting this to .1 or .2.
The number of ACK retries before reporting a failure.
The delay time before attempting a retry after not receiving an ACK
- property bitrate: float¶
The modulation bitrate in bits/second (or chip rate if Manchester encoding is enabled). Can be a value from ~489 to 32mbit/s, but see the datasheet for the exact supported values.
The default destination address for packet transmissions. (0-255). If 255 (0xff) then any receiving node should accept the packet. Second byte of the RadioHead header.
- property encryption_key: bytearray¶
The AES encryption key used to encrypt and decrypt packets by the chip. This can be set to None to disable encryption (the default), otherwise it must be a 16 byte long byte string which defines the key (both the transmitter and receiver must use the same key value).
Upper 4 bits reserved for use by Reliable Datagram Mode. Lower 4 bits may be used to pass information. Fourth byte of the RadioHead header.
- property frequency_mhz: float¶
The frequency of the radio in Megahertz. Only the allowed values for your radio must be specified (i.e. 433 vs. 915 mhz)!
Automatically set to the sequence number when send_with_ack() used. Third byte of the RadioHead header.
The RSSI of the last received packet. Stored when the packet was received. This instantaneous RSSI value may not be accurate once the operating mode has been changed.
- listen() None ¶
Listen for packets to be received by the chip. Use
receive()to listen, wait and retrieve packets as they’re available.
The default address of this Node. (0-255). If not 255 (0xff) then only packets address to this node will be accepted. First byte of the RadioHead header.
- property operation_mode: int¶
The operation mode value. Unless you’re manually controlling the chip you shouldn’t change the operation_mode with this property as other side-effects are required for changing logical modes–use
listen()instead to signal intent for explicit logical modes.
- property preamble_length: int¶
The length of the preamble for sent and received packets, an unsigned 16-bit value. Received packets must match this length or they are ignored! Set to 4 to match the RadioHead RFM69 library.
- receive(*, keep_listening: bool = True, with_ack: bool = False, timeout: float | None = None, with_header: bool = False) int ¶
Wait to receive a packet from the receiver. If a packet is found the payload bytes are returned, otherwise None is returned (which indicates the timeout elapsed with no reception). If keep_listening is True (the default) the chip will immediately enter listening mode after reception of a packet, otherwise it will fall back to idle mode and ignore any future reception. All packets must have a 4 byte header for compatibilty with the RadioHead library. The header consists of 4 bytes (To,From,ID,Flags). The default setting will strip the header before returning the packet to the caller. If with_header is True then the 4 byte header will be returned with the packet. The payload then begins at packet. If with_ack is True, send an ACK after receipt (Reliable Datagram mode)
The amount of time to poll for a received packet. If no packet is received, the returned packet will be None
- property rssi: float¶
The received strength indicator (in dBm). May be inaccuate if not read immediatey. last_rssi contains the value read immediately receipt of the last packet.
- send(data: array | bytearray | bytes | memoryview | rgbmatrix.RGBMatrix | ulab.numpy.ndarray, *, keep_listening: bool = False, destination: int | None = None, node: int | None = None, identifier: int | None = None, flags: int | None = None) bool ¶
Send a string of data using the transmitter. You can only send 60 bytes at a time (limited by chip’s FIFO size and appended headers). This appends a 4 byte header to be compatible with the RadioHead library. The header defaults to using the initialized attributes: (destination,node,identifier,flags) It may be temporarily overidden via the kwargs - destination,node,identifier,flags. Values passed via kwargs do not alter the attribute settings. The keep_listening argument should be set to True if you want to start listening automatically after the packet is sent. The default setting is False.
Returns: True if success or False if the send timed out.
- send_with_ack(data: int) bool ¶
Reliable Datagram mode: Send a packet with data and wait for an ACK response. The packet header is automatically generated. If enabled, the packet transmission will be retried on failure
- property sync_word: bytearray¶
The synchronization word value. This is a byte string up to 8 bytes long (64 bits) which indicates the synchronization word for transmitted and received packets. Any received packet which does not include this sync word will be ignored. The default value is 0x2D, 0xD4 which matches the RadioHead RFM69 library. Setting a value of None will disable synchronization word matching entirely.
- property temperature: float¶
The internal temperature of the chip in degrees Celsius. Be warned this is not calibrated or very accurate.
Reading this will STOP any receiving/sending that might be happening!
- transmit() None ¶
Transmit a packet which is queued in the FIFO. This is a low level function for entering transmit mode and more. For generating and transmitting a packet of data use
- property tx_power: int¶
The transmit power in dBm. Can be set to a value from -2 to 20 for high power devices (RFM69HCW, high_power=True) or -18 to 13 for low power devices. Only integer power levels are actually set (i.e. 12.5 will result in a value of 12 dBm).
The amount of time to wait for the HW to transmit the packet. This is mainly used to prevent a hang due to a HW issue
- adafruit_rfm69.check_timeout(flag: Callable, limit: float) bool ¶
test for timeout waiting for specified flag