Nrf24 (nrf24 v2.0.0)

View Source

Library for trasmitting and receiveing data with nRF24L01+ transciever.

It works, by default, in ShockBurst mode with ACK (auto acknowledgement) and CRC check enabled. However it can be configured to disable both.

Examples

# Receiving data
{:ok, nrf} =
  Nrf24.start_link(
    bus_name: "spidev0.0",
    ce_pin: 17,
    csn_pin: 0,
    channel: 0x4C,
    crc_length: 2,
    speed: :medium,
    pipes: [[pipe_no: 0, address: "1Node", payload_size: 4, auto_ack: true]]
  )
Nrf24.start_listening(nrf)
Nrf24.receive(nrf, 4)
Nrf24.stop_listening(nrf)

# Sending data
{:ok, nrf} =
  Nrf24.start_link(
    bus_name: "spidev0.0",
    ce_pin: 17,
    csn_pin: 0,
    channel: 0x4C,
    crc_length: 2,
    speed: :medium,
  )
data = <<9273.69::float-little-size(32)>>
Nrf24.send(nrf, "2Node", data)

Summary

Types

init_options()

@type init_options() :: [
  name: GenServer.name(),
  bus_name: String.t(),
  ce_pin: integer(),
  csn_pin: integer(),
  channel: integer(),
  crc_length: 0 | 1 | 2,
  speed: :low | :medium | :hi,
  pipes: [
    [
      pipe_no: integer(),
      address: integer(),
      payload_size: integer(),
      auto_ack: boolean()
    ]
  ]
]

Functions

ack_off(spi, pipe_no)

ack_on(spi, pipe_no)

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

disable_pipe(spi, pipe_no)

enable_pipe(spi, pipe_no)

power_off(pid)

power_on(pid)

read_register(spi, register)

read_register(spi, register, bytes_no)

receive(spi, payload_size, timeout_in_seconds)

reset_device(spi)

reset_status(spi)

send(spi, address, data)

set_channel(pid, channel)

set_crc_length(pid, length)

set_payload_size(spi, pipe_no, payload_size)

set_pipe(spi, pipe_no, options)

set_pipe_address(pid, pipe_no, address)

set_receive_mode(pid)

set_retransmit_count(spi, count)

set_retransmit_delay(spi, delay)

set_speed(pid, speed)

set_transmit_address(spi, address)

set_transmit_mode(pid)

start_link(args)

@spec start_link(init_options()) :: GenServer.on_start()

nRF24L01+ GenServer start_link options

  • :name - GenServer nome
  • :bus_name - SPI bus name (e.g. "spidev0.0", "spidev1.0", default: "spidev0.0")
  • :ce_pin - Rasbperry PI pin to which transciever's CE pin is connected
  • :csn_pin - Rasbperry PI pin to which transciever's CSN pin is connected
  • :channel - Frequency channel on which transciever will operate (default: 0x4c)
  • :crc_length - CRC length for transmitted data verification (values: 1, 2, default: 2)
  • :speed - Data transfer speed (values: low, med, high, default: med)
  • :pipes - Data pipes configuration to be used

Data speed values:

  • :low - 250Kbp
  • :medium - 1Mbps
  • :high - 2Mbps

Pipe configuration options:

  • :pipe_no - Pipe number (values 0 to 5)
  • :address - For pipes 0 and 1 5-byte address and for other single byte address
  • :payload_size - Size of data that will be received through the pipe
  • :auto_ack - Turning auto-acknowledge on or off for the pipe (default: true)

If pipes configuration is missing, default, factory set, values will be used.

Example

{:ok, nrf} =
  Nrf24.start_link(
    bus_name: "spidev0.0",
    ce_pin: 17,
    csn_pin: 0,
    channel: 0x4C,
    crc_length: 2,
    speed: :medium,
    pipes: [[pipe_no: 0, address: "1Node", payload_size: 4, auto_ack: true]]
  )

start_listening(spi)

stop_listening(spi)

write_register(spi, register, value)