Ein Roboter mit bürstenlosem Antrieb, differenzial und NRF24L01 Funk. Großflächig gebaut um ein großes Solarpanel aufzunehmen. https://gitlab.informatik.hs-fulda.de/fdai5253/roboter
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2030 lines
73 KiB

  1. /*
  2. Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. version 2 as published by the Free Software Foundation.
  6. */
  7. /**
  8. * @file RF24.h
  9. *
  10. * Class declaration for RF24 and helper enums
  11. */
  12. #ifndef __RF24_H__
  13. #define __RF24_H__
  14. #include "RF24_config.h"
  15. #if defined (RF24_LINUX) || defined (LITTLEWIRE)
  16. #include "utility/includes.h"
  17. #elif defined SOFTSPI
  18. #include <DigitalIO.h>
  19. #endif
  20. /**
  21. * Power Amplifier level.
  22. *
  23. * For use with setPALevel()
  24. */
  25. typedef enum { RF24_PA_MIN = 0,RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX, RF24_PA_ERROR } rf24_pa_dbm_e ;
  26. /**
  27. * Data rate. How fast data moves through the air.
  28. *
  29. * For use with setDataRate()
  30. */
  31. typedef enum { RF24_1MBPS = 0, RF24_2MBPS, RF24_250KBPS } rf24_datarate_e;
  32. /**
  33. * CRC Length. How big (if any) of a CRC is included.
  34. *
  35. * For use with setCRCLength()
  36. */
  37. typedef enum { RF24_CRC_DISABLED = 0, RF24_CRC_8, RF24_CRC_16 } rf24_crclength_e;
  38. /**
  39. * Driver for nRF24L01(+) 2.4GHz Wireless Transceiver
  40. */
  41. class RF24
  42. {
  43. private:
  44. #ifdef SOFTSPI
  45. SoftSPI<SOFT_SPI_MISO_PIN, SOFT_SPI_MOSI_PIN, SOFT_SPI_SCK_PIN, SPI_MODE> spi;
  46. #elif defined (SPI_UART)
  47. SPIUARTClass uspi;
  48. #endif
  49. #if defined (RF24_LINUX) || defined (XMEGA_D3) /* XMEGA can use SPI class */
  50. SPI spi;
  51. #endif
  52. #if defined (MRAA)
  53. GPIO gpio;
  54. #endif
  55. uint16_t ce_pin; /**< "Chip Enable" pin, activates the RX or TX role */
  56. uint16_t csn_pin; /**< SPI Chip select */
  57. uint16_t spi_speed; /**< SPI Bus Speed */
  58. #if defined (RF24_LINUX) || defined (XMEGA_D3)
  59. uint8_t spi_rxbuff[32+1] ; //SPI receive buffer (payload max 32 bytes)
  60. uint8_t spi_txbuff[32+1] ; //SPI transmit buffer (payload max 32 bytes + 1 byte for the command)
  61. #endif
  62. bool p_variant; /* False for RF24L01 and true for RF24L01P */
  63. uint8_t payload_size; /**< Fixed size of payloads */
  64. bool dynamic_payloads_enabled; /**< Whether dynamic payloads are enabled. */
  65. uint8_t pipe0_reading_address[5]; /**< Last address set on pipe 0 for reading. */
  66. uint8_t addr_width; /**< The address width to use - 3,4 or 5 bytes. */
  67. protected:
  68. /**
  69. * SPI transactions
  70. *
  71. * Common code for SPI transactions including CSN toggle
  72. *
  73. */
  74. inline void beginTransaction();
  75. inline void endTransaction();
  76. public:
  77. /**
  78. * @name Primary public interface
  79. *
  80. * These are the main methods you need to operate the chip
  81. */
  82. /**@{*/
  83. /**
  84. * Arduino Constructor
  85. *
  86. * Creates a new instance of this driver. Before using, you create an instance
  87. * and send in the unique pins that this chip is connected to.
  88. *
  89. * @param _cepin The pin attached to Chip Enable on the RF module
  90. * @param _cspin The pin attached to Chip Select
  91. */
  92. RF24(uint16_t _cepin, uint16_t _cspin);
  93. //#if defined (RF24_LINUX)
  94. /**
  95. * Optional Linux Constructor
  96. *
  97. * Creates a new instance of this driver. Before using, you create an instance
  98. * and send in the unique pins that this chip is connected to.
  99. *
  100. * @param _cepin The pin attached to Chip Enable on the RF module
  101. * @param _cspin The pin attached to Chip Select
  102. * @param spispeed For RPi, the SPI speed in MHZ ie: BCM2835_SPI_SPEED_8MHZ
  103. */
  104. RF24(uint16_t _cepin, uint16_t _cspin, uint32_t spispeed );
  105. //#endif
  106. #if defined (RF24_LINUX)
  107. virtual ~RF24() {};
  108. #endif
  109. /**
  110. * Begin operation of the chip
  111. *
  112. * Call this in setup(), before calling any other methods.
  113. * @code radio.begin() @endcode
  114. */
  115. bool begin(void);
  116. /**
  117. * Checks if the chip is connected to the SPI bus
  118. */
  119. bool isChipConnected();
  120. /**
  121. * Start listening on the pipes opened for reading.
  122. *
  123. * 1. Be sure to call openReadingPipe() first.
  124. * 2. Do not call write() while in this mode, without first calling stopListening().
  125. * 3. Call available() to check for incoming traffic, and read() to get it.
  126. *
  127. * @code
  128. * Open reading pipe 1 using address CCCECCCECC
  129. *
  130. * byte address[] = { 0xCC,0xCE,0xCC,0xCE,0xCC };
  131. * radio.openReadingPipe(1,address);
  132. * radio.startListening();
  133. * @endcode
  134. */
  135. void startListening(void);
  136. /**
  137. * Stop listening for incoming messages, and switch to transmit mode.
  138. *
  139. * Do this before calling write().
  140. * @code
  141. * radio.stopListening();
  142. * radio.write(&data,sizeof(data));
  143. * @endcode
  144. */
  145. void stopListening(void);
  146. /**
  147. * Check whether there are bytes available to be read
  148. * @code
  149. * if(radio.available()){
  150. * radio.read(&data,sizeof(data));
  151. * }
  152. * @endcode
  153. * @return True if there is a payload available, false if none is
  154. */
  155. bool available(void);
  156. /**
  157. * Read the available payload
  158. *
  159. * The size of data read is the fixed payload size, see getPayloadSize()
  160. *
  161. * @note I specifically chose 'void*' as a data type to make it easier
  162. * for beginners to use. No casting needed.
  163. *
  164. * @note No longer boolean. Use available to determine if packets are
  165. * available. Interrupt flags are now cleared during reads instead of
  166. * when calling available().
  167. *
  168. * @param buf Pointer to a buffer where the data should be written
  169. * @param len Maximum number of bytes to read into the buffer
  170. *
  171. * @code
  172. * if(radio.available()){
  173. * radio.read(&data,sizeof(data));
  174. * }
  175. * @endcode
  176. * @return No return value. Use available().
  177. */
  178. void read( void* buf, uint8_t len );
  179. /**
  180. * Be sure to call openWritingPipe() first to set the destination
  181. * of where to write to.
  182. *
  183. * This blocks until the message is successfully acknowledged by
  184. * the receiver or the timeout/retransmit maxima are reached. In
  185. * the current configuration, the max delay here is 60-70ms.
  186. *
  187. * The maximum size of data written is the fixed payload size, see
  188. * getPayloadSize(). However, you can write less, and the remainder
  189. * will just be filled with zeroes.
  190. *
  191. * TX/RX/RT interrupt flags will be cleared every time write is called
  192. *
  193. * @param buf Pointer to the data to be sent
  194. * @param len Number of bytes to be sent
  195. *
  196. * @code
  197. * radio.stopListening();
  198. * radio.write(&data,sizeof(data));
  199. * @endcode
  200. * @return True if the payload was delivered successfully and an ACK was received, or upon successfull transmission if auto-ack is disabled.
  201. */
  202. bool write( const void* buf, uint8_t len );
  203. /**
  204. * New: Open a pipe for writing via byte array. Old addressing format retained
  205. * for compatibility.
  206. *
  207. * Only one writing pipe can be open at once, but you can change the address
  208. * you'll write to. Call stopListening() first.
  209. *
  210. * Addresses are assigned via a byte array, default is 5 byte address length
  211. s *
  212. * @code
  213. * uint8_t addresses[][6] = {"1Node","2Node"};
  214. * radio.openWritingPipe(addresses[0]);
  215. * @endcode
  216. * @code
  217. * uint8_t address[] = { 0xCC,0xCE,0xCC,0xCE,0xCC };
  218. * radio.openWritingPipe(address);
  219. * address[0] = 0x33;
  220. * radio.openReadingPipe(1,address);
  221. * @endcode
  222. * @see setAddressWidth
  223. *
  224. * @param address The address of the pipe to open. Coordinate these pipe
  225. * addresses amongst nodes on the network.
  226. */
  227. void openWritingPipe(const uint8_t *address);
  228. /**
  229. * Open a pipe for reading
  230. *
  231. * Up to 6 pipes can be open for reading at once. Open all the required
  232. * reading pipes, and then call startListening().
  233. *
  234. * @see openWritingPipe
  235. * @see setAddressWidth
  236. *
  237. * @note Pipes 0 and 1 will store a full 5-byte address. Pipes 2-5 will technically
  238. * only store a single byte, borrowing up to 4 additional bytes from pipe #1 per the
  239. * assigned address width.
  240. * @warning Pipes 1-5 should share the same address, except the first byte.
  241. * Only the first byte in the array should be unique, e.g.
  242. * @code
  243. * uint8_t addresses[][6] = {"1Node","2Node"};
  244. * openReadingPipe(1,addresses[0]);
  245. * openReadingPipe(2,addresses[1]);
  246. * @endcode
  247. *
  248. * @warning Pipe 0 is also used by the writing pipe. So if you open
  249. * pipe 0 for reading, and then startListening(), it will overwrite the
  250. * writing pipe. Ergo, do an openWritingPipe() again before write().
  251. *
  252. * @param number Which pipe# to open, 0-5.
  253. * @param address The 24, 32 or 40 bit address of the pipe to open.
  254. */
  255. void openReadingPipe(uint8_t number, const uint8_t *address);
  256. /**@}*/
  257. /**
  258. * @name Advanced Operation
  259. *
  260. * Methods you can use to drive the chip in more advanced ways
  261. */
  262. /**@{*/
  263. /**
  264. * Print a giant block of debugging information to stdout
  265. *
  266. * @warning Does nothing if stdout is not defined. See fdevopen in stdio.h
  267. * The printf.h file is included with the library for Arduino.
  268. * @code
  269. * #include <printf.h>
  270. * setup(){
  271. * Serial.begin(115200);
  272. * printf_begin();
  273. * ...
  274. * }
  275. * @endcode
  276. */
  277. void printDetails(void);
  278. /**
  279. * Test whether there are bytes available to be read in the
  280. * FIFO buffers.
  281. *
  282. * @param[out] pipe_num Which pipe has the payload available
  283. *
  284. * @code
  285. * uint8_t pipeNum;
  286. * if(radio.available(&pipeNum)){
  287. * radio.read(&data,sizeof(data));
  288. * Serial.print("Got data on pipe");
  289. * Serial.println(pipeNum);
  290. * }
  291. * @endcode
  292. * @return True if there is a payload available, false if none is
  293. */
  294. bool available(uint8_t* pipe_num);
  295. /**
  296. * Check if the radio needs to be read. Can be used to prevent data loss
  297. * @return True if all three 32-byte radio buffers are full
  298. */
  299. bool rxFifoFull();
  300. /**
  301. * Enter low-power mode
  302. *
  303. * To return to normal power mode, call powerUp().
  304. *
  305. * @note After calling startListening(), a basic radio will consume about 13.5mA
  306. * at max PA level.
  307. * During active transmission, the radio will consume about 11.5mA, but this will
  308. * be reduced to 26uA (.026mA) between sending.
  309. * In full powerDown mode, the radio will consume approximately 900nA (.0009mA)
  310. *
  311. * @code
  312. * radio.powerDown();
  313. * avr_enter_sleep_mode(); // Custom function to sleep the device
  314. * radio.powerUp();
  315. * @endcode
  316. */
  317. void powerDown(void);
  318. /**
  319. * Leave low-power mode - required for normal radio operation after calling powerDown()
  320. *
  321. * To return to low power mode, call powerDown().
  322. * @note This will take up to 5ms for maximum compatibility
  323. */
  324. void powerUp(void) ;
  325. /**
  326. * Write for single NOACK writes. Optionally disables acknowledgements/autoretries for a single write.
  327. *
  328. * @note enableDynamicAck() must be called to enable this feature
  329. *
  330. * Can be used with enableAckPayload() to request a response
  331. * @see enableDynamicAck()
  332. * @see setAutoAck()
  333. * @see write()
  334. *
  335. * @param buf Pointer to the data to be sent
  336. * @param len Number of bytes to be sent
  337. * @param multicast Request ACK (0), NOACK (1)
  338. */
  339. bool write( const void* buf, uint8_t len, const bool multicast );
  340. /**
  341. * This will not block until the 3 FIFO buffers are filled with data.
  342. * Once the FIFOs are full, writeFast will simply wait for success or
  343. * timeout, and return 1 or 0 respectively. From a user perspective, just
  344. * keep trying to send the same data. The library will keep auto retrying
  345. * the current payload using the built in functionality.
  346. * @warning It is important to never keep the nRF24L01 in TX mode and FIFO full for more than 4ms at a time. If the auto
  347. * retransmit is enabled, the nRF24L01 is never in TX mode long enough to disobey this rule. Allow the FIFO
  348. * to clear by issuing txStandBy() or ensure appropriate time between transmissions.
  349. *
  350. * @code
  351. * Example (Partial blocking):
  352. *
  353. * radio.writeFast(&buf,32); // Writes 1 payload to the buffers
  354. * txStandBy(); // Returns 0 if failed. 1 if success. Blocks only until MAX_RT timeout or success. Data flushed on fail.
  355. *
  356. * radio.writeFast(&buf,32); // Writes 1 payload to the buffers
  357. * txStandBy(1000); // Using extended timeouts, returns 1 if success. Retries failed payloads for 1 seconds before returning 0.
  358. * @endcode
  359. *
  360. * @see txStandBy()
  361. * @see write()
  362. * @see writeBlocking()
  363. *
  364. * @param buf Pointer to the data to be sent
  365. * @param len Number of bytes to be sent
  366. * @return True if the payload was delivered successfully false if not
  367. */
  368. bool writeFast( const void* buf, uint8_t len );
  369. /**
  370. * WriteFast for single NOACK writes. Disables acknowledgements/autoretries for a single write.
  371. *
  372. * @note enableDynamicAck() must be called to enable this feature
  373. * @see enableDynamicAck()
  374. * @see setAutoAck()
  375. *
  376. * @param buf Pointer to the data to be sent
  377. * @param len Number of bytes to be sent
  378. * @param multicast Request ACK (0) or NOACK (1)
  379. */
  380. bool writeFast( const void* buf, uint8_t len, const bool multicast );
  381. /**
  382. * This function extends the auto-retry mechanism to any specified duration.
  383. * It will not block until the 3 FIFO buffers are filled with data.
  384. * If so the library will auto retry until a new payload is written
  385. * or the user specified timeout period is reached.
  386. * @warning It is important to never keep the nRF24L01 in TX mode and FIFO full for more than 4ms at a time. If the auto
  387. * retransmit is enabled, the nRF24L01 is never in TX mode long enough to disobey this rule. Allow the FIFO
  388. * to clear by issuing txStandBy() or ensure appropriate time between transmissions.
  389. *
  390. * @code
  391. * Example (Full blocking):
  392. *
  393. * radio.writeBlocking(&buf,32,1000); //Wait up to 1 second to write 1 payload to the buffers
  394. * txStandBy(1000); //Wait up to 1 second for the payload to send. Return 1 if ok, 0 if failed.
  395. * //Blocks only until user timeout or success. Data flushed on fail.
  396. * @endcode
  397. * @note If used from within an interrupt, the interrupt should be disabled until completion, and sei(); called to enable millis().
  398. * @see txStandBy()
  399. * @see write()
  400. * @see writeFast()
  401. *
  402. * @param buf Pointer to the data to be sent
  403. * @param len Number of bytes to be sent
  404. * @param timeout User defined timeout in milliseconds.
  405. * @return True if the payload was loaded into the buffer successfully false if not
  406. */
  407. bool writeBlocking( const void* buf, uint8_t len, uint32_t timeout );
  408. /**
  409. * This function should be called as soon as transmission is finished to
  410. * drop the radio back to STANDBY-I mode. If not issued, the radio will
  411. * remain in STANDBY-II mode which, per the data sheet, is not a recommended
  412. * operating mode.
  413. *
  414. * @note When transmitting data in rapid succession, it is still recommended by
  415. * the manufacturer to drop the radio out of TX or STANDBY-II mode if there is
  416. * time enough between sends for the FIFOs to empty. This is not required if auto-ack
  417. * is enabled.
  418. *
  419. * Relies on built-in auto retry functionality.
  420. *
  421. * @code
  422. * Example (Partial blocking):
  423. *
  424. * radio.writeFast(&buf,32);
  425. * radio.writeFast(&buf,32);
  426. * radio.writeFast(&buf,32); //Fills the FIFO buffers up
  427. * bool ok = txStandBy(); //Returns 0 if failed. 1 if success.
  428. * //Blocks only until MAX_RT timeout or success. Data flushed on fail.
  429. * @endcode
  430. * @see txStandBy(unsigned long timeout)
  431. * @return True if transmission is successful
  432. *
  433. */
  434. bool txStandBy();
  435. /**
  436. * This function allows extended blocking and auto-retries per a user defined timeout
  437. * @code
  438. * Fully Blocking Example:
  439. *
  440. * radio.writeFast(&buf,32);
  441. * radio.writeFast(&buf,32);
  442. * radio.writeFast(&buf,32); //Fills the FIFO buffers up
  443. * bool ok = txStandBy(1000); //Returns 0 if failed after 1 second of retries. 1 if success.
  444. * //Blocks only until user defined timeout or success. Data flushed on fail.
  445. * @endcode
  446. * @note If used from within an interrupt, the interrupt should be disabled until completion, and sei(); called to enable millis().
  447. * @param timeout Number of milliseconds to retry failed payloads
  448. * @return True if transmission is successful
  449. *
  450. */
  451. bool txStandBy(uint32_t timeout, bool startTx = 0);
  452. /**
  453. * Write an ack payload for the specified pipe
  454. *
  455. * The next time a message is received on @p pipe, the data in @p buf will
  456. * be sent back in the acknowledgement.
  457. * @see enableAckPayload()
  458. * @see enableDynamicPayloads()
  459. * @warning Only three of these can be pending at any time as there are only 3 FIFO buffers.<br> Dynamic payloads must be enabled.
  460. * @note Ack payloads are handled automatically by the radio chip when a payload is received. Users should generally
  461. * write an ack payload as soon as startListening() is called, so one is available when a regular payload is received.
  462. * @note Ack payloads are dynamic payloads. This only works on pipes 0&1 by default. Call
  463. * enableDynamicPayloads() to enable on all pipes.
  464. *
  465. * @param pipe Which pipe# (typically 1-5) will get this response.
  466. * @param buf Pointer to data that is sent
  467. * @param len Length of the data to send, up to 32 bytes max. Not affected
  468. * by the static payload set by setPayloadSize().
  469. */
  470. void writeAckPayload(uint8_t pipe, const void* buf, uint8_t len);
  471. /**
  472. * Determine if an ack payload was received in the most recent call to
  473. * write(). The regular available() can also be used.
  474. *
  475. * Call read() to retrieve the ack payload.
  476. *
  477. * @return True if an ack payload is available.
  478. */
  479. bool isAckPayloadAvailable(void);
  480. /**
  481. * Call this when you get an interrupt to find out why
  482. *
  483. * Tells you what caused the interrupt, and clears the state of
  484. * interrupts.
  485. *
  486. * @param[out] tx_ok The send was successful (TX_DS)
  487. * @param[out] tx_fail The send failed, too many retries (MAX_RT)
  488. * @param[out] rx_ready There is a message waiting to be read (RX_DS)
  489. */
  490. void whatHappened(bool& tx_ok,bool& tx_fail,bool& rx_ready);
  491. /**
  492. * Non-blocking write to the open writing pipe used for buffered writes
  493. *
  494. * @note Optimization: This function now leaves the CE pin high, so the radio
  495. * will remain in TX or STANDBY-II Mode until a txStandBy() command is issued. Can be used as an alternative to startWrite()
  496. * if writing multiple payloads at once.
  497. * @warning It is important to never keep the nRF24L01 in TX mode with FIFO full for more than 4ms at a time. If the auto
  498. * retransmit/autoAck is enabled, the nRF24L01 is never in TX mode long enough to disobey this rule. Allow the FIFO
  499. * to clear by issuing txStandBy() or ensure appropriate time between transmissions.
  500. *
  501. * @see write()
  502. * @see writeFast()
  503. * @see startWrite()
  504. * @see writeBlocking()
  505. *
  506. * For single noAck writes see:
  507. * @see enableDynamicAck()
  508. * @see setAutoAck()
  509. *
  510. * @param buf Pointer to the data to be sent
  511. * @param len Number of bytes to be sent
  512. * @param multicast Request ACK (0) or NOACK (1)
  513. * @return True if the payload was delivered successfully false if not
  514. */
  515. void startFastWrite( const void* buf, uint8_t len, const bool multicast, bool startTx = 1 );
  516. /**
  517. * Non-blocking write to the open writing pipe
  518. *
  519. * Just like write(), but it returns immediately. To find out what happened
  520. * to the send, catch the IRQ and then call whatHappened().
  521. *
  522. * @see write()
  523. * @see writeFast()
  524. * @see startFastWrite()
  525. * @see whatHappened()
  526. *
  527. * For single noAck writes see:
  528. * @see enableDynamicAck()
  529. * @see setAutoAck()
  530. *
  531. * @param buf Pointer to the data to be sent
  532. * @param len Number of bytes to be sent
  533. * @param multicast Request ACK (0) or NOACK (1)
  534. *
  535. */
  536. void startWrite( const void* buf, uint8_t len, const bool multicast );
  537. /**
  538. * This function is mainly used internally to take advantage of the auto payload
  539. * re-use functionality of the chip, but can be beneficial to users as well.
  540. *
  541. * The function will instruct the radio to re-use the data in the FIFO buffers,
  542. * and instructs the radio to re-send once the timeout limit has been reached.
  543. * Used by writeFast and writeBlocking to initiate retries when a TX failure
  544. * occurs. Retries are automatically initiated except with the standard write().
  545. * This way, data is not flushed from the buffer until switching between modes.
  546. *
  547. * @note This is to be used AFTER auto-retry fails if wanting to resend
  548. * using the built-in payload reuse features.
  549. * After issuing reUseTX(), it will keep reending the same payload forever or until
  550. * a payload is written to the FIFO, or a flush_tx command is given.
  551. */
  552. void reUseTX();
  553. /**
  554. * Empty the transmit buffer. This is generally not required in standard operation.
  555. * May be required in specific cases after stopListening() , if operating at 250KBPS data rate.
  556. *
  557. * @return Current value of status register
  558. */
  559. uint8_t flush_tx(void);
  560. /**
  561. * Test whether there was a carrier on the line for the
  562. * previous listening period.
  563. *
  564. * Useful to check for interference on the current channel.
  565. *
  566. * @return true if was carrier, false if not
  567. */
  568. bool testCarrier(void);
  569. /**
  570. * Test whether a signal (carrier or otherwise) greater than
  571. * or equal to -64dBm is present on the channel. Valid only
  572. * on nRF24L01P (+) hardware. On nRF24L01, use testCarrier().
  573. *
  574. * Useful to check for interference on the current channel and
  575. * channel hopping strategies.
  576. *
  577. * @code
  578. * bool goodSignal = radio.testRPD();
  579. * if(radio.available()){
  580. * Serial.println(goodSignal ? "Strong signal > 64dBm" : "Weak signal < 64dBm" );
  581. * radio.read(0,0);
  582. * }
  583. * @endcode
  584. * @return true if signal => -64dBm, false if not
  585. */
  586. bool testRPD(void) ;
  587. /**
  588. * Test whether this is a real radio, or a mock shim for
  589. * debugging. Setting either pin to 0xff is the way to
  590. * indicate that this is not a real radio.
  591. *
  592. * @return true if this is a legitimate radio
  593. */
  594. bool isValid() { return ce_pin != 0xff && csn_pin != 0xff; }
  595. /**
  596. * Close a pipe after it has been previously opened.
  597. * Can be safely called without having previously opened a pipe.
  598. * @param pipe Which pipe # to close, 0-5.
  599. */
  600. void closeReadingPipe( uint8_t pipe ) ;
  601. /**
  602. *
  603. * If a failure has been detected, it usually indicates a hardware issue. By default the library
  604. * will cease operation when a failure is detected.
  605. * This should allow advanced users to detect and resolve intermittent hardware issues.
  606. *
  607. * In most cases, the radio must be re-enabled via radio.begin(); and the appropriate settings
  608. * applied after a failure occurs, if wanting to re-enable the device immediately.
  609. *
  610. * The three main failure modes of the radio include:
  611. *
  612. * Writing to radio: Radio unresponsive - Fixed internally by adding a timeout to the internal write functions in RF24 (failure handling)
  613. *
  614. * Reading from radio: Available returns true always - Fixed by adding a timeout to available functions by the user. This is implemented internally in RF24Network.
  615. *
  616. * Radio configuration settings are lost - Fixed by monitoring a value that is different from the default, and re-configuring the radio if this setting reverts to the default.
  617. *
  618. * See the included example, GettingStarted_HandlingFailures
  619. *
  620. * @code
  621. * if(radio.failureDetected){
  622. * radio.begin(); // Attempt to re-configure the radio with defaults
  623. * radio.failureDetected = 0; // Reset the detection value
  624. * radio.openWritingPipe(addresses[1]); // Re-configure pipe addresses
  625. * radio.openReadingPipe(1,addresses[0]);
  626. * report_failure(); // Blink leds, send a message, etc. to indicate failure
  627. * }
  628. * @endcode
  629. */
  630. //#if defined (FAILURE_HANDLING)
  631. bool failureDetected;
  632. //#endif
  633. /**@}*/
  634. /**@}*/
  635. /**
  636. * @name Optional Configurators
  637. *
  638. * Methods you can use to get or set the configuration of the chip.
  639. * None are required. Calling begin() sets up a reasonable set of
  640. * defaults.
  641. */
  642. /**@{*/
  643. /**
  644. * Set the address width from 3 to 5 bytes (24, 32 or 40 bit)
  645. *
  646. * @param a_width The address width to use: 3,4 or 5
  647. */
  648. void setAddressWidth(uint8_t a_width);
  649. /**
  650. * Set the number and delay of retries upon failed submit
  651. *
  652. * @param delay How long to wait between each retry, in multiples of 250us,
  653. * max is 15. 0 means 250us, 15 means 4000us.
  654. * @param count How many retries before giving up, max 15
  655. */
  656. void setRetries(uint8_t delay, uint8_t count);
  657. /**
  658. * Set RF communication channel
  659. *
  660. * @param channel Which RF channel to communicate on, 0-125
  661. */
  662. void setChannel(uint8_t channel);
  663. /**
  664. * Get RF communication channel
  665. *
  666. * @return The currently configured RF Channel
  667. */
  668. uint8_t getChannel(void);
  669. /**
  670. * Set Static Payload Size
  671. *
  672. * This implementation uses a pre-stablished fixed payload size for all
  673. * transmissions. If this method is never called, the driver will always
  674. * transmit the maximum payload size (32 bytes), no matter how much
  675. * was sent to write().
  676. *
  677. * @todo Implement variable-sized payloads feature
  678. *
  679. * @param size The number of bytes in the payload
  680. */
  681. void setPayloadSize(uint8_t size);
  682. /**
  683. * Get Static Payload Size
  684. *
  685. * @see setPayloadSize()
  686. *
  687. * @return The number of bytes in the payload
  688. */
  689. uint8_t getPayloadSize(void);
  690. /**
  691. * Get Dynamic Payload Size
  692. *
  693. * For dynamic payloads, this pulls the size of the payload off
  694. * the chip
  695. *
  696. * @note Corrupt packets are now detected and flushed per the
  697. * manufacturer.
  698. * @code
  699. * if(radio.available()){
  700. * if(radio.getDynamicPayloadSize() < 1){
  701. * // Corrupt payload has been flushed
  702. * return;
  703. * }
  704. * radio.read(&data,sizeof(data));
  705. * }
  706. * @endcode
  707. *
  708. * @return Payload length of last-received dynamic payload
  709. */
  710. uint8_t getDynamicPayloadSize(void);
  711. /**
  712. * Enable custom payloads on the acknowledge packets
  713. *
  714. * Ack payloads are a handy way to return data back to senders without
  715. * manually changing the radio modes on both units.
  716. *
  717. * @note Ack payloads are dynamic payloads. This only works on pipes 0&1 by default. Call
  718. * enableDynamicPayloads() to enable on all pipes.
  719. */
  720. void enableAckPayload(void);
  721. /**
  722. * Enable dynamically-sized payloads
  723. *
  724. * This way you don't always have to send large packets just to send them
  725. * once in a while. This enables dynamic payloads on ALL pipes.
  726. *
  727. */
  728. void enableDynamicPayloads(void);
  729. /**
  730. * Disable dynamically-sized payloads
  731. *
  732. * This disables dynamic payloads on ALL pipes. Since Ack Payloads
  733. * requires Dynamic Payloads, Ack Payloads are also disabled.
  734. * If dynamic payloads are later re-enabled and ack payloads are desired
  735. * then enableAckPayload() must be called again as well.
  736. *
  737. */
  738. void disableDynamicPayloads(void);
  739. /**
  740. * Enable dynamic ACKs (single write multicast or unicast) for chosen messages
  741. *
  742. * @note To enable full multicast or per-pipe multicast, use setAutoAck()
  743. *
  744. * @warning This MUST be called prior to attempting single write NOACK calls
  745. * @code
  746. * radio.enableDynamicAck();
  747. * radio.write(&data,32,1); // Sends a payload with no acknowledgement requested
  748. * radio.write(&data,32,0); // Sends a payload using auto-retry/autoACK
  749. * @endcode
  750. */
  751. void enableDynamicAck();
  752. /**
  753. * Determine whether the hardware is an nRF24L01+ or not.
  754. *
  755. * @return true if the hardware is nRF24L01+ (or compatible) and false
  756. * if its not.
  757. */
  758. bool isPVariant(void) ;
  759. /**
  760. * Enable or disable auto-acknowlede packets
  761. *
  762. * This is enabled by default, so it's only needed if you want to turn
  763. * it off for some reason.
  764. *
  765. * @param enable Whether to enable (true) or disable (false) auto-acks
  766. */
  767. void setAutoAck(bool enable);
  768. /**
  769. * Enable or disable auto-acknowlede packets on a per pipeline basis.
  770. *
  771. * AA is enabled by default, so it's only needed if you want to turn
  772. * it off/on for some reason on a per pipeline basis.
  773. *
  774. * @param pipe Which pipeline to modify
  775. * @param enable Whether to enable (true) or disable (false) auto-acks
  776. */
  777. void setAutoAck( uint8_t pipe, bool enable ) ;
  778. /**
  779. * Set Power Amplifier (PA) level to one of four levels:
  780. * RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH and RF24_PA_MAX
  781. *
  782. * The power levels correspond to the following output levels respectively:
  783. * NRF24L01: -18dBm, -12dBm,-6dBM, and 0dBm
  784. *
  785. * SI24R1: -6dBm, 0dBm, 3dBM, and 7dBm.
  786. *
  787. * @param level Desired PA level.
  788. */
  789. void setPALevel ( uint8_t level );
  790. /**
  791. * Fetches the current PA level.
  792. *
  793. * NRF24L01: -18dBm, -12dBm, -6dBm and 0dBm
  794. * SI24R1: -6dBm, 0dBm, 3dBm, 7dBm
  795. *
  796. * @return Returns values 0 to 3 representing the PA Level.
  797. */
  798. uint8_t getPALevel( void );
  799. /**
  800. * Set the transmission data rate
  801. *
  802. * @warning setting RF24_250KBPS will fail for non-plus units
  803. *
  804. * @param speed RF24_250KBPS for 250kbs, RF24_1MBPS for 1Mbps, or RF24_2MBPS for 2Mbps
  805. * @return true if the change was successful
  806. */
  807. bool setDataRate(rf24_datarate_e speed);
  808. /**
  809. * Fetches the transmission data rate
  810. *
  811. * @return Returns the hardware's currently configured datarate. The value
  812. * is one of 250kbs, RF24_1MBPS for 1Mbps, or RF24_2MBPS, as defined in the
  813. * rf24_datarate_e enum.
  814. */
  815. rf24_datarate_e getDataRate( void ) ;
  816. /**
  817. * Set the CRC length
  818. * <br>CRC checking cannot be disabled if auto-ack is enabled
  819. * @param length RF24_CRC_8 for 8-bit or RF24_CRC_16 for 16-bit
  820. */
  821. void setCRCLength(rf24_crclength_e length);
  822. /**
  823. * Get the CRC length
  824. * <br>CRC checking cannot be disabled if auto-ack is enabled
  825. * @return RF24_CRC_DISABLED if disabled or RF24_CRC_8 for 8-bit or RF24_CRC_16 for 16-bit
  826. */
  827. rf24_crclength_e getCRCLength(void);
  828. /**
  829. * Disable CRC validation
  830. *
  831. * @warning CRC cannot be disabled if auto-ack/ESB is enabled.
  832. */
  833. void disableCRC( void ) ;
  834. /**
  835. * The radio will generate interrupt signals when a transmission is complete,
  836. * a transmission fails, or a payload is received. This allows users to mask
  837. * those interrupts to prevent them from generating a signal on the interrupt
  838. * pin. Interrupts are enabled on the radio chip by default.
  839. *
  840. * @code
  841. * Mask all interrupts except the receive interrupt:
  842. *
  843. * radio.maskIRQ(1,1,0);
  844. * @endcode
  845. *
  846. * @param tx_ok Mask transmission complete interrupts
  847. * @param tx_fail Mask transmit failure interrupts
  848. * @param rx_ready Mask payload received interrupts
  849. */
  850. void maskIRQ(bool tx_ok,bool tx_fail,bool rx_ready);
  851. /**
  852. *
  853. * The driver will delay for this duration when stopListening() is called
  854. *
  855. * When responding to payloads, faster devices like ARM(RPi) are much faster than Arduino:
  856. * 1. Arduino sends data to RPi, switches to RX mode
  857. * 2. The RPi receives the data, switches to TX mode and sends before the Arduino radio is in RX mode
  858. * 3. If AutoACK is disabled, this can be set as low as 0. If AA/ESB enabled, set to 100uS minimum on RPi
  859. *
  860. * @warning If set to 0, ensure 130uS delay after stopListening() and before any sends
  861. */
  862. uint32_t txDelay;
  863. /**
  864. *
  865. * On all devices but Linux and ATTiny, a small delay is added to the CSN toggling function
  866. *
  867. * This is intended to minimise the speed of SPI polling due to radio commands
  868. *
  869. * If using interrupts or timed requests, this can be set to 0 Default:5
  870. */
  871. uint32_t csDelay;
  872. /**@}*/
  873. /**
  874. * @name Deprecated
  875. *
  876. * Methods provided for backwards compabibility.
  877. */
  878. /**@{*/
  879. /**
  880. * Open a pipe for reading
  881. * @note For compatibility with old code only, see new function
  882. *
  883. * @warning Pipes 1-5 should share the first 32 bits.
  884. * Only the least significant byte should be unique, e.g.
  885. * @code
  886. * openReadingPipe(1,0xF0F0F0F0AA);
  887. * openReadingPipe(2,0xF0F0F0F066);
  888. * @endcode
  889. *
  890. * @warning Pipe 0 is also used by the writing pipe. So if you open
  891. * pipe 0 for reading, and then startListening(), it will overwrite the
  892. * writing pipe. Ergo, do an openWritingPipe() again before write().
  893. *
  894. * @param number Which pipe# to open, 0-5.
  895. * @param address The 40-bit address of the pipe to open.
  896. */
  897. void openReadingPipe(uint8_t number, uint64_t address);
  898. /**
  899. * Open a pipe for writing
  900. * @note For compatibility with old code only, see new function
  901. *
  902. * Addresses are 40-bit hex values, e.g.:
  903. *
  904. * @code
  905. * openWritingPipe(0xF0F0F0F0F0);
  906. * @endcode
  907. *
  908. * @param address The 40-bit address of the pipe to open.
  909. */
  910. void openWritingPipe(uint64_t address);
  911. /**
  912. * Empty the receive buffer
  913. *
  914. * @return Current value of status register
  915. */
  916. uint8_t flush_rx(void);
  917. private:
  918. /**
  919. * @name Low-level internal interface.
  920. *
  921. * Protected methods that address the chip directly. Regular users cannot
  922. * ever call these. They are documented for completeness and for developers who
  923. * may want to extend this class.
  924. */
  925. /**@{*/
  926. /**
  927. * Set chip select pin
  928. *
  929. * Running SPI bus at PI_CLOCK_DIV2 so we don't waste time transferring data
  930. * and best of all, we make use of the radio's FIFO buffers. A lower speed
  931. * means we're less likely to effectively leverage our FIFOs and pay a higher
  932. * AVR runtime cost as toll.
  933. *
  934. * @param mode HIGH to take this unit off the SPI bus, LOW to put it on
  935. */
  936. void csn(bool mode);
  937. /**
  938. * Set chip enable
  939. *
  940. * @param level HIGH to actively begin transmission or LOW to put in standby. Please see data sheet
  941. * for a much more detailed description of this pin.
  942. */
  943. void ce(bool level);
  944. /**
  945. * Read a chunk of data in from a register
  946. *
  947. * @param reg Which register. Use constants from nRF24L01.h
  948. * @param buf Where to put the data
  949. * @param len How many bytes of data to transfer
  950. * @return Current value of status register
  951. */
  952. uint8_t read_register(uint8_t reg, uint8_t* buf, uint8_t len);
  953. /**
  954. * Read single byte from a register
  955. *
  956. * @param reg Which register. Use constants from nRF24L01.h
  957. * @return Current value of register @p reg
  958. */
  959. uint8_t read_register(uint8_t reg);
  960. /**
  961. * Write a chunk of data to a register
  962. *
  963. * @param reg Which register. Use constants from nRF24L01.h
  964. * @param buf Where to get the data
  965. * @param len How many bytes of data to transfer
  966. * @return Current value of status register
  967. */
  968. uint8_t write_register(uint8_t reg, const uint8_t* buf, uint8_t len);
  969. /**
  970. * Write a single byte to a register
  971. *
  972. * @param reg Which register. Use constants from nRF24L01.h
  973. * @param value The new value to write
  974. * @return Current value of status register
  975. */
  976. uint8_t write_register(uint8_t reg, uint8_t value);
  977. /**
  978. * Write the transmit payload
  979. *
  980. * The size of data written is the fixed payload size, see getPayloadSize()
  981. *
  982. * @param buf Where to get the data
  983. * @param len Number of bytes to be sent
  984. * @return Current value of status register
  985. */
  986. uint8_t write_payload(const void* buf, uint8_t len, const uint8_t writeType);
  987. /**
  988. * Read the receive payload
  989. *
  990. * The size of data read is the fixed payload size, see getPayloadSize()
  991. *
  992. * @param buf Where to put the data
  993. * @param len Maximum number of bytes to read
  994. * @return Current value of status register
  995. */
  996. uint8_t read_payload(void* buf, uint8_t len);
  997. /**
  998. * Retrieve the current status of the chip
  999. *
  1000. * @return Current value of status register
  1001. */
  1002. uint8_t get_status(void);
  1003. #if !defined (MINIMAL)
  1004. /**
  1005. * Decode and print the given status to stdout
  1006. *
  1007. * @param status Status value to print
  1008. *
  1009. * @warning Does nothing if stdout is not defined. See fdevopen in stdio.h
  1010. */
  1011. void print_status(uint8_t status);
  1012. /**
  1013. * Decode and print the given 'observe_tx' value to stdout
  1014. *
  1015. * @param value The observe_tx value to print
  1016. *
  1017. * @warning Does nothing if stdout is not defined. See fdevopen in stdio.h
  1018. */
  1019. void print_observe_tx(uint8_t value);
  1020. /**
  1021. * Print the name and value of an 8-bit register to stdout
  1022. *
  1023. * Optionally it can print some quantity of successive
  1024. * registers on the same line. This is useful for printing a group
  1025. * of related registers on one line.
  1026. *
  1027. * @param name Name of the register
  1028. * @param reg Which register. Use constants from nRF24L01.h
  1029. * @param qty How many successive registers to print
  1030. */
  1031. void print_byte_register(const char* name, uint8_t reg, uint8_t qty = 1);
  1032. /**
  1033. * Print the name and value of a 40-bit address register to stdout
  1034. *
  1035. * Optionally it can print some quantity of successive
  1036. * registers on the same line. This is useful for printing a group
  1037. * of related registers on one line.
  1038. *
  1039. * @param name Name of the register
  1040. * @param reg Which register. Use constants from nRF24L01.h
  1041. * @param qty How many successive registers to print
  1042. */
  1043. void print_address_register(const char* name, uint8_t reg, uint8_t qty = 1);
  1044. #endif
  1045. /**
  1046. * Turn on or off the special features of the chip
  1047. *
  1048. * The chip has certain 'features' which are only available when the 'features'
  1049. * are enabled. See the datasheet for details.
  1050. */
  1051. void toggle_features(void);
  1052. /**
  1053. * Built in spi transfer function to simplify repeating code repeating code
  1054. */
  1055. uint8_t spiTrans(uint8_t cmd);
  1056. #if defined (FAILURE_HANDLING) || defined (RF24_LINUX)
  1057. void errNotify(void);
  1058. #endif
  1059. /**@}*/
  1060. };
  1061. /**
  1062. * @example GettingStarted.ino
  1063. * <b>For Arduino</b><br>
  1064. * <b>Updated: TMRh20 2014 </b><br>
  1065. *
  1066. * This is an example of how to use the RF24 class to communicate on a basic level. Configure and write this sketch to two
  1067. * different nodes. Put one of the nodes into 'transmit' mode by connecting with the serial monitor and <br>
  1068. * sending a 'T'. The ping node sends the current time to the pong node, which responds by sending the value
  1069. * back. The ping node can then see how long the whole cycle took. <br>
  1070. * @note For a more efficient call-response scenario see the GettingStarted_CallResponse.ino example.
  1071. * @note When switching between sketches, the radio may need to be powered down to clear settings that are not "un-set" otherwise
  1072. */
  1073. /**
  1074. * @example gettingstarted.cpp
  1075. * <b>For Linux</b><br>
  1076. * <b>Updated: TMRh20 2014 </b><br>
  1077. *
  1078. * This is an example of how to use the RF24 class to communicate on a basic level. Configure and write this sketch to two
  1079. * different nodes. Put one of the nodes into 'transmit' mode by connecting with the serial monitor and <br>
  1080. * sending a 'T'. The ping node sends the current time to the pong node, which responds by sending the value
  1081. * back. The ping node can then see how long the whole cycle took. <br>
  1082. * @note For a more efficient call-response scenario see the GettingStarted_CallResponse.ino example.
  1083. */
  1084. /**
  1085. * @example GettingStarted_CallResponse.ino
  1086. * <b>For Arduino</b><br>
  1087. * <b>New: TMRh20 2014</b><br>
  1088. *
  1089. * This example continues to make use of all the normal functionality of the radios including
  1090. * the auto-ack and auto-retry features, but allows ack-payloads to be written optionlly as well. <br>
  1091. * This allows very fast call-response communication, with the responding radio never having to
  1092. * switch out of Primary Receiver mode to send back a payload, but having the option to switch to <br>
  1093. * primary transmitter if wanting to initiate communication instead of respond to a commmunication.
  1094. */
  1095. /**
  1096. * @example gettingstarted_call_response.cpp
  1097. * <b>For Linux</b><br>
  1098. * <b>New: TMRh20 2014</b><br>
  1099. *
  1100. * This example continues to make use of all the normal functionality of the radios including
  1101. * the auto-ack and auto-retry features, but allows ack-payloads to be written optionlly as well. <br>
  1102. * This allows very fast call-response communication, with the responding radio never having to
  1103. * switch out of Primary Receiver mode to send back a payload, but having the option to switch to <br>
  1104. * primary transmitter if wanting to initiate communication instead of respond to a commmunication.
  1105. */
  1106. /**
  1107. * @example GettingStarted_HandlingData.ino
  1108. * <b>Dec 2014 - TMRh20</b><br>
  1109. *
  1110. * This example demonstrates how to send multiple variables in a single payload and work with data. As usual, it is
  1111. * generally important to include an incrementing value like millis() in the payloads to prevent errors.
  1112. */
  1113. /**
  1114. * @example GettingStarted_HandlingFailures.ino
  1115. *
  1116. * This example demonstrates the basic getting started functionality, but with failure handling for the radio chip.
  1117. * Addresses random radio failures etc, potentially due to loose wiring on breadboards etc.
  1118. */
  1119. /**
  1120. * @example Transfer.ino
  1121. * <b>For Arduino</b><br>
  1122. * This example demonstrates half-rate transfer using the FIFO buffers<br>
  1123. *
  1124. * It is an example of how to use the RF24 class. Write this sketch to two
  1125. * different nodes. Put one of the nodes into 'transmit' mode by connecting <br>
  1126. * with the serial monitor and sending a 'T'. The data transfer will begin,
  1127. * with the receiver displaying the payload count. (32Byte Payloads) <br>
  1128. */
  1129. /**
  1130. * @example transfer.cpp
  1131. * <b>For Linux</b><br>
  1132. * This example demonstrates half-rate transfer using the FIFO buffers<br>
  1133. *
  1134. * It is an example of how to use the RF24 class. Write this sketch to two
  1135. * different nodes. Put one of the nodes into 'transmit' mode by connecting <br>
  1136. * with the serial monitor and sending a 'T'. The data transfer will begin,
  1137. * with the receiver displaying the payload count. (32Byte Payloads) <br>
  1138. */
  1139. /**
  1140. * @example TransferTimeouts.ino
  1141. * <b>New: TMRh20 </b><br>
  1142. * This example demonstrates the use of and extended timeout period and
  1143. * auto-retries/auto-reUse to increase reliability in noisy or low signal scenarios. <br>
  1144. *
  1145. * Write this sketch to two different nodes. Put one of the nodes into 'transmit'
  1146. * mode by connecting with the serial monitor and sending a 'T'. The data <br>
  1147. * transfer will begin, with the receiver displaying the payload count and the
  1148. * data transfer rate.
  1149. */
  1150. /**
  1151. * @example starping.pde
  1152. *
  1153. * This sketch is a more complex example of using the RF24 library for Arduino.
  1154. * Deploy this on up to six nodes. Set one as the 'pong receiver' by tying the
  1155. * role_pin low, and the others will be 'ping transmit' units. The ping units
  1156. * unit will send out the value of millis() once a second. The pong unit will
  1157. * respond back with a copy of the value. Each ping unit can get that response
  1158. * back, and determine how long the whole cycle took.
  1159. *
  1160. * This example requires a bit more complexity to determine which unit is which.
  1161. * The pong receiver is identified by having its role_pin tied to ground.
  1162. * The ping senders are further differentiated by a byte in eeprom.
  1163. */
  1164. /**
  1165. * @example pingpair_ack.ino
  1166. * <b>Update: TMRh20</b><br>
  1167. * This example continues to make use of all the normal functionality of the radios including
  1168. * the auto-ack and auto-retry features, but allows ack-payloads to be written optionlly as well.<br>
  1169. * This allows very fast call-response communication, with the responding radio never having to
  1170. * switch out of Primary Receiver mode to send back a payload, but having the option to if wanting<br>
  1171. * to initiate communication instead of respond to a commmunication.
  1172. */
  1173. /**
  1174. * @example pingpair_irq.ino
  1175. * <b>Update: TMRh20</b><br>
  1176. * This is an example of how to user interrupts to interact with the radio, and a demonstration
  1177. * of how to use them to sleep when receiving, and not miss any payloads.<br>
  1178. * The pingpair_sleepy example expands on sleep functionality with a timed sleep option for the transmitter.
  1179. * Sleep functionality is built directly into my fork of the RF24Network library<br>
  1180. */
  1181. /**
  1182. * @example pingpair_irq_simple.ino
  1183. * <b>Dec 2014 - TMRh20</b><br>
  1184. * This is an example of how to user interrupts to interact with the radio, with bidirectional communication.
  1185. */
  1186. /**
  1187. * @example pingpair_sleepy.ino
  1188. * <b>Update: TMRh20</b><br>
  1189. * This is an example of how to use the RF24 class to create a battery-
  1190. * efficient system. It is just like the GettingStarted_CallResponse example, but the<br>
  1191. * ping node powers down the radio and sleeps the MCU after every
  1192. * ping/pong cycle, and the receiver sleeps between payloads. <br>
  1193. */
  1194. /**
  1195. * @example rf24ping85.ino
  1196. * <b>New: Contributed by https://github.com/tong67</b><br>
  1197. * This is an example of how to use the RF24 class to communicate with ATtiny85 and other node. <br>
  1198. */
  1199. /**
  1200. * @example timingSearch3pin.ino
  1201. * <b>New: Contributed by https://github.com/tong67</b><br>
  1202. * This is an example of how to determine the correct timing for ATtiny when using only 3-pins
  1203. */
  1204. /**
  1205. * @example pingpair_dyn.ino
  1206. *
  1207. * This is an example of how to use payloads of a varying (dynamic) size on Arduino.
  1208. */
  1209. /**
  1210. * @example pingpair_dyn.cpp
  1211. *
  1212. * This is an example of how to use payloads of a varying (dynamic) size on Linux.
  1213. */
  1214. /**
  1215. * @example pingpair_dyn.py
  1216. *
  1217. * This is a python example for RPi of how to use payloads of a varying (dynamic) size.
  1218. */
  1219. /**
  1220. * @example scanner.ino
  1221. *
  1222. * Example to detect interference on the various channels available.
  1223. * This is a good diagnostic tool to check whether you're picking a
  1224. * good channel for your application.
  1225. *
  1226. * Inspired by cpixip.
  1227. * See http://arduino.cc/forum/index.php/topic,54795.0.html
  1228. */
  1229. /**
  1230. * @mainpage Optimized High Speed Driver for nRF24L01(+) 2.4GHz Wireless Transceiver
  1231. *
  1232. * @section Goals Design Goals
  1233. *
  1234. * This library fork is designed to be...
  1235. * @li More compliant with the manufacturer specified operation of the chip, while allowing advanced users
  1236. * to work outside the recommended operation.
  1237. * @li Utilize the capabilities of the radio to their full potential via Arduino
  1238. * @li More reliable, responsive, bug-free and feature rich
  1239. * @li Easy for beginners to use, with well documented examples and features
  1240. * @li Consumed with a public interface that's similar to other Arduino standard libraries
  1241. *
  1242. * @section News News
  1243. *
  1244. * **Dec 2015**<br>
  1245. * - ESP8266 support via Arduino IDE
  1246. * - <a href="https://github.com/stewarthou/Particle-RF24">Particle Photon/Core</a> fork available
  1247. * - ATTiny2313/4313 support added
  1248. * - Python 3 support added
  1249. * - RF24 added to Arduino library manager
  1250. * - RF24 added to PlatformIO library manager
  1251. *
  1252. * **March 2015**<br>
  1253. * - Uses SPI transactions on Arduino
  1254. * - New layout for <a href="Portability.html">easier portability:</a> Break out defines & includes for individual platforms to RF24/utility
  1255. * - <a href="MRAA.html">MRAA</a> support added ( Galileo, Edison, etc)
  1256. * - <a href="Linux.html">Generic Linux support (SPIDEV)</a> support
  1257. * - Support for RPi 2 added
  1258. * - Major Documentation cleanup & update (Move all docs to github.io)
  1259. *
  1260. *
  1261. * If issues are discovered with the documentation, please report them <a href="https://github.com/TMRh20/tmrh20.github.io/issues"> here</a>
  1262. *
  1263. * <br>
  1264. * @section Useful Useful References
  1265. *
  1266. *
  1267. * @li <a href="http://tmrh20.github.io/RF24/classRF24.html"><b>RF24</b> Class Documentation</a>
  1268. * @li <a href="https://github.com/TMRh20/RF24/archive/master.zip"><b>Download</b></a>
  1269. * @li <a href="https://github.com/tmrh20/RF24/"><b>Source Code</b></a>
  1270. * @li <a href="http://tmrh20.blogspot.com/2014/03/high-speed-data-transfers-and-wireless.html"><b>My Blog:</b> RF24 Optimization Overview</a>
  1271. * @li <a href="http://tmrh20.blogspot.com/2016/08/raspberry-pilinux-with-nrf24l01.html"><b>My Blog:</b> RPi/Linux w/RF24Gateway</a>
  1272. * @li <a href="http://www.nordicsemi.com/files/Product/data_sheet/nRF24L01_Product_Specification_v2_0.pdf">Chip Datasheet</a>
  1273. *
  1274. * **Additional Information and Add-ons**
  1275. *
  1276. * @li <a href="http://tmrh20.github.io/RF24Network"> <b>RF24Network:</b> OSI Network Layer for multi-device communication. Create a home sensor network.</a>
  1277. * @li <a href="http://tmrh20.github.io/RF24Mesh"> <b>RF24Mesh:</b> Dynamic Mesh Layer for RF24Network</a>
  1278. * @li <a href="http://tmrh20.github.io/RF24Ethernet"> <b>RF24Ethernet:</b> TCP/IP Radio Mesh Networking (shares Arduino Ethernet API)</a>
  1279. * @li <a href="http://tmrh20.github.io/RF24Audio"> <b>RF24Audio:</b> Realtime Wireless Audio streaming</a>
  1280. * @li <a href="http://tmrh20.github.io/">All TMRh20 Documentation Main Page</a>
  1281. *
  1282. * **More Information and RF24 Based Projects**
  1283. *
  1284. * @li <a href="http://TMRh20.blogspot.com"> Project Blog: TMRh20.blogspot.com </a>
  1285. * @li <a href="http://maniacalbits.blogspot.ca/"> Maniacal Bits Blog</a>
  1286. * @li <a href="http://www.mysensors.org/">MySensors.org (User friendly sensor networks/IoT)</a>
  1287. * @li <a href="https://github.com/mannkind/RF24Node_MsgProto"> RF24Node_MsgProto (MQTT)</a>
  1288. * @li <a href="https://bitbucket.org/pjhardy/rf24sensornet/"> RF24SensorNet </a>
  1289. * @li <a href="http://www.homeautomationforgeeks.com/rf24software.shtml">Home Automation for Geeks</a>
  1290. * @li <a href="https://maniacbug.wordpress.com/2012/03/30/rf24network/"> Original Maniacbug RF24Network Blog Post</a>
  1291. * @li <a href="https://github.com/maniacbug/RF24"> ManiacBug on GitHub (Original Library Author)</a>
  1292. *
  1293. *
  1294. * <br>
  1295. *
  1296. * @section Platform_Support Platform Support Pages
  1297. *
  1298. * @li <a href="Arduino.html"><b>Arduino</b></a> (Uno, Nano, Mega, Due, Galileo, etc)
  1299. * @li <a href="ATTiny.html"><b>ATTiny</b></a>
  1300. * @li <a href="Linux.html"><b>Linux devices</b></a>( <a href="RPi.html"><b>RPi</b></a> , <a href="Linux.html"><b>Linux SPI userspace device</b></a>, <a href="MRAA.html"><b>MRAA</b></a> supported boards ( Galileo, Edison, etc), <a href="LittleWire.html"><b>LittleWire</b></a>)
  1301. * @li <a href="CrossCompile.html"><b>Cross-compilation</b></a> for linux devices
  1302. * @li <a href="Python.html"><b>Python</b></a> wrapper available for Linux devices
  1303. *
  1304. * <br>
  1305. * **General µC Pin layout** (See the individual board support pages for more info)
  1306. *
  1307. * The table below shows how to connect the the pins of the NRF24L01(+) to different boards.
  1308. * CE and CSN are configurable.
  1309. *
  1310. * | PIN | NRF24L01 | Arduino UNO | ATtiny25/45/85 [0] | ATtiny44/84 [1] | LittleWire [2] | RPI | RPi -P1 Connector |
  1311. * |-----|----------|-------------|--------------------|-----------------|-------------------------|------------|-------------------|
  1312. * | 1 | GND | GND | pin 4 | pin 14 | GND | rpi-gnd | (25) |
  1313. * | 2 | VCC | 3.3V | pin 8 | pin 1 | regulator 3.3V required | rpi-3v3 | (17) |
  1314. * | 3 | CE | digIO 7 | pin 2 | pin 12 | pin to 3.3V | rpi-gpio22 | (15) |
  1315. * | 4 | CSN | digIO 8 | pin 3 | pin 11 | RESET | rpi-gpio8 | (24) |
  1316. * | 5 | SCK | digIO 13 | pin 7 | pin 9 | SCK | rpi-sckl | (23) |
  1317. * | 6 | MOSI | digIO 11 | pin 6 | pin 7 | MOSI | rpi-mosi | (19) |
  1318. * | 7 | MISO | digIO 12 | pin 5 | pin 8 | MISO | rpi-miso | (21) |
  1319. * | 8 | IRQ | - | - | - | - | - | - |
  1320. *
  1321. * @li [0] https://learn.sparkfun.com/tutorials/tiny-avr-programmer-hookup-guide/attiny85-use-hints
  1322. * @li [1] http://highlowtech.org/?p=1695
  1323. * @li [2] http://littlewire.cc/
  1324. * <br><br><br>
  1325. *
  1326. *
  1327. *
  1328. *
  1329. * @page Arduino Arduino
  1330. *
  1331. * RF24 is fully compatible with Arduino boards <br>
  1332. * See <b> http://www.arduino.cc/en/Reference/Board </b> and <b> http://arduino.cc/en/Reference/SPI </b> for more information
  1333. *
  1334. * RF24 makes use of the standard hardware SPI pins (MISO,MOSI,SCK) and requires two additional pins, to control
  1335. * the chip-select and chip-enable functions.<br>
  1336. * These pins must be chosen and designated by the user, in RF24 radio(ce_pin,cs_pin); and can use any
  1337. * available pins.
  1338. *
  1339. * <br>
  1340. * @section ARD_DUE Arduino Due
  1341. *
  1342. * RF24 makes use of the extended SPI functionality available on the Arduino Due, and requires one of the
  1343. * defined hardware SS/CS pins to be designated in RF24 radio(ce_pin,cs_pin);<br>
  1344. * See http://arduino.cc/en/Reference/DueExtendedSPI for more information
  1345. *
  1346. * Initial Due support taken from https://github.com/mcrosson/RF24/tree/due
  1347. *
  1348. * <br>
  1349. * @section Alternate_SPI Alternate SPI Support
  1350. *
  1351. * RF24 supports alternate SPI methods, in case the standard hardware SPI pins are otherwise unavailable.
  1352. *
  1353. * <br>
  1354. * **Software Driven SPI**
  1355. *
  1356. * Software driven SPI is provided by the <a href=https://github.com/greiman/DigitalIO>DigitalIO</a> library
  1357. *
  1358. * Setup:<br>
  1359. * 1. Install the digitalIO library<br>
  1360. * 2. Open RF24_config.h in a text editor.
  1361. Uncomment the line
  1362. @code
  1363. #define SOFTSPI
  1364. @endcode
  1365. or add the build flag/option
  1366. @code
  1367. -DSOFTSPI
  1368. @endcode
  1369. * 3. In your sketch, add
  1370. * @code
  1371. * #include DigitalIO.h
  1372. * @endcode
  1373. *
  1374. * @note Note: Pins are listed as follows and can be modified by editing the RF24_config.h file<br>
  1375. *
  1376. * #define SOFT_SPI_MISO_PIN 16
  1377. * #define SOFT_SPI_MOSI_PIN 15
  1378. * #define SOFT_SPI_SCK_PIN 14
  1379. * Or add the build flag/option
  1380. *
  1381. * -DSOFT_SPI_MISO_PIN=16 -DSOFT_SPI_MOSI_PIN=15 -DSOFT_SPI_SCK_PIN=14
  1382. *
  1383. * <br>
  1384. * **Alternate Hardware (UART) Driven SPI**
  1385. *
  1386. * The Serial Port (UART) on Arduino can also function in SPI mode, and can double-buffer data, while the
  1387. * default SPI hardware cannot.
  1388. *
  1389. * The SPI_UART library is available at https://github.com/TMRh20/Sketches/tree/master/SPI_UART
  1390. *
  1391. * Enabling:
  1392. * 1. Install the SPI_UART library
  1393. * 2. Edit RF24_config.h and uncomment #define SPI_UART
  1394. * 3. In your sketch, add @code #include <SPI_UART.h> @endcode
  1395. *
  1396. * SPI_UART SPI Pin Connections:
  1397. * | NRF |Arduino Uno Pin|
  1398. * |-----|---------------|
  1399. * | MOSI| TX(0) |
  1400. * | MISO| RX(1) |
  1401. * | SCK | XCK(4) |
  1402. * | CE | User Specified|
  1403. * | CSN | User Specified|
  1404. *
  1405. *
  1406. * @note SPI_UART on Mega boards requires soldering to an unused pin on the chip. <br>See
  1407. * https://github.com/TMRh20/RF24/issues/24 for more information on SPI_UART.
  1408. *
  1409. * @page ATTiny ATTiny
  1410. *
  1411. * ATTiny support is built into the library, so users are not required to include SPI.h in their sketches<br>
  1412. * See the included rf24ping85 example for pin info and usage
  1413. *
  1414. * Some versions of Arduino IDE may require a patch to allow use of the full program space on ATTiny<br>
  1415. * See https://github.com/TCWORLD/ATTinyCore/tree/master/PCREL%20Patch%20for%20GCC for ATTiny patch
  1416. *
  1417. * ATTiny board support initially added from https://github.com/jscrane/RF24
  1418. *
  1419. * @section Hardware Hardware Configuration
  1420. * By tong67 ( https://github.com/tong67 )
  1421. *
  1422. * **ATtiny25/45/85 Pin map with CE_PIN 3 and CSN_PIN 4**
  1423. * @code
  1424. * +-\/-+
  1425. * NC PB5 1|o |8 Vcc --- nRF24L01 VCC, pin2 --- LED --- 5V
  1426. * nRF24L01 CE, pin3 --- PB3 2| |7 PB2 --- nRF24L01 SCK, pin5
  1427. * nRF24L01 CSN, pin4 --- PB4 3| |6 PB1 --- nRF24L01 MOSI, pin6
  1428. * nRF24L01 GND, pin1 --- GND 4| |5 PB0 --- nRF24L01 MISO, pin7
  1429. * +----+
  1430. * @endcode
  1431. *
  1432. * <br>
  1433. * **ATtiny25/45/85 Pin map with CE_PIN 3 and CSN_PIN 3** => PB3 and PB4 are free to use for application <br>
  1434. * Circuit idea from http://nerdralph.blogspot.ca/2014/01/nrf24l01-control-with-3-attiny85-pins.html <br>
  1435. * Original RC combination was 1K/100nF. 22K/10nF combination worked better. <br>
  1436. * For best settletime delay value in RF24::csn() the timingSearch3pin.ino sketch can be used. <br>
  1437. * This configuration is enabled when CE_PIN and CSN_PIN are equal, e.g. both 3 <br>
  1438. * Because CE is always high the power consumption is higher than for 5 pins solution <br>
  1439. * @code
  1440. * ^^
  1441. * +-\/-+ nRF24L01 CE, pin3 ------| //
  1442. * PB5 1|o |8 Vcc --- nRF24L01 VCC, pin2 ------x----------x--|<|-- 5V
  1443. * NC PB3 2| |7 PB2 --- nRF24L01 SCK, pin5 --|<|---x-[22k]--| LED
  1444. * NC PB4 3| |6 PB1 --- nRF24L01 MOSI, pin6 1n4148 |
  1445. * nRF24L01 GND, pin1 -x- GND 4| |5 PB0 --- nRF24L01 MISO, pin7 |
  1446. * | +----+ |
  1447. * |-----------------------------------------------||----x-- nRF24L01 CSN, pin4
  1448. * 10nF
  1449. * @endcode
  1450. *
  1451. * <br>
  1452. * **ATtiny24/44/84 Pin map with CE_PIN 8 and CSN_PIN 7** <br>
  1453. * Schematic provided and successfully tested by Carmine Pastore (https://github.com/Carminepz) <br>
  1454. * @code
  1455. * +-\/-+
  1456. * nRF24L01 VCC, pin2 --- VCC 1|o |14 GND --- nRF24L01 GND, pin1
  1457. * PB0 2| |13 AREF
  1458. * PB1 3| |12 PA1
  1459. * PB3 4| |11 PA2 --- nRF24L01 CE, pin3
  1460. * PB2 5| |10 PA3 --- nRF24L01 CSN, pin4
  1461. * PA7 6| |9 PA4 --- nRF24L01 SCK, pin5
  1462. * nRF24L01 MISO, pin7 --- PA6 7| |8 PA5 --- nRF24L01 MOSI, pin6
  1463. * +----+
  1464. * @endcode
  1465. *
  1466. * <br>
  1467. * **ATtiny2313/4313 Pin map with CE_PIN 12 and CSN_PIN 13** <br>
  1468. * @code
  1469. * +-\/-+
  1470. * PA2 1|o |20 VCC --- nRF24L01 VCC, pin2
  1471. * PD0 2| |19 PB7 --- nRF24L01 SCK, pin5
  1472. * PD1 3| |18 PB6 --- nRF24L01 MOSI, pin6
  1473. * PA1 4| |17 PB5 --- nRF24L01 MISO, pin7
  1474. * PA0 5| |16 PB4 --- nRF24L01 CSN, pin4
  1475. * PD2 6| |15 PB3 --- nRF24L01 CE, pin3
  1476. * PD3 7| |14 PB2
  1477. * PD4 8| |13 PB1
  1478. * PD5 9| |12 PB0
  1479. * nRF24L01 GND, pin1 --- GND 10| |11 PD6
  1480. * +----+
  1481. * @endcode
  1482. *
  1483. * <br><br><br>
  1484. *
  1485. *
  1486. *
  1487. *
  1488. *
  1489. *
  1490. * @page Linux Linux devices
  1491. *
  1492. * Generic Linux devices are supported via SPIDEV, MRAA, RPi native via BCM2835, or using LittleWire.
  1493. *
  1494. * @note The SPIDEV option should work with most Linux systems supporting spi userspace device. <br>
  1495. *
  1496. * <br>
  1497. * @section AutoInstall Automated Install
  1498. *(**Designed & Tested on RPi** - Defaults to SPIDEV on devices supporting it)
  1499. *
  1500. *
  1501. * 1. Install prerequisites if there are any (MRAA, LittleWire libraries, setup SPI device etc)
  1502. * 2. Download the install.sh file from http://tmrh20.github.io/RF24Installer/RPi/install.sh
  1503. * @code wget http://tmrh20.github.io/RF24Installer/RPi/install.sh @endcode
  1504. * 3. Make it executable
  1505. * @code chmod +x install.sh @endcode
  1506. * 4. Run it and choose your options
  1507. * @code ./install.sh @endcode
  1508. * 5. Run an example from one of the libraries
  1509. * @code
  1510. * cd rf24libs/RF24/examples_linux
  1511. * @endcode
  1512. * Edit the gettingstarted example, to set your pin configuration
  1513. * @code nano gettingstarted.cpp
  1514. * make
  1515. * sudo ./gettingstarted
  1516. * @endcode
  1517. *
  1518. * <br>
  1519. * @section ManInstall Manual Install
  1520. * 1. Install prerequisites if there are any (MRAA, LittleWire libraries, setup SPI device etc)
  1521. * @note See the <a href="http://iotdk.intel.com/docs/master/mraa/index.html">MRAA </a> documentation for more info on installing MRAA <br>
  1522. * 2. Make a directory to contain the RF24 and possibly RF24Network lib and enter it
  1523. * @code
  1524. * mkdir ~/rf24libs
  1525. * cd ~/rf24libs
  1526. * @endcode
  1527. * 3. Clone the RF24 repo
  1528. * @code git clone https://github.com/tmrh20/RF24.git RF24 @endcode
  1529. * 4. Change to the new RF24 directory
  1530. * @code cd RF24 @endcode
  1531. * 5. Configure build environment using @code ./configure @endcode script. It auto detectes device and build environment. For overriding autodetections, use command-line switches, see @code ./configure --help @endcode for description.
  1532. * 6. Build the library, and run an example file
  1533. * @code sudo make install @endcode
  1534. * @code
  1535. * cd examples_linux
  1536. * @endcode
  1537. * Edit the gettingstarted example, to set your pin configuration
  1538. * @code nano gettingstarted.cpp
  1539. * make
  1540. * sudo ./gettingstarted
  1541. * @endcode
  1542. *
  1543. * <br><br>
  1544. *
  1545. * @page MRAA MRAA
  1546. *
  1547. * MRAA is a Low Level Skeleton Library for Communication on GNU/Linux platforms <br>
  1548. * See http://iotdk.intel.com/docs/master/mraa/index.html for more information
  1549. *
  1550. * RF24 supports all MRAA supported platforms, but might not be tested on each individual platform due to the wide range of hardware support:<br>
  1551. * <a href="https://github.com/TMRh20/RF24/issues">Report an RF24 bug or issue </a>
  1552. *
  1553. * @section Setup Setup and installation
  1554. * 1. Install the MRAA lib
  1555. * 2. As per your device, SPI may need to be enabled
  1556. * 3. Follow <a href="Linux.html">Linux installation steps</a> to install RF24 libraries
  1557. *
  1558. *
  1559. * <br><br><br>
  1560. *
  1561. *
  1562. *
  1563. *
  1564. * @page RPi Raspberry Pi
  1565. *
  1566. * RF24 supports a variety of Linux based devices via various drivers. Some boards like RPi can utilize multiple methods
  1567. * to drive the GPIO and SPI functionality.
  1568. *
  1569. * <br>
  1570. * @section PreConfig Potential PreConfiguration
  1571. *
  1572. * If SPI is not already enabled, load it on boot:
  1573. * @code sudo raspi-config @endcode
  1574. * A. Update the tool via the menu as required<br>
  1575. * B. Select **Advanced** and **enable the SPI kernel module** <br>
  1576. * C. Update other software and libraries
  1577. * @code sudo apt-get update @endcode
  1578. * @code sudo apt-get upgrade @endcode
  1579. * <br><br>
  1580. *
  1581. * @section Build Build Options
  1582. * The default build on Raspberry Pi utilizes the included **BCM2835** driver from http://www.airspayce.com/mikem/bcm2835
  1583. * 1. @code sudo make install -B @endcode
  1584. *
  1585. * Build using the **MRAA** library from http://iotdk.intel.com/docs/master/mraa/index.html <br>
  1586. * MRAA is not included. See the <a href="MRAA.html">MRAA</a> platform page for more information.
  1587. *
  1588. * 1. Install, and build MRAA
  1589. * @code
  1590. * git clone https://github.com/intel-iot-devkit/mraa.git
  1591. * cd mraa
  1592. * mkdir build
  1593. * cd build
  1594. * cmake .. -DBUILDSWIGNODE=OFF
  1595. * sudo make install
  1596. * @endcode
  1597. *
  1598. * 2. Complete the install <br>
  1599. * @code nano /etc/ld.so.conf @endcode
  1600. * Add the line @code /usr/local/lib/arm-linux-gnueabihf @endcode
  1601. * Run @code sudo ldconfig @endcode
  1602. *
  1603. * 3. Install RF24, using MRAA
  1604. * @code
  1605. * ./configure --driver=MRAA
  1606. * sudo make install -B
  1607. * @endcode
  1608. * See the gettingstarted example for an example of pin configuration
  1609. *
  1610. * Build using **SPIDEV**
  1611. *
  1612. * 1. Make sure that spi device support is enabled and /dev/spidev\<a\>.\<b\> is present
  1613. * 2. Install RF24, using SPIDEV
  1614. * @code
  1615. * ./configure --driver=SPIDEV
  1616. * sudo make install -B
  1617. * @endcode
  1618. * 3. See the gettingstarted example for an example of pin configuration
  1619. *
  1620. * <br>
  1621. * @section Pins Connections and Pin Configuration
  1622. *
  1623. *
  1624. * Using pin 15/GPIO 22 for CE, pin 24/GPIO8 (CE0) for CSN
  1625. *
  1626. * Can use either RPi CE0 or CE1 pins for radio CSN.<br>
  1627. * Choose any RPi output pin for radio CE pin.
  1628. *
  1629. * **BCM2835 Constructor:**
  1630. * @code
  1631. * RF24 radio(RPI_V2_GPIO_P1_15,BCM2835_SPI_CS0, BCM2835_SPI_SPEED_8MHZ);
  1632. * or
  1633. * RF24 radio(RPI_V2_GPIO_P1_15,BCM2835_SPI_CS1, BCM2835_SPI_SPEED_8MHZ);
  1634. *
  1635. * RPi B+:
  1636. * RF24 radio(RPI_BPLUS_GPIO_J8_15,RPI_BPLUS_GPIO_J8_24, BCM2835_SPI_SPEED_8MHZ);
  1637. * or
  1638. * RF24 radio(RPI_BPLUS_GPIO_J8_15,RPI_BPLUS_GPIO_J8_26, BCM2835_SPI_SPEED_8MHZ);
  1639. *
  1640. * General:
  1641. * RF24 radio(22,0);
  1642. * or
  1643. * RF24 radio(22,1);
  1644. *
  1645. * @endcode
  1646. * See the gettingstarted example for an example of pin configuration
  1647. *
  1648. * See http://www.airspayce.com/mikem/bcm2835/index.html for BCM2835 class documentation.
  1649. * <br><br>
  1650. * **MRAA Constructor:**
  1651. *
  1652. * @code RF24 radio(15,0); @endcode
  1653. *
  1654. * See http://iotdk.intel.com/docs/master/mraa/rasppi.html
  1655. * <br><br>
  1656. * **SPI_DEV Constructor**
  1657. *
  1658. * @code RF24 radio(22,0); @endcode
  1659. * In general, use @code RF24 radio(<ce_pin>, <a>*10+<b>); @endcode for proper SPIDEV constructor to address correct spi device at /dev/spidev\<a\>.\<b\>
  1660. *
  1661. * See http://pi.gadgetoid.com/pinout
  1662. *
  1663. * **Pins:**
  1664. *
  1665. * | PIN | NRF24L01 | RPI | RPi -P1 Connector |
  1666. * |-----|----------|------------|-------------------|
  1667. * | 1 | GND | rpi-gnd | (25) |
  1668. * | 2 | VCC | rpi-3v3 | (17) |
  1669. * | 3 | CE | rpi-gpio22 | (15) |
  1670. * | 4 | CSN | rpi-gpio8 | (24) |
  1671. * | 5 | SCK | rpi-sckl | (23) |
  1672. * | 6 | MOSI | rpi-mosi | (19) |
  1673. * | 7 | MISO | rpi-miso | (21) |
  1674. * | 8 | IRQ | - | - |
  1675. *
  1676. *
  1677. *
  1678. *
  1679. * <br><br>
  1680. ****************
  1681. *
  1682. * Based on the arduino lib from J. Coliz <maniacbug@ymail.com> <br>
  1683. * the library was berryfied by Purinda Gunasekara <purinda@gmail.com> <br>
  1684. * then forked from github stanleyseow/RF24 to https://github.com/jscrane/RF24-rpi <br>
  1685. * Network lib also based on https://github.com/farconada/RF24Network
  1686. *
  1687. *
  1688. *
  1689. *
  1690. * <br><br><br>
  1691. *
  1692. *
  1693. *
  1694. * @page Python Python Wrapper (by https://github.com/mz-fuzzy)
  1695. *
  1696. * @note Both python2 and python3 are supported.
  1697. *
  1698. * @section Install Installation:
  1699. *
  1700. * 1. Install the python-dev (or python3-dev) and boost libraries
  1701. * @code sudo apt-get install python-dev libboost-python-dev @endcode
  1702. * @note For python3 in Raspbian, it's needed to manually link python boost library, like this:
  1703. * @code sudo ln -s /usr/lib/arm-linux-gnueabihf/libboost_python-py34.so /usr/lib/arm-linux-gnueabihf/libboost_python3.so @endcode
  1704. *
  1705. * 2. Install python-setuptools (or python3-setuptools)
  1706. * @code sudo apt-get install python-setuptools @endcode
  1707. *
  1708. * 3. Build the library
  1709. * @code ./setup.py build @endcode
  1710. * @note Build takes several minutes on arm-based machines. Machines with RAM <1GB may need to increase amount of swap for build.
  1711. *
  1712. * 4. Install the library
  1713. * @code sudo ./setup.py install @endcode
  1714. * See the additional <a href="pages.html">Platform Support</a> pages for information on connecting your hardware <br>
  1715. * See the included <a href="pingpair_dyn_8py-example.html">example </a> for usage information.
  1716. *
  1717. * 5. Running the Example
  1718. * Edit the pingpair_dyn.py example to configure the appropriate pins per the above documentation:
  1719. * @code nano pingpair_dyn.py @endcode
  1720. * Configure another device, Arduino or RPi with the <a href="pingpair_dyn_8py-example.html">pingpair_dyn</a> example <br>
  1721. * Run the example
  1722. * @code sudo ./pingpair_dyn.py @endcode
  1723. *
  1724. * <br><br><br>
  1725. *
  1726. * @page CrossCompile Linux cross-compilation
  1727. *
  1728. * RF24 library supports cross-compilation. Advantages of cross-compilation:
  1729. * - development tools don't have to be installed on target machine
  1730. * - resources of target machine don't have to be sufficient for compilation
  1731. * - compilation time can be reduced for large projects
  1732. *
  1733. * Following prerequisites need to be assured:
  1734. * - ssh passwordless access to target machine (https://linuxconfig.org/passwordless-ssh)
  1735. * - sudo of a remote user without password (http://askubuntu.com/questions/334318/sudoers-file-enable-nopasswd-for-user-all-commands)
  1736. * - cross-compilation toolchain for your target machine; for RPi
  1737. * @code git clone https://github.com/raspberrypi/tools rpi_tools @endcode
  1738. * and cross-compilation tools must be in PATH, for example
  1739. * @code export PATH=$PATH:/your/dir/rpi-tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin @endcode
  1740. *
  1741. * @section CxSteps Cross compilation steps:
  1742. * 1. clone RF24 to a machine for cross-compilation
  1743. * @code
  1744. * git clone https://github.com/TMRh20/RF24
  1745. * cd RF24
  1746. * @endcode
  1747. * 2. configure for cross compilation
  1748. * @code ./configure --remote=pi@target_linux_host @endcode
  1749. * eventually
  1750. * @code ./configure --remote=pi@target_linux_host --driver=<driver> @endcode
  1751. * 3. build
  1752. * @code make @endcode
  1753. * 4. (opt) install library to cross-compilation machine into cross-exvironment - important for compilation of examples
  1754. * @code sudo make install @endcode
  1755. * 5. upload library to target machine
  1756. * @code make upload @endcode
  1757. * 6. (opt) compile examples
  1758. * @code
  1759. * cd examples_linux
  1760. * make
  1761. * @endcode
  1762. * 7. (opt) upload examples to target machine
  1763. * @code make upload @endcode
  1764. *
  1765. * @section CxStepsPython Cross comilation steps for python wrapper
  1766. *
  1767. * Prerequisites:
  1768. * - Python setuptools must be installed on both target and cross-compilation machines
  1769. * @code sudo pip install setuptools @endcode
  1770. * or
  1771. * @code sudo apt-get install python-setuptools @endcode
  1772. *
  1773. * Installation steps:
  1774. * 1. Assure having libboost-python-dev library in your cross-compilation environment. Alternatively, you can install it into your target machine and copy /usr and /lib directories to the cross-compilation machine.
  1775. * For example
  1776. * @code
  1777. * mkdir -p rpi_root && rsync -a pi@target_linux_host:/usr :/lib rpi_root
  1778. * export CFLAGS="--sysroot=/your/dir/rpi_root -I/your/dir/rpi_root/usr/include/python2.7/"
  1779. * @endcode
  1780. *
  1781. * 2. Build the python wrapper
  1782. * @code
  1783. * cd pyRF24
  1784. * ./setup.py build --compiler=crossunix
  1785. * @endcode
  1786. *
  1787. * 3. Make the egg package
  1788. * @code ./setup.py bdist_egg --plat-name=cross @endcode
  1789. * dist/RF24-<version>-cross.egg should be created.
  1790. *
  1791. * 4. Upload it to the target machine and install there:
  1792. * @code
  1793. * scp dist/RF24-*-cross.egg pi@target_linux_host:
  1794. * ssh pi@target_linux_host 'sudo easy_install RF24-*-cross.egg'
  1795. * @endcode
  1796. *
  1797. * <br><br><br>
  1798. *
  1799. * @page ATXMEGA ATXMEGA
  1800. *
  1801. * The RF24 driver can be build as a static library with Atmel Studio 7 in order to be included as any other library in another program for the XMEGA family.
  1802. *
  1803. * Currently only the <b>ATXMEGA D3</b> family is implemented.
  1804. *
  1805. * @section Preparation
  1806. *
  1807. * Create an empty GCC Static Library project in AS7.<br>
  1808. * As not all files are required, copy the following directory structure in the project:
  1809. *
  1810. * @code
  1811. * utility\
  1812. * ATXMegaD3\
  1813. * compatibility.c
  1814. * compatibility.h
  1815. * gpio.cpp
  1816. * gpio.h
  1817. * gpio_helper.c
  1818. * gpio_helper.h
  1819. * includes.h
  1820. * RF24_arch_config.h
  1821. * spi.cpp
  1822. * spi.h
  1823. * nRF24L01.h
  1824. * printf.h
  1825. * RF24.cpp
  1826. * RF24.h
  1827. * RF24_config.h
  1828. * @endcode
  1829. *
  1830. * @section Usage
  1831. *
  1832. * Add the library to your project!<br>
  1833. * In the file where the **main()** is put the following in order to update the millisecond functionality:
  1834. *
  1835. * @code
  1836. * ISR(TCE0_OVF_vect)
  1837. * {
  1838. * update_milisec();
  1839. * }
  1840. * @endcode
  1841. *
  1842. * Declare the rf24 radio with **RF24 radio(XMEGA_PORTC_PIN3, XMEGA_SPI_PORT_C);**
  1843. *
  1844. * First parameter is the CE pin which can be any available pin on the uC.
  1845. *
  1846. * Second parameter is the CS which can be on port C (**XMEGA_SPI_PORT_C**) or on port D (**XMEGA_SPI_PORT_D**).
  1847. *
  1848. * Call the **__start_timer()** to start the millisecond timer.
  1849. *
  1850. * @note Note about the millisecond functionality:<br>
  1851. *
  1852. * The millisecond functionality is based on the TCE0 so don't use these pins as IO.<br>
  1853. * The operating frequency of the uC is 32MHz. If you have other frequency change the TCE0 registers appropriatly in function **__start_timer()** in **compatibility.c** file for your frequency.
  1854. *
  1855. * @page Portability RF24 Portability
  1856. *
  1857. * The RF24 radio driver mainly utilizes the <a href="http://arduino.cc/en/reference/homePage">Arduino API</a> for GPIO, SPI, and timing functions, which are easily replicated
  1858. * on various platforms. <br>Support files for these platforms are stored under RF24/utility, and can be modified to provide
  1859. * the required functionality.
  1860. *
  1861. * <br>
  1862. * @section Hardware_Templates Basic Hardware Template
  1863. *
  1864. * **RF24/utility**
  1865. *
  1866. * The RF24 library now includes a basic hardware template to assist in porting to various platforms. <br> The following files can be included
  1867. * to replicate standard Arduino functions as needed, allowing devices from ATTiny to Raspberry Pi to utilize the same core RF24 driver.
  1868. *
  1869. * | File | Purpose |
  1870. * |--------------------|------------------------------------------------------------------------------|
  1871. * | RF24_arch_config.h | Basic Arduino/AVR compatibility, includes for remaining support files, etc |
  1872. * | includes.h | Linux only. Defines specific platform, include correct RF24_arch_config file |
  1873. * | spi.h | Provides standardized SPI ( transfer() ) methods |
  1874. * | gpio.h | Provides standardized GPIO ( digitalWrite() ) methods |
  1875. * | compatibility.h | Provides standardized timing (millis(), delay()) methods |
  1876. * | your_custom_file.h | Provides access to custom drivers for spi,gpio, etc |
  1877. *
  1878. * <br>
  1879. * Examples are provided via the included hardware support templates in **RF24/utility** <br>
  1880. * See the <a href="modules.html">modules</a> page for examples of class declarations
  1881. *
  1882. *<br>
  1883. * @section Device_Detection Device Detection
  1884. *
  1885. * 1. The main detection for Linux devices is done in the configure script, with the includes.h from the proper hardware directory copied to RF24/utility/includes.h <br>
  1886. * 2. Secondary detection is completed in RF24_config.h, causing the include.h file to be included for all supported Linux devices <br>
  1887. * 3. RF24.h contains the declaration for SPI and GPIO objects 'spi' and 'gpio' to be used for porting-in related functions.
  1888. *
  1889. * <br>
  1890. * @section Ported_Code Code
  1891. * To have your ported code included in this library, or for assistance in porting, create a pull request or open an issue at https://github.com/TMRh20/RF24
  1892. *
  1893. *
  1894. *<br><br><br>
  1895. */
  1896. #endif // __RF24_H__