@rf24/rf24
    Preparing search index...

    Class RF24

    This class provides the user facing API to interact with a nRF24L01 transceiver.

    Index

    Advanced

    • get rpd(): boolean

      Was the Received Power Detection (RPD) trigger?

      This flag is asserted during an RX session (after a mandatory 130 microseconds duration) if a signal stronger than -64 dBm was detected.

      Note that if a payload was placed in RX mode, then that means the signal used to transmit that payload was stronger than either

      Sensitivity may vary based of the radio's model and manufacturer. The information above is stated in the nRF24L01+ datasheet.

      Returns boolean

    • Set the radio's CE pin HIGH (true) or LOW (false).

      This is only exposed for advanced use of TX FIFO during asynchronous TX operations. It is highly encouraged to use RF24.asRx or RF24.asTx to ensure proper radio behavior when entering RX or TX mode.

      Parameters

      • value: number | boolean

      Returns void

    • Reset the specified StatusFlags.

      Parameters

      • Optionalflags: StatusFlags | null

        If no value is given, then all flags are reset.

      Returns void

    • Discard all 3 levels of the radio's RX FIFO.

      Returns void

    • Discard all 3 levels of the radio's TX FIFO.

      This is automatically called by RF24.asTx when ACK payloads are enabled (via RF24.ackPayloads).

      Returns void

    • Get the length of the next available payload in the RX FIFO.

      If dynamically sized payloads are not enabled (via RF24.dynamicPayloads), then use RF24.payloadLength.

      Returns number

    • Get the state of the specified FIFO.

      Parameters

      • aboutTx: number | boolean

        True returns data about the TX FIFO. False returns data about the RX FIFO.

      Returns FifoState

    • Get the Automatic Retry Count (ARC) of attempts made during the last transmission.

      This resets with every new transmission. The returned value is meaningless if the auto-ack feature is disabled.

      Use RF24.setAutoRetries to configure the automatic retries feature.

      Returns number

    • Get the current state of the StatusFlags.

      Note

      This function simply returns the value of the flags that was cached from the last SPI transaction. It does not actually update the values (from the radio) before returning them.

      Use RF24.update to update them first.

      Returns StatusFlags

    • A non-blocking function to restart a failed transmission.

      This is a helper function to RF24.resend. Use RF24.update and RF24.getStatusFlags to determine if retransmission was successful.

      Returns void

    • Start a constant carrier wave

      This functionality is meant for hardware tests (in conjunction with RF24.rpd). Typically, this behavior is required by government agencies to enforce regional restrictions.

      Parameters

      • level: PaLevel

        The Power Amplitude level to use when transmitting.

      • channel: number

        The channel (radio's frequency) used to transmit. The channel should not be changed while transmitting because it can cause undefined behavior.

      Returns void

    • Stop the constant carrier wave started via RF24.startCarrierWave.

      This function leaves the radio in a configuration that may be undesired or unexpected because of the setup involved in RF24.startCarrierWave. The PaLevel and channel passed to RF24.startCarrierWave are still set. If RF24.isPlusVariant returns true, the following features are all disabled:

      • auto-ack
      • CRC
      • auto-retry

      Returns void

    • Update the cached value of Status flags.

      Use RF24.getStatusFlags to get the updated values.

      Returns void

    • A non-blocking function that uploads a given buf to the radio's TX FIFO.

      This is a helper function to RF24.send. Use this in combination with RF24.update and RF24.getStatusFlags to determine if transmission was successful.

      Parameters

      • buf: Buffer

        The buffer of bytes to load into the TX FIFO.

      • OptionalwriteConfig: WriteConfig | null

      Returns boolean

      A Boolean that describes if the given buf was successfully loaded into the TX FIFO. Remember, the TX FIFO has only 3 levels ("slots").

    • Upload a given ACK packet's payload (buf) into the radio's TX FIFO.

      This feature requires RF24.ackPayloads to be enabled.

      Parameters

      • pipe: number

        The pipe number that (when data is received) will be responded with the given payload (buf).

      • buf: Buffer

        The payload to attach to the auto-ack packet when responding to data received on specified pipe.

      Returns boolean

      A boolean value that describes if the payload was successfully uploaded to the TX FIFO. Remember, the TX FIFO only has 3 levels ("slots").

    Basic

    • Construct an object to control the radio.

      Parameters

      • cePin: number

        The GPIO pin number connected to the radio's CE pin.

      • csPin: number

        The identifying number for the SPI bus' CS pin; also labeled as "CEx" (where "x" is this parameter's value) on many Raspberry Pi pin diagrams. See HardwareConfig.devSpiBus for more detail.

      • OptionalhardwareConfig: HardwareConfig | null

        Optional parameters to fine tune hardware configuration (like SPI bus number and GPIO chip number).

      Returns RF24

    • get channel(): number

      Returns number

    • set channel(channel: number): void

      Set the channel (frequency) that the radio uses to transmit and receive.

      Parameters

      • channel: number

        This value is clamped to the range [0, 125].

        This value can be roughly translated into a frequency with the formula:

        frequency (in Hz) = channel + 2400
        

      Returns void

    • get isRx(): boolean

      Is the radio in active RX mode?

      Returns boolean

    • Put the radio into active RX mode.

      Conventionally, this should be called after setting the RX addresses via RF24.openRxPipe.

      This function will restore the cached RX address set to pipe 0. This is done because the RF24.asTx will appropriate the RX address on pipe 0 for auto-ack purposes.

      Returns void

    • Puts the radio into an inactive TX mode.

      This must be called at least once before calling RF24.send or RF24.write.

      For auto-ack purposes, this function will also restore the cached txAddress to the RX pipe 0.

      The datasheet recommends idling the radio in an inactive TX mode.

      Note

      This function will also flush the TX FIFO when ACK payloads are enabled (via RF24.ackPayloads).

      Parameters

      • OptionaltxAddress: Buffer<ArrayBufferLike> | null

        If specified, then this buffer will be cached and set as the new TX address.

      Returns void

    • Is there a payload available in the RX FIFO?

      Use RF24.read to get the payload data.

      Returns boolean

    • Initialize the radio on the configured hardware (as specified to RF24 constructor).

      Returns void

      A Generic Error if a hardware failure caused problems (includes a message to describe what problem was detected).

      This is the same as RF24.withConfig, but this function also

      • detects if the radio is a plus variant (RF24.isPlusVariant)
      • checks for data corruption across the SPI lines (MOSI, MISO, SCLK)
    • Close the specified pipe from receiving transmissions.

      Use RF24.openRxPipe to set the address for a specific pipe.

      Parameters

      • pipe: number

        The pipe to close. This must be in range [0, 5], otherwise this function does nothing.

      Returns void

    • Open a specific pipe for receiving from the given address.

      It is highly recommended to avoid using pipe 0 to receive because it is also used to transmit automatic acknowledgements.

      Note

      Only pipes 0 and 1 actually use up to 5 bytes of the given address. Pipes 2 - 5 only use the first byte of the given address and last 4 bytes of the address set to pipe 1.

      Parameters

      • pipe: number

        The pipe number to receive data. This must be in range [0, 5], otherwise this function does nothing.

      • address: Buffer

        The address to receive data from.

      Returns void

    • Read data from the radio's RX FIFO.

      Use RF24.available to determine if there is data ready to read from the RX FIFO.

      Parameters

      • Optionallen: number | null

        An optional number of bytes to read from the FIFO. This is capped at 32. If not specified, then the length of the next available payload is used (which automatically respects if dynamic payloads are enabled).

        Use RF24.dynamicPayloads for dynamically sized payload or RF24.payloadLength for statically sized payloads.

      Returns Buffer

    • A blocking function to resend a failed payload in the TX FIFO.

      This is similar to RF24.send but specifically for failed transmissions.

      Returns boolean

    • Blocking function that loads a given buf into the TX FIFO, waits for a response (if auto-ack is enabled), then returns a Boolean describing success.

      Parameters

      • buf: Buffer

        The buffer of bytes to transmit.

      • OptionalaskNoAck: number | boolean

        A flag to disable the auto-ack feature for the given payload in buf. This has no effect if auto-ack is disabled or RF24.allowAskNoAck is not enabled.

      Returns boolean

      A boolean that describes if transmission is successful or not. This will always return true if auto-ack is disabled.

    Configuration

    • get ackPayloads(): boolean

      Returns boolean

    • set ackPayloads(enable: number | boolean): void

      Enable or disable the custom ACK payloads attached to auto-ack packets.

      Important

      This feature requires dynamically sized payloads. This attribute will enable RF24.dynamicPayloads automatically when needed. This attribute will not disable RF24.dynamicPayloads.

      Parameters

      • enable: number | boolean

      Returns void

    • get addressLength(): number

      Returns number

    • set addressLength(length: number): void

      Set the address length (applied to all pipes).

      Parameters

      • length: number

        The address length is clamped to the range [2, 5].

      Returns void

    • get crcLength(): CrcLength

      Returns CrcLength

    • set crcLength(crcLength: CrcLength): void

      Get/set the CrcLength used for all outgoing and incoming transmissions.

      Note

      If disabled (CrcLength.Disabled) while auto-ack feature is enabled, then this function's returned value does not reflect the fact that CRC is forcefully enabled by the radio's firmware (needed by the auto-ack feature).

      Parameters

      Returns void

    • get dataRate(): DataRate

      Returns DataRate

    • set dataRate(dataRate: DataRate): void

      Get/set the DataRate used for all incoming and outgoing transmissions.

      Parameters

      Returns void

    • get dynamicPayloads(): boolean

      Returns boolean

    • set dynamicPayloads(enable: number | boolean): void

      Enable or disable the dynamically sized payloads feature.

      Parameters

      • enable: number | boolean

        If set to true, the statically sized payload length (set via RF24.payloadLength) are not used.

      Returns void

    • get isPlusVariant(): boolean

      Is this radio a nRF24L01+ variant?

      The bool that this attribute returns is only valid after calling RF24.begin.

      Returns boolean

    • get paLevel(): PaLevel

      Returns PaLevel

    • set paLevel(paLevel: PaLevel): void

      Get/set the Power Amplitude (PA) level used for all transmissions (including auto ack packet).

      Parameters

      Returns void

    • get payloadLength(): number

      Returns number

    • set payloadLength(length: number): void

      Get/set the statically sized payload length.

      This configuration is not used if dynamic payloads are enabled. Use RF24.getDynamicPayloadLength instead if dynamically sized payloads are enabled (via RF24.dynamicPayloads).

      Parameters

      • length: number

      Returns void

    • get power(): boolean

      Returns boolean

    • set power(enable: number): void

      Control the radio's powered level.

      This is just a convenience attribute that calls RF24.powerUp or RF24.powerDown.

      Use RF24.isRx to determine if the radio is in RX or TX mode.

      Parameters

      • enable: number

      Returns void

    • get txDelay(): number

      Returns number

    • set txDelay(value: number): void

      The driver will delay for this duration (32 bit unsigned int of microseconds) when RF24.asTx is called.

      If the auto-ack feature is disabled, then this can be set as low as 0. If the auto-ack feature is enabled, then set to 100 microseconds minimum on generally faster devices (like RPi).

      This value cannot be negative.

      Since this value can be optimized per the radio's data rate, this value is automatically adjusted when changing RF24.dataRate. If setting this to a custom value be sure, to set it after changing the radio's data rate.

      Warning

      If set to 0, then the concurrent outgoing ACK packet (when auto-ack is enabled) may fail to transmit when exiting RX mode with RF24.asTx.

      Parameters

      • value: number

      Returns void

    • Allow disabling the auto-ack feature for individual payloads.

      Parameters

      • enable: number | boolean

        Setting this to true will allow the askNoAck parameter to take effect. See RF24.send and WriteConfig.askNoAck for more detail.

      Returns void

    • Power Down the radio.

      No transmissions can be received when the radio is powered down.

      Returns void

    • Power up the radio.

      Parameters

      • Optionaldelay: number | null

        The number of nanoseconds to wait for the radio to finish powering up. If not specified, the default wait time defaults to 5 milliseconds.

      Returns void

    • Print helpful debug information to stdout.

      Returns void

    • Enable or disable the auto-ack feature for all pipes.

      Note

      This feature requires CRC to be enabled. See RF24.crcLength for more detail.

      Parameters

      • enable: number | boolean

      Returns void

    • Enable or disable the auto-ack feature for a specified pipe.

      Parameters

      • enable: number
      • pipe: number

      Returns void

    • Configure the automatic retry feature.

      This feature is part of the auto-ack feature, thus the auto-ack feature is required for this function to have any effect.

      Parameters

      • delay: number

        This value is clamped to the range [0, 15]. This value is translated to microseconds with the formula 250 + (delay * 250) = microseconds. Meaning, the effective range of delay is [250, 4000].

      • count: number

        The number of attempt to retransmit when no ACK packet was received (after transmitting). This value is clamped to the range [0, 15].

      Returns void

    • Enable or disable the LNA feature.

      This is enabled by default (regardless of chip variant). See PaLevel for effective behavior.

      On nRF24L01+ modules with a builtin antenna, this feature is always enabled. For clone's and module's with a separate PA/LNA circuit (external antenna), this function may not behave exactly as expected. Consult the radio module's manufacturer.

      Parameters

      • enable: number | boolean

      Returns void

    • Configure the IRQ pin to reflect the specified StatusFlags.

      Parameters

      • Optionalflags: StatusFlags | null

        If no value is given, then all flags are reflected by the IRQ pin.

      Returns void

    • Reconfigure the radio with the specified config.

      Warning

      It is strongly encouraged to call RF24.begin after constructing the RF24 object.

      Only use this function subsequently to quickly switch between different network settings.

      Parameters

      Returns void