CircuitPython module for the RFM95/6/7/8 LoRa 433/915mhz radio modules. This is adapted from the Radiohead library RF95 code from: http:

  • Author(s): Tony DiCola, Jerry Needell

class adafruit_rfm9x.RFM9x(spi: SPI, cs: DigitalInOut, reset: DigitalInOut, frequency: int, *, preamble_length: int = 8, high_power: bool = True, baudrate: int = 5000000, agc: bool = False, crc: bool = True)

Interface to a RFM95/6/7/8 LoRa radio module. Allows sending and receiving bytes of data in long range LoRa mode at a support board frequency (433/915mhz).

You must specify the following parameters: - spi: The SPI bus connected to the radio. - cs: The CS pin DigitalInOut connected to the radio. - reset: The reset/RST pin DigialInOut connected to the radio. - frequency: The frequency (in mhz) of the radio module (433/915mhz typically).

You can optionally specify: - preamble_length: The length in bytes of the packet preamble (default 8). - high_power: Boolean to indicate a high power board (RFM95, etc.). Default is True for high power. - baudrate: Baud rate of the SPI connection, default is 10mhz but you might choose to lower to 1mhz if using long wires or a breadboard. - agc: Boolean to Enable/Disable Automatic Gain Control - Default=False (AGC off) - crc: Boolean to Enable/Disable Cyclic Redundancy Check - Default=True (CRC Enabled) 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 defaults and assumes that each packet contains a 4 byte header compatible with RadioHead’s implementation. 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, sender is notified if a packet 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


Automatic Gain Control state

property coding_rate: Literal[5, 6, 7, 8]

The coding rate used by the radio to control forward error correction (try setting to a higher value to increase tolerance of short bursts of interference or to a lower value to increase bit rate). Valid values are limited to 5, 6, 7, or 8.

crc_error() bool

crc status


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 enable_crc: bool

CRC Enable state


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: Literal[433.0, 915.0]

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.

idle() None

Enter idle standby mode.


The RSSI of the last received packet. Stored when the packet was received. The instantaneous RSSI value may not be accurate once the operating mode has been changed.


The SNR of the last received packet. Stored when the packet was received. The instantaneous SNR 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 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 8 to match the RadioHead RFM95 library.

receive(*, keep_listening: bool = True, with_header: bool = False, with_ack: bool = False, timeout: float | None = None) bytearray | None

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 compatibility 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[4]. 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

reset() None

Perform a reset of the chip.

property rssi: int

The received strength indicator (in dBm) of the last received message.

rx_done() bool

Receive status

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 252 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: array | bytearray | bytes | memoryview | rgbmatrix.RGBMatrix | ulab.numpy.ndarray) 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 signal_bandwidth: int

The signal bandwidth used by the radio (try setting to a higher value to increase throughput or to a lower value to increase the likelihood of successfully received payloads). Valid values are listed in RFM9x.bw_bins.

sleep() None

Enter sleep mode.

property snr: float

The SNR (in dB) of the last received message.

property spreading_factor: Literal[6, 7, 8, 9, 10, 11, 12]

The spreading factor used by the radio (try setting to a higher value to increase the receiver’s ability to distinguish signal from noise or to a lower value to increase the data transmission rate). Valid values are limited to 6, 7, 8, 9, 10, 11, or 12.

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 send() instead.

tx_done() bool

Transmit status

property tx_power: int

The transmit power in dBm. Can be set to a value from 5 to 23 for high power devices (RFM95/96/97/98, high_power=True) or -1 to 14 for low power devices. Only integer power levels are actually set (i.e. 12.5 will result in a value of 12 dBm). The actual maximum setting for high_power=True is 20dBm but for values > 20 the PA_BOOST will be enabled resulting in an additional gain of 3dBm. The actual setting is reduced by 3dBm. The reported value will reflect the reduced setting.


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_rfm9x.ticks_diff(ticks1: int, ticks2: int) int

Compute the signed difference between two ticks values assuming that they are within 2**28 ticks