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 intARCstatic intARC_CNTstatic intARDstatic intAWstatic intCDstatic intCONFIG_REGISTERstatic intCRCOstatic intDPL_P0static intDPL_P1static intDPL_P2static intDPL_P3static intDPL_P4static intDPL_P5static intDYNPDstatic intEN_AAstatic intEN_ACK_PAYstatic intEN_CRCstatic intEN_DPLstatic intEN_DYN_ACKstatic intEN_RXADDR_REGISTERstatic intENAA_P0static intENAA_P1static intENAA_P2static intENAA_P3static intENAA_P4static intENAA_P5static intERX_P0static intERX_P1static intERX_P2static intERX_P3static intERX_P4static intERX_P5static intFEATUREstatic intFIFO_FULLstatic intFIFO_STATUS_REGISTERstatic intMASK_MAX_RTstatic intMASK_RX_DRstatic intMASK_TX_DSstatic intMAX_RTstatic intOBSERVE_TXstatic intPLOS_CNTstatic intPRIM_RXstatic intPWR_UPstatic intRF_CH_REGISTERstatic intRF_SETUPstatic intRF24_1MBPSstatic intRF24_250KBPSstatic intRF24_2MBPSstatic intRF24_AW_3BYTESstatic intRF24_AW_4BYTESstatic intRF24_AW_5BYTESstatic intRF24_PA_HIGHstatic intRF24_PA_LOWstatic intRF24_PA_MASKstatic intRF24_PA_MAXstatic intRF24_PA_MINstatic intRPDstatic intRX_ADDR_P0static intRX_ADDR_P1static intRX_ADDR_P2static intRX_ADDR_P3static intRX_ADDR_P4static intRX_ADDR_P5static intRX_DRstatic intRX_EMPTYstatic intRX_FULLstatic intRX_P_NOstatic intRX_PW_P0static intRX_PW_P1static intRX_PW_P2static intRX_PW_P3static intRX_PW_P4static intRX_PW_P5static intSETUP_AW_REGISTERstatic intSETUP_RETR_REGISTERstatic intSTATUS_REGISTERstatic intTX_ADDRstatic intTX_DSstatic intTX_EMPTYstatic intTX_FULLstatic intTX_REUSE -
Constructor Summary
-
Method Summary
Modifier and Type Method Description voidclearRegisterBits(int reg, byte bits)Clear specified bits in single-byte registervoidconfig(int payloadSize)Configure the parameters of the device.voidconfigRegister(int reg, byte value)(DEPRECATED) Write single byte to specified register.
Use method writeByteRegister instead.java.lang.StringconfigToString(byte value)java.lang.StringdataRateToString(int dataRate)booleandataReady()Checks if data is available for reading in RX FIFOvoiddisableCRC()Disable CRCjava.lang.StringfifoStatusToString(byte value)intgetAddressWidth()Return address width in bytesbytegetAutomaticRetransmission()bytegetChannel()Get frequency channel nRF24 chip is currently usingbytegetConfig()Read CONFIG registerbooleangetData(byte[] data)Read data received into the arrayjava.lang.StringgetDetails()bytegetFIFOStatus()intgetPayloadSize()byte[][]getRXAddresses()Read addresses receiver is listening frombytegetStatus()Read STATUS registerbyte[]getTXAddress()Read transmitter address - source addressbooleaninit(int cePin, int csnPin)Initialize nRF24 chip and set the defaultsbooleanisSending()Test if chip is still sending.voidpowerDown()voidprintDetails(java.io.PrintStream prn)Print detailed information about nRF24 chipbytereadByteRegister(int reg)Reads single one-byte registervoidreadRegister(int reg, byte[] value)Reads an array of bytes from the given start position in the MiRF registers.voidreset()Set initial chip parameters according to nRF24 documentationbooleanrxFifoEmpty()voidsend(byte[] value)Send up to 32 bytes of data.voidsetAddressWidth(int width)Set RX/TX address width.voidsetAutoACK(boolean enable)Enable or disable automatic packet acknowledgements.voidsetAutoACK(int pipe, boolean enable)Enable or disable automatic packet acknowledgements for specific pipe.voidsetChannel(int ch)Set frequency channel nRF24 operates onvoidsetCRCSize(int crcSize)Set CRC sizevoidsetDataRate(int dataRate)Sets data ratevoidsetPALevel(int level)Sets TX output power level.voidsetPayloadSize(int size)Set payload (packet) size for all pipesvoidsetPayloadSize(int pipe, int size)Set payload (packet) size for specific pipevoidsetRADDR(byte[] adr)Sets receiving address P1.voidsetRegisterBits(int reg, byte bits)Set specified bits in single-byte registervoidsetRetries(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.voidsetTADDR(byte[] adr, boolean setP0Too)Sets the transmitting address.java.lang.StringsetupRetrToString(byte value)voidstartListening()Tell NRF24 to start listening.voidstartTestCarrier(int channel, int powerLevel)Start generating testing unodulated carrier wave.java.lang.StringstatusToString(byte status)voidstopListening()Stops receiving.voidstopTestCarrier()Stop generating testing carrier wavevoidterminate()Terminate connection to nRF24 chipbooleantestRPD()Test whether a signal (carrier or otherwise) greater than or equal to -64dBm is present on the channel.intwrite(byte[] value)Send data packet.voidwriteByteRegister(int reg, byte value)Writes value to single-byte register.voidwriteRegister(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()
-