rozman50

NRF24L01 - SLAVE

Feb 18th, 2018
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1.  
  2.  
  3.  
  4.  
  5. // SimpleRx - the slave or the receiver
  6.  
  7. #include <SPI.h>
  8. #include <nRF24L01.h>
  9. #include <RF24.h>
  10.  
  11. #define CE_PIN 9
  12. #define CSN_PIN 10
  13.  
  14. const byte slaveAddress[][5]= {{'R', 'x', 'A', 'A', 'A'}, {'R', 'x', 'A', 'A', 'B'},
  15. {'R', 'x', 'A', 'A', 'C'}, {'R', 'x', 'A', 'A', 'D'}};
  16.  
  17. RF24 radio(CE_PIN, CSN_PIN);
  18.  
  19. char dataReceived[10]; // this must match dataToSend in the TX
  20. bool newData = false;
  21.  
  22. //===========
  23.  
  24. void setup() {
  25.  
  26. Serial.begin(9600);
  27.  
  28. Serial.println("SimpleRx Starting");
  29. radio.begin();
  30. radio.setDataRate(RF24_250KBPS);
  31. radio.openReadingPipe(1,slaveAddress[1]);
  32. radio.enableDynamicPayloads() ;
  33. radio.setAutoAck(false);
  34. radio.startListening();
  35. }
  36.  
  37. //=============
  38.  
  39. void loop() {
  40. getData();
  41. showData();
  42. }
  43.  
  44. //==============
  45.  
  46. void getData() {
  47. if ( radio.available() ) {
  48. radio.read( &dataReceived, sizeof(dataReceived) );
  49. newData = true;
  50. }
  51. }
  52.  
  53. void showData() {
  54. if (newData == true) {
  55. Serial.print("Data received ");
  56. Serial.println(dataReceived);
  57. newData = false;
  58. }
  59. }
Add Comment
Please, Sign In to add comment