PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

3 лет назад
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // nrf24_client.pde
  2. // -*- mode: C++ -*-
  3. // Example sketch showing how to create a simple messageing client
  4. // with the RH_NRF24 class. RH_NRF24 class does not provide for addressing or
  5. // reliability, so you should only use RH_NRF24 if you do not need the higher
  6. // level messaging abilities.
  7. // It is designed to work with the other example nrf24_server.
  8. // Tested on Uno with Sparkfun NRF25L01 module
  9. // Tested on Anarduino Mini (http://www.anarduino.com/mini/) with RFM73 module
  10. // Tested on Arduino Mega with Sparkfun WRL-00691 NRF25L01 module
  11. #include <SPI.h>
  12. #include <RH_NRF24.h>
  13. // Singleton instance of the radio driver
  14. RH_NRF24 nrf24;
  15. // RH_NRF24 nrf24(8, 7); // use this to be electrically compatible with Mirf
  16. // RH_NRF24 nrf24(8, 10);// For Leonardo, need explicit SS pin
  17. // RH_NRF24 nrf24(8, 7); // For RFM73 on Anarduino Mini
  18. void setup()
  19. {
  20. Serial.begin(9600);
  21. while (!Serial)
  22. ; // wait for serial port to connect. Needed for Leonardo only
  23. if (!nrf24.init())
  24. Serial.println("init failed");
  25. // Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm
  26. if (!nrf24.setChannel(1))
  27. Serial.println("setChannel failed");
  28. if (!nrf24.setRF(RH_NRF24::DataRate2Mbps, RH_NRF24::TransmitPower0dBm))
  29. Serial.println("setRF failed");
  30. }
  31. void loop()
  32. {
  33. Serial.println("Sending to nrf24_server");
  34. // Send a message to nrf24_server
  35. uint8_t data[] = "Hello World!";
  36. nrf24.send(data, sizeof(data));
  37. nrf24.waitPacketSent();
  38. // Now wait for a reply
  39. uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];
  40. uint8_t len = sizeof(buf);
  41. if (nrf24.waitAvailableTimeout(500))
  42. {
  43. // Should be a reply message for us now
  44. if (nrf24.recv(buf, &len))
  45. {
  46. Serial.print("got reply: ");
  47. Serial.println((char*)buf);
  48. }
  49. else
  50. {
  51. Serial.println("recv failed");
  52. }
  53. }
  54. else
  55. {
  56. Serial.println("No reply, is nrf24_server running?");
  57. }
  58. delay(400);
  59. }