Package jpigpio.devices
Class NRF24L01
java.lang.Object
jpigpio.devices.NRF24L01
public class NRF24L01
extends java.lang.Object
The NRF24L is a wireless communication device.
- Author:
- kolban
-
Field Summary
Fields Modifier and Type Field Description static int
ARC
static int
ARC_CNT
static int
ARD
static int
AW
static int
CD
static int
CONFIG_REGISTER
static int
CRCO
static int
DPL_P0
static int
DPL_P1
static int
DPL_P2
static int
DPL_P3
static int
DPL_P4
static int
DPL_P5
static int
DYNPD
static int
EN_AA
static int
EN_ACK_PAY
static int
EN_CRC
static int
EN_DPL
static int
EN_DYN_ACK
static int
EN_RXADDR_REGISTER
static int
ENAA_P0
static int
ENAA_P1
static int
ENAA_P2
static int
ENAA_P3
static int
ENAA_P4
static int
ENAA_P5
static int
ERX_P0
static int
ERX_P1
static int
ERX_P2
static int
ERX_P3
static int
ERX_P4
static int
ERX_P5
static int
FEATURE
static int
FIFO_FULL
static int
FIFO_STATUS_REGISTER
static int
MASK_MAX_RT
static int
MASK_RX_DR
static int
MASK_TX_DS
static int
MAX_RT
static int
OBSERVE_TX
static int
PLOS_CNT
static int
PRIM_RX
static int
PWR_UP
static int
RF_CH_REGISTER
static int
RF_SETUP
static int
RF24_1MBPS
static int
RF24_250KBPS
static int
RF24_2MBPS
static int
RF24_AW_3BYTES
static int
RF24_AW_4BYTES
static int
RF24_AW_5BYTES
static int
RF24_PA_HIGH
static int
RF24_PA_LOW
static int
RF24_PA_MASK
static int
RF24_PA_MAX
static int
RF24_PA_MIN
static int
RPD
static int
RX_ADDR_P0
static int
RX_ADDR_P1
static int
RX_ADDR_P2
static int
RX_ADDR_P3
static int
RX_ADDR_P4
static int
RX_ADDR_P5
static int
RX_DR
static int
RX_EMPTY
static int
RX_FULL
static int
RX_P_NO
static int
RX_PW_P0
static int
RX_PW_P1
static int
RX_PW_P2
static int
RX_PW_P3
static int
RX_PW_P4
static int
RX_PW_P5
static int
SETUP_AW_REGISTER
static int
SETUP_RETR_REGISTER
static int
STATUS_REGISTER
static int
TX_ADDR
static int
TX_DS
static int
TX_EMPTY
static int
TX_FULL
static int
TX_REUSE
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description void
clearRegisterBits(int reg, byte bits)
Clear specified bits in single-byte registervoid
config(int payloadSize)
Configure the parameters of the device.void
configRegister(int reg, byte value)
(DEPRECATED) Write single byte to specified register.
Use method writeByteRegister instead.java.lang.String
configToString(byte value)
java.lang.String
dataRateToString(int dataRate)
boolean
dataReady()
Checks if data is available for reading in RX FIFOvoid
disableCRC()
Disable CRCjava.lang.String
fifoStatusToString(byte value)
int
getAddressWidth()
Return address width in bytesbyte
getAutomaticRetransmission()
byte
getChannel()
Get frequency channel nRF24 chip is currently usingbyte
getConfig()
Read CONFIG registerboolean
getData(byte[] data)
Read data received into the arrayjava.lang.String
getDetails()
byte
getFIFOStatus()
int
getPayloadSize()
byte[][]
getRXAddresses()
Read addresses receiver is listening frombyte
getStatus()
Read STATUS registerbyte[]
getTXAddress()
Read transmitter address - source addressboolean
init(int cePin, int csnPin)
Initialize nRF24 chip and set the defaultsboolean
isSending()
Test if chip is still sending.void
powerDown()
void
printDetails(java.io.PrintStream prn)
Print detailed information about nRF24 chipbyte
readByteRegister(int reg)
Reads single one-byte registervoid
readRegister(int reg, byte[] value)
Reads an array of bytes from the given start position in the MiRF registers.void
reset()
Set initial chip parameters according to nRF24 documentationboolean
rxFifoEmpty()
void
send(byte[] value)
Send up to 32 bytes of data.void
setAddressWidth(int width)
Set RX/TX address width.void
setAutoACK(boolean enable)
Enable or disable automatic packet acknowledgements.void
setAutoACK(int pipe, boolean enable)
Enable or disable automatic packet acknowledgements for specific pipe.void
setChannel(int ch)
Set frequency channel nRF24 operates onvoid
setCRCSize(int crcSize)
Set CRC sizevoid
setDataRate(int dataRate)
Sets data ratevoid
setPALevel(int level)
Sets TX output power level.void
setPayloadSize(int size)
Set payload (packet) size for all pipesvoid
setPayloadSize(int pipe, int size)
Set payload (packet) size for specific pipevoid
setRADDR(byte[] adr)
Sets receiving address P1.void
setRegisterBits(int reg, byte bits)
Set specified bits in single-byte registervoid
setRetries(int delay, int count)
Configure delay between retransmissions and number of retransmissions.
Set 1500uS (minimum for 32B payload in ESB@250KBPS) timeouts, to make testing a little easier
WARNING: If this is ever lowered, either 250KBS mode with AA is broken or maximum packet sizes must never be used.void
setTADDR(byte[] adr, boolean setP0Too)
Sets the transmitting address.java.lang.String
setupRetrToString(byte value)
void
startListening()
Tell NRF24 to start listening.void
startTestCarrier(int channel, int powerLevel)
Start generating testing unodulated carrier wave.java.lang.String
statusToString(byte status)
void
stopListening()
Stops receiving.void
stopTestCarrier()
Stop generating testing carrier wavevoid
terminate()
Terminate connection to nRF24 chipboolean
testRPD()
Test whether a signal (carrier or otherwise) greater than or equal to -64dBm is present on the channel.int
write(byte[] value)
Send data packet.void
writeByteRegister(int reg, byte value)
Writes value to single-byte register.void
writeRegister(int reg, byte[] data)
Writes provided bytes into MiRF registers starting from provided register address.
Good for multi-byte registers.
-
Field Details
-
CONFIG_REGISTER
public static final int CONFIG_REGISTER- See Also:
- Constant Field Values
-
EN_AA
public static final int EN_AA- See Also:
- Constant Field Values
-
EN_RXADDR_REGISTER
public static final int EN_RXADDR_REGISTER- See Also:
- Constant Field Values
-
SETUP_AW_REGISTER
public static final int SETUP_AW_REGISTER- See Also:
- Constant Field Values
-
SETUP_RETR_REGISTER
public static final int SETUP_RETR_REGISTER- See Also:
- Constant Field Values
-
RF_CH_REGISTER
public static final int RF_CH_REGISTER- See Also:
- Constant Field Values
-
RF_SETUP
public static final int RF_SETUP- See Also:
- Constant Field Values
-
STATUS_REGISTER
public static final int STATUS_REGISTER- See Also:
- Constant Field Values
-
OBSERVE_TX
public static final int OBSERVE_TX- See Also:
- Constant Field Values
-
RPD
public static final int RPD- See Also:
- Constant Field Values
-
CD
public static final int CD- See Also:
- Constant Field Values
-
RX_ADDR_P0
public static final int RX_ADDR_P0- See Also:
- Constant Field Values
-
RX_ADDR_P1
public static final int RX_ADDR_P1- See Also:
- Constant Field Values
-
RX_ADDR_P2
public static final int RX_ADDR_P2- See Also:
- Constant Field Values
-
RX_ADDR_P3
public static final int RX_ADDR_P3- See Also:
- Constant Field Values
-
RX_ADDR_P4
public static final int RX_ADDR_P4- See Also:
- Constant Field Values
-
RX_ADDR_P5
public static final int RX_ADDR_P5- See Also:
- Constant Field Values
-
TX_ADDR
public static final int TX_ADDR- See Also:
- Constant Field Values
-
RX_PW_P0
public static final int RX_PW_P0- See Also:
- Constant Field Values
-
RX_PW_P1
public static final int RX_PW_P1- See Also:
- Constant Field Values
-
RX_PW_P2
public static final int RX_PW_P2- See Also:
- Constant Field Values
-
RX_PW_P3
public static final int RX_PW_P3- See Also:
- Constant Field Values
-
RX_PW_P4
public static final int RX_PW_P4- See Also:
- Constant Field Values
-
RX_PW_P5
public static final int RX_PW_P5- See Also:
- Constant Field Values
-
FIFO_STATUS_REGISTER
public static final int FIFO_STATUS_REGISTER- See Also:
- Constant Field Values
-
DYNPD
public static final int DYNPD- See Also:
- Constant Field Values
-
FEATURE
public static final int FEATURE- See Also:
- Constant Field Values
-
MASK_RX_DR
public static final int MASK_RX_DR- See Also:
- Constant Field Values
-
MASK_TX_DS
public static final int MASK_TX_DS- See Also:
- Constant Field Values
-
MASK_MAX_RT
public static final int MASK_MAX_RT- See Also:
- Constant Field Values
-
EN_CRC
public static final int EN_CRC- See Also:
- Constant Field Values
-
CRCO
public static final int CRCO- See Also:
- Constant Field Values
-
PWR_UP
public static final int PWR_UP- See Also:
- Constant Field Values
-
PRIM_RX
public static final int PRIM_RX- See Also:
- Constant Field Values
-
ENAA_P5
public static final int ENAA_P5- See Also:
- Constant Field Values
-
ENAA_P4
public static final int ENAA_P4- See Also:
- Constant Field Values
-
ENAA_P3
public static final int ENAA_P3- See Also:
- Constant Field Values
-
ENAA_P2
public static final int ENAA_P2- See Also:
- Constant Field Values
-
ENAA_P1
public static final int ENAA_P1- See Also:
- Constant Field Values
-
ENAA_P0
public static final int ENAA_P0- See Also:
- Constant Field Values
-
ERX_P5
public static final int ERX_P5- See Also:
- Constant Field Values
-
ERX_P4
public static final int ERX_P4- See Also:
- Constant Field Values
-
ERX_P3
public static final int ERX_P3- See Also:
- Constant Field Values
-
ERX_P2
public static final int ERX_P2- See Also:
- Constant Field Values
-
ERX_P1
public static final int ERX_P1- See Also:
- Constant Field Values
-
ERX_P0
public static final int ERX_P0- See Also:
- Constant Field Values
-
AW
public static final int AW- See Also:
- Constant Field Values
-
ARD
public static final int ARD- See Also:
- Constant Field Values
-
ARC
public static final int ARC- See Also:
- Constant Field Values
-
RX_DR
public static final int RX_DR- See Also:
- Constant Field Values
-
TX_DS
public static final int TX_DS- See Also:
- Constant Field Values
-
MAX_RT
public static final int MAX_RT- See Also:
- Constant Field Values
-
RX_P_NO
public static final int RX_P_NO- See Also:
- Constant Field Values
-
TX_FULL
public static final int TX_FULL- See Also:
- Constant Field Values
-
PLOS_CNT
public static final int PLOS_CNT- See Also:
- Constant Field Values
-
ARC_CNT
public static final int ARC_CNT- See Also:
- Constant Field Values
-
TX_REUSE
public static final int TX_REUSE- See Also:
- Constant Field Values
-
FIFO_FULL
public static final int FIFO_FULL- See Also:
- Constant Field Values
-
TX_EMPTY
public static final int TX_EMPTY- See Also:
- Constant Field Values
-
RX_FULL
public static final int RX_FULL- See Also:
- Constant Field Values
-
RX_EMPTY
public static final int RX_EMPTY- See Also:
- Constant Field Values
-
DPL_P5
public static final int DPL_P5- See Also:
- Constant Field Values
-
DPL_P4
public static final int DPL_P4- See Also:
- Constant Field Values
-
DPL_P3
public static final int DPL_P3- See Also:
- Constant Field Values
-
DPL_P2
public static final int DPL_P2- See Also:
- Constant Field Values
-
DPL_P1
public static final int DPL_P1- See Also:
- Constant Field Values
-
DPL_P0
public static final int DPL_P0- See Also:
- Constant Field Values
-
EN_DPL
public static final int EN_DPL- See Also:
- Constant Field Values
-
EN_ACK_PAY
public static final int EN_ACK_PAY- See Also:
- Constant Field Values
-
EN_DYN_ACK
public static final int EN_DYN_ACK- See Also:
- Constant Field Values
-
RF24_250KBPS
public static final int RF24_250KBPS- See Also:
- Constant Field Values
-
RF24_1MBPS
public static final int RF24_1MBPS- See Also:
- Constant Field Values
-
RF24_2MBPS
public static final int RF24_2MBPS- See Also:
- Constant Field Values
-
RF24_PA_MIN
public static final int RF24_PA_MIN- See Also:
- Constant Field Values
-
RF24_PA_LOW
public static final int RF24_PA_LOW- See Also:
- Constant Field Values
-
RF24_PA_HIGH
public static final int RF24_PA_HIGH- See Also:
- Constant Field Values
-
RF24_PA_MAX
public static final int RF24_PA_MAX- See Also:
- Constant Field Values
-
RF24_PA_MASK
public static final int RF24_PA_MASK- See Also:
- Constant Field Values
-
RF24_AW_3BYTES
public static final int RF24_AW_3BYTES- See Also:
- Constant Field Values
-
RF24_AW_4BYTES
public static final int RF24_AW_4BYTES- See Also:
- Constant Field Values
-
RF24_AW_5BYTES
public static final int RF24_AW_5BYTES- See Also:
- Constant Field Values
-
-
Constructor Details
-
Method Details
-
init
Initialize nRF24 chip and set the defaults- Parameters:
cePin
- gpio pin connected to CEcsnPin
- gpio pin connected to CSN- Returns:
- true if initialized successfully
- Throws:
PigpioException
-
reset
Set initial chip parameters according to nRF24 documentation- Throws:
PigpioException
-
terminate
Terminate connection to nRF24 chip- Throws:
PigpioException
-
config
Configure the parameters of the device.- Parameters:
payloadSize
- Number of bytes in payload pipe 0 and pipe 1.- Throws:
PigpioException
-
setRADDR
Sets receiving address P1.- Parameters:
adr
-- Throws:
PigpioException
-
setTADDR
Sets the transmitting address. Note: RX_ADDR_P0 must be set to the sending addr for auto ack to work.- Parameters:
adr
- TX addresssetP0Too
- if true, set RX_ADDR_P0 to TX address too (for auto ack to work)- Throws:
PigpioException
-
setChannel
Set frequency channel nRF24 operates on- Parameters:
ch
- channel 0-127- Throws:
PigpioException
-
setDataRate
Sets data rate- Parameters:
dataRate
- datarate to use RF24_250KBPS = 250 kbit/s RF24_1MBPS = 1 Mbit/s RF24_2MBPS = 2 Mbit/2*- Throws:
PigpioException
-
setPALevel
Sets TX output power level.- Parameters:
level
- TX output power level RF24_PA_MIN = -18db RF24_PA_LOW = -12db RF24_PA_HIGH = -6db RF24_PA_MAX = 0db- Throws:
PigpioException
-
setAutoACK
Enable or disable automatic packet acknowledgements. Default is ENABLE.- Parameters:
enable
- true to enable, false to disable- Throws:
PigpioException
-
setAutoACK
Enable or disable automatic packet acknowledgements for specific pipe.- Parameters:
pipe
- true to enable, false to disableenable
-- Throws:
PigpioException
-
setPayloadSize
Set payload (packet) size for all pipes- Parameters:
size
- payload size 1-32 bytes- Throws:
PigpioException
-
setPayloadSize
Set payload (packet) size for specific pipe- Parameters:
pipe
- pipe 0-5size
- payload size 1-32 bytes- Throws:
PigpioException
-
getPayloadSize
public int getPayloadSize() -
disableCRC
Disable CRC- Throws:
PigpioException
-
setCRCSize
Set CRC size- Parameters:
crcSize
- CRC size in bytes (0 = disable, 1 = 8 bits, 2 = 16 bits)- Throws:
PigpioException
-
setRegisterBits
Set specified bits in single-byte register- Parameters:
reg
- register to setbits
- bits to set- Throws:
PigpioException
-
clearRegisterBits
Clear specified bits in single-byte register- Parameters:
reg
- register to setbits
- bts to clear- Throws:
PigpioException
-
setRetries
Configure delay between retransmissions and number of retransmissions.
Set 1500uS (minimum for 32B payload in ESB@250KBPS) timeouts, to make testing a little easier
WARNING: If this is ever lowered, either 250KBS mode with AA is broken or maximum packet sizes must never be used. See documentation for a more complete explanation.- Parameters:
delay
- How long to wait between each retry, in multiples of 250us, max is 15. 0 means 250us, 15 means 4000us.*count
- Number of retries (0 = no retries, max 15 retries)- Throws:
PigpioException
-
dataReady
Checks if data is available for reading in RX FIFO- Returns:
- true if there is data available for reading
- Throws:
PigpioException
-
rxFifoEmpty
- Throws:
PigpioException
-
getData
Read data received into the array- Parameters:
data
- The array of data to be returned.- Returns:
- true if there is more data to read
- Throws:
PigpioException
-
configRegister
(DEPRECATED) Write single byte to specified register.
Use method writeByteRegister instead.- Parameters:
reg
- registe to write tovalue
- new value- Throws:
PigpioException
-
readByteRegister
Reads single one-byte register- Parameters:
reg
- register to read- Returns:
- register value
- Throws:
PigpioException
-
readRegister
Reads an array of bytes from the given start position in the MiRF registers.- Parameters:
reg
- starting registervalue
- array of bytes to store read values to- Throws:
PigpioException
-
writeRegister
Writes provided bytes into MiRF registers starting from provided register address.
Good for multi-byte registers. For single-byte registers you can use method writeByteRegister.- Parameters:
reg
- starting registerdata
-- Throws:
PigpioException
-
writeByteRegister
Writes value to single-byte register. For multi-byte registers you can use method writeRegister.- Parameters:
reg
- register to write tovalue
- new register value- Throws:
PigpioException
-
write
Send data packet. This is a blocking call, but 60ms max, so no big deal.- Parameters:
value
- data to send- Returns:
- 0 if OK, 1 if number of retries reached, 2 if timeout occurred
- Throws:
PigpioException
-
send
Send up to 32 bytes of data.- Parameters:
value
- The data to send.- Throws:
PigpioException
-
isSending
Test if chip is still sending. When sending has finished return chip to listening.- Returns:
- true if data is currently being transmitted
- Throws:
PigpioException
- on pigpiod error
-
getStatus
Read STATUS register- Returns:
- value stored in STATUS register
- Throws:
PigpioException
-
getConfig
Read CONFIG register- Returns:
- value stored in CONFIG register
- Throws:
PigpioException
-
getChannel
Get frequency channel nRF24 chip is currently using- Returns:
- used frequency channel number
- Throws:
PigpioException
-
getAddressWidth
Return address width in bytes- Returns:
- address width in bytes (3-5)
- Throws:
PigpioException
-
getRXAddresses
Read addresses receiver is listening from- Returns:
- array containing addresses of reading pipes 0-5
- Throws:
PigpioException
-
getTXAddress
Read transmitter address - source address- Returns:
- transmitter address
- Throws:
PigpioException
-
setAddressWidth
Set RX/TX address width.- Parameters:
width
- Width in bytes. Allowed values are 3,4,5.- Throws:
PigpioException
-
getAutomaticRetransmission
- Throws:
PigpioException
-
getFIFOStatus
- Throws:
PigpioException
-
startListening
Tell NRF24 to start listening. Power up and set to RX Mode. Flushes both RX and TX FIFOs. Resets STATUS register flags.- Throws:
PigpioException
-
stopListening
Stops receiving. Go from active RX Mode to to Standby-I Mode. Flushes both RX and TX FIFOs.- Throws:
PigpioException
-
powerDown
- Throws:
PigpioException
-
startTestCarrier
Start generating testing unodulated carrier wave. For testing purposes only.- Parameters:
channel
- RF channel to start carrier wave onpowerLevel
- power level for carrier wave- Throws:
PigpioException
-
stopTestCarrier
Stop generating testing carrier wave- Throws:
PigpioException
-
testRPD
Test whether a signal (carrier or otherwise) greater than or equal to -64dBm is present on the channel. Valid only on nRF24L01P (+) hardware. Useful to check for interference on the current channel and channel hopping strategies.- Returns:
- true if signal => -64dBm, false if not
- Throws:
PigpioException
-
statusToString
public java.lang.String statusToString(byte status) -
configToString
public java.lang.String configToString(byte value) -
setupRetrToString
public java.lang.String setupRetrToString(byte value) -
fifoStatusToString
public java.lang.String fifoStatusToString(byte value) -
dataRateToString
public java.lang.String dataRateToString(int dataRate) -
printDetails
public void printDetails(java.io.PrintStream prn)Print detailed information about nRF24 chip- Parameters:
prn
- PrintStream to which data will be sent
-
getDetails
public java.lang.String getDetails()
-