Advertisement
maniacbug

Untitled

Feb 29th, 2012
645
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. In global part of main “.ino” file:
  2.  
  3. #include
  4. #include
  5. #include “nRF24L01.h”
  6. #include “printf.h”
  7.  
  8. // Setup Radio parameters / data storage
  9. RF24 radio(8,7); //CE, CSN
  10. uint8_t frame[27];
  11. uint8_t packetType = 0;
  12. uint32_t uid = 0;
  13.  
  14. In Setup:
  15.  
  16. radio.begin();
  17. radio.setChannel(25);
  18. radio.setPayloadSize(27);
  19. radio.setAutoAck(false);
  20. radio.setDataRate(RF24_250KBPS);
  21. radio.setCRCLength(RF24_CRC_DISABLED); // was 8
  22. radio.openReadingPipe(1,0xC2BD0DLL);
  23. radio.startListening();
  24. radio.printDetails();
  25.  
  26. In Loop:
  27.  
  28. if ( radio.available() )
  29. {
  30. // Get the packet from the radio
  31. radio.read( &frame, sizeof(frame) );
  32. parseFrame();
  33.  
  34. if (1)
  35. {
  36. printf(“PacketType: %X, UID: %08lX\n”, packetType, uid);
  37. printf(“\r\n”);
  38. }
  39. }
  40.  
  41. Functions to add after Loop:
  42.  
  43. void parseFrame(void)
  44. {
  45. uid = frame[1];
  46. uid <<= 8;
  47. uid |= frame[2];
  48. uid <<= 8;
  49. uid |= frame[3];
  50. uid <<= 8;
  51. uid |= frame[4];
  52.  
  53. packetType = frame[0];
  54. }
  55.  
  56. void printFrame(void)
  57. {
  58. int i;
  59. printf("Frame: ");
  60. for(i = 0 ; i < 27 ; i++)
  61. {
  62. printf(" ");
  63. printf("%02X", frame[i]); // prints value as string in hexadecimal
  64. }
  65. printf("\r\n");
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement