One of the factors that limits the reliability of packet transmission and receipt using CircuitPython is the current lack of support for "interrupts". This means that the library can only "poll" for available packets and there are significant time gaps when the code is switching between transmit and receive. Packets can be missed during these transitions. Using the Reliable Datagram mode should help, but even with that there are cases when the timing just does not work well. There are several parameters that can be adjusted to help minimize the likelihood of a missed packet.

These parameters are noted here for the RFM9x and here for the RFM69. The RFM9x is used as an example below,  but the parameters are the same for the RFM69.

If you are having trouble receiving the ACK packets from the the recipient, it may be helpful to enable a delay between receipt of the packet and transmission of the ACK packet.

This is done via the ack_delay attribute. The default setting is None so the ACK packet is sent as quickly as possible. This may be too fast for some systems, especially when using a Raspberry Pi where there can be delays associated with the operating system.

A delay of 0.1 seconds was used in the Reliable Datagram examples:

Download: file
# Initialize SPI bus.
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
# Initialze RFM radio
rfm9x = adafruit_rfm9x.RFM9x(spi, CS, RESET, RADIO_FREQ_MHZ)

# enable CRC checking
rfm9x.enable_crc = True
# set delay before transmitting ACK (seconds)
rfm9x.ack_delay = 0.1
# set node addresses
rfm9x.node = 2
rfm9x.destination = 1

Other parameters that may be useful to adjust are:

  • rfm9x.ack_wait (defaults to 0.5ms)
    • This sets the delay before retrying transmission of a packet after no ACK has been received.
  • rfm9x.receive_timeout (defaults to 0.5ms)
    • Set the amount of time the receive() function will listen for incoming packets before returning if none received. This can also passed as a function argument.
  • rfm9x.ack_retries (defaults to 5 retries)
    • Set the number or retries to attempt if no ACK message is received.

Another simple adjustment is to pay attention to when packets are transmitted after receipt. Depending on the application, it may be helpful to add a delay between the receipt of a packet and the transmission of a response. 

Download: file
# send response 2 sec after any packet received
        time.sleep(2)

This guide was first published on Apr 15, 2016. It was last updated on Apr 15, 2016.

This page (Advanced CircuitPython Library RFM9x/RFM69 - Tweaking Parameters) was last updated on Nov 24, 2020.