rozman50

BARELY WORKING - node

May 14th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. #include "Arduino.h"
  2. #include <SPI.h>
  3. #include <RF24.h>
  4.  
  5. // This is just the way the RF24 library works:
  6. // Hardware configuration: Set up nRF24L01 radio on SPI bus (pins 10, 11, 12, 13) plus pins 7 & 8
  7. RF24 radio(7, 8);
  8.  
  9. byte addresses[][6] = { "1Node","2Node" };
  10.  
  11.  
  12. char poslji[] = "YOOOO";
  13. char data;
  14. // -----------------------------------------------------------------------------
  15. // SETUP SETUP SETUP SETUP SETUP SETUP SETUP SETUP SETUP
  16. // -----------------------------------------------------------------------------
  17. void setup() {
  18. Serial.begin(9600);
  19. Serial.println("THIS IS THE RECEIVER CODE - YOU NEED THE OTHER ARDUINO TO TRANSMIT");
  20.  
  21. // Initiate the radio object
  22. radio.begin();
  23.  
  24. // Set the transmit power to lowest available to prevent power supply related issues
  25. radio.setPALevel(RF24_PA_MIN);
  26.  
  27. // Set the speed of the transmission to the quickest available
  28. radio.setDataRate(RF24_2MBPS);
  29.  
  30. // Use a channel unlikely to be used by Wifi, Microwave ovens etc
  31. radio.setChannel(124);
  32.  
  33. // Open a writing and reading pipe on each radio, with opposite addresses
  34. radio.openWritingPipe(addresses[0]);
  35. radio.openReadingPipe(1, addresses[1]);
  36.  
  37. // Start the radio listening for data
  38. radio.startListening();
  39. }
  40.  
  41. // -----------------------------------------------------------------------------
  42. // We are LISTENING on this device only (although we do transmit a response)
  43. // -----------------------------------------------------------------------------
  44. void loop() {
  45.  
  46. // This is what we receive from the other device (the transmitter)
  47.  
  48. if (radio.available()) {
  49. char preberi[32];
  50. radio.read(&preberi, sizeof(preberi));
  51. Serial.println(preberi);
  52.  
  53. String dataReq(preberi);
  54. // Serial.println(dataReq);
  55.  
  56. }
  57.  
  58. radio.stopListening();
  59.  
  60. // radio.write(&poslji, sizeof(poslji));
  61. radio.write(&poslji, sizeof(poslji));
  62. //if (radio.write(&poslji, sizeof(poslji))) Serial.println("We did it!");
  63. radio.startListening();
  64.  
  65.  
  66. /*
  67. // Is there any data for us to get?
  68. if (radio.available()) {
  69.  
  70. // Go and read the data and put it into that variable
  71. //while (radio.available()) {
  72. radio.read(&data, sizeof(char));
  73. Serial.println(data);
  74. // }
  75. // if(data) Serial.println("This crap");
  76. // else {
  77. // Serial.println("Nc");
  78. // Serial.println((char)data);
  79. // }
  80. // Serial.println(data);
  81.  
  82. // No more data to get so send it back but add 1 first just for kicks
  83. // First, stop listening so we can talk
  84.  
  85. radio.stopListening();
  86. char beta = 1;
  87. radio.write(&beta, sizeof(beta));
  88.  
  89. // Now, resume listening so we catch the next packets.
  90. radio.startListening();
  91.  
  92. // Tell the user what we sent back (the random numer + 1)
  93. // Serial.print("Sent response ");
  94. // Serial.println(data);
  95. }
  96. */
  97. }
Add Comment
Please, Sign In to add comment