nrf24_specan.pde 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // nrf24_specan.pde
  2. // -*- mode: C++ -*-
  3. // Example sketch showing how to create a primitive spectrum analyser
  4. // with the NRF24 class.
  5. // The nRF24L01 received power detector is only one bit, but
  6. // this will show which channels have more than -64dBm present
  7. #include <NRF24.h>
  8. #include <SPI.h>
  9. // Singleton instance of the radio
  10. NRF24 nrf24;
  11. // NRF24 nrf24(8, 7); // use this to be electrically compatible with Mirf
  12. // NRF24 nrf24(8, 10);// For Leonardo, need explicit SS pin
  13. void setup()
  14. {
  15. Serial.begin(9600);
  16. while (!Serial)
  17. ; // wait for serial port to connect. Needed for Leonardo only
  18. if (!nrf24.init())
  19. Serial.println("NRF24 init failed");
  20. // Narrow the receiver bandwidth
  21. if (!nrf24.setRF(NRF24::NRF24DataRate250kbps, NRF24::NRF24TransmitPowerm18dBm))
  22. Serial.println("setRF failed");
  23. // Start the receiver
  24. if (!nrf24.powerUpRx())
  25. Serial.println("powerUpRx failed");
  26. Serial.println("initialised");
  27. }
  28. // Here we only scan the first 50 channels
  29. void loop()
  30. {
  31. uint8_t i;
  32. for (i = 0; i < 50; i++)
  33. {
  34. if (!nrf24.setChannel(i))
  35. Serial.println("setChannel failed");
  36. delay(1); // need at least 170microsecs
  37. uint8_t rpd = nrf24.spiReadRegister(NRF24_REG_09_RPD); // 1 bit only :-(
  38. Serial.print(i, DEC);
  39. Serial.print(": ");
  40. Serial.println(rpd);
  41. }
  42. Serial.println("-------------------------");
  43. delay(1000);
  44. }