PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.5KB

  1. // nrf905_client.pde
  2. // -*- mode: C++ -*-
  3. // Example sketch showing how to create a simple messageing client
  4. // with the RH_NRF905 class. RH_NRF905 class does not provide for addressing or
  5. // reliability, so you should only use RH_NRF905 if you do not need the higher
  6. // level messaging abilities.
  7. // It is designed to work with the other example nrf905_server.
  8. // Tested on Teensy3.1 with nRF905 module
  9. // Tested on Arduino Due with nRF905 module (Caution: use the SPI headers for connecting)
  10. #include <SPI.h>
  11. #include <RH_NRF905.h>
  12. // Singleton instance of the radio driver
  13. RH_NRF905 nrf905;
  14. void setup()
  15. {
  16. Serial.begin(9600);
  17. while (!Serial)
  18. ; // wait for serial port to connect. Needed for Leonardo only
  19. if (!nrf905.init())
  20. Serial.println("init failed");
  21. // Defaults after init are 433.2 MHz (channel 108), -10dBm
  22. }
  23. void loop()
  24. {
  25. Serial.println("Sending to nrf905_server");
  26. // Send a message to nrf905_server
  27. uint8_t data[] = "Hello World!";
  28. nrf905.send(data, sizeof(data));
  29. nrf905.waitPacketSent();
  30. // Now wait for a reply
  31. uint8_t buf[RH_NRF905_MAX_MESSAGE_LEN];
  32. uint8_t len = sizeof(buf);
  33. if (nrf905.waitAvailableTimeout(500))
  34. {
  35. // Should be a reply message for us now
  36. if (nrf905.recv(buf, &len))
  37. {
  38. Serial.print("got reply: ");
  39. Serial.println((char*)buf);
  40. }
  41. else
  42. {
  43. Serial.println("recv failed");
  44. }
  45. }
  46. else
  47. {
  48. Serial.println("No reply, is nrf905_server running?");
  49. }
  50. delay(400);
  51. }