Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. /*
  2. Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
  3.  
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. version 2 as published by the Free Software Foundation.
  7. */
  8.  
  9. /**
  10. * Example for Getting Started with nRF24L01+ radios.
  11. *
  12. * This is an example of how to use the RF24 class. Write this sketch to two
  13. * different nodes. Put one of the nodes into 'transmit' mode by connecting
  14. * with the serial monitor and sending a 'T'. The ping node sends the current
  15. * time to the pong node, which responds by sending the value back. The ping
  16. * node can then see how long the whole cycle took.
  17. */
  18.  
  19. #include <SPI.h>
  20. #include "nRF24L01.h"
  21. #include "RF24.h"
  22. #include "printf.h"
  23.  
  24. //
  25. // Hardware configuration
  26. //
  27.  
  28. // Set up nRF24L01 radio on SPI bus plus pins 9 & 10
  29.  
  30. RF24 radio(9,10);
  31.  
  32. //
  33. // Topology
  34. //
  35.  
  36. // Radio pipe address
  37. const uint64_t pipe = 0xF0F0F0F0D2LL;
  38.  
  39. //Settings
  40. char message[] = "DATA OVERGEBRACHT";
  41. int ART_delay = 15;
  42. int ART_frequency = 15;
  43. int channel = 46;
  44.  
  45. void setup(void)
  46. {
  47.  
  48. Serial.begin(57600);
  49. printf_begin();
  50.  
  51. //
  52. // Setup and configure rf radio
  53. //
  54.  
  55. radio.begin();
  56.  
  57. // optionally, increase the delay between retries & # of retries
  58. radio.setRetries(15,15);
  59.  
  60. //
  61. // Open pipe to other nodes for communication
  62. //
  63.  
  64. radio.openReadingPipe(1,pipe);
  65.  
  66. radio.startListening();
  67. radio.printDetails();
  68.  
  69. //Settings
  70. radio.setChannel(channel);
  71. radio.setPALevel(RF24_PA_MIN);//set output power level RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX
  72. radio.setDataRate(RF24_1MBPS);//set data rate RF24_1MBPS, RF24_2MBPS, RF24_250KBPS
  73. radio.setRetries(ART_delay, ART_frequency); //ART settings
  74. }
  75.  
  76. void loop(void)
  77. {
  78. printf("voor Ontvangen");
  79. // if there is data ready
  80. printf("Voor ontvangen.");
  81. if ( radio.available() )
  82. {
  83. printf("Ontvangen");
  84. // Dump the payloads until we've gotten everything
  85. unsigned char got_message[17];
  86. bool done = false;
  87. while (!done)
  88. {
  89. // Fetch the payload, and see if this was the last one.
  90. done = radio.read( &got_message, sizeof(unsigned char) );
  91.  
  92. // Spew it
  93. printf("Got payload %S...",got_message);
  94.  
  95. // Delay just a little bit to let the other unit
  96. // make the transition to receiver
  97. delay(20);
  98. }
  99.  
  100. if(strcmp(got_message, message) == 0){
  101. Serial.print("string are equal.");
  102. }else{
  103. Serial.print("string are not equal.");
  104. }
  105.  
  106. // // First, stop listening so we can talk
  107. // radio.stopListening();
  108. //
  109. // // Send the final one back.
  110. // radio.write( &got_time, sizeof(unsigned long) );
  111. // printf("Sent response.\n\r");
  112. //
  113. // // Now, resume listening so we catch the next packets.
  114. // radio.startListening();
  115. }
  116.  
  117. }
  118.  
  119. // vim:cin:ai:sts=2 sw=2 ft=cpp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement