Example to detect interference on the various channels available. This is a good diagnostic tool to check whether you're picking a good channel for your application.
59RF24 radio(CE_PIN, CSN_PIN);
65const uint8_t num_channels = 126;
66uint8_t values[num_channels];
71const uint8_t noiseAddress[][2] = { { 0x55, 0x55 }, { 0xAA, 0xAA }, { 0xA0, 0xAA }, { 0xAB, 0xAA }, { 0xAC, 0xAA }, { 0xAD, 0xAA } };
73const int num_reps = 100;
74bool constCarrierMode = 0;
86 Serial.println(F(
"RF24/examples/scanner/"));
90 Serial.println(F(
"radio hardware not responding!"));
95 radio.stopConstCarrier();
96 radio.setAutoAck(
false);
98 radio.setAddressWidth(2);
99 for (uint8_t i = 0; i < 6; ++i) {
100 radio.openReadingPipe(i, noiseAddress[i]);
104 Serial.print(F(
"Select your Data Rate. "));
105 Serial.print(F(
"Enter '1' for 1 Mbps, '2' for 2 Mbps, '3' for 250 kbps. "));
106 Serial.println(F(
"Defaults to 1Mbps."));
107 while (!Serial.available()) {
110 uint8_t dataRate = Serial.parseInt();
111 if (dataRate == 50) {
112 Serial.println(F(
"Using 2 Mbps."));
114 }
else if (dataRate == 51) {
115 Serial.println(F(
"Using 250 kbps."));
118 Serial.println(F(
"Using 1 Mbps."));
121 Serial.println(F(
"***Enter a channel number to emit a constant carrier wave."));
122 Serial.println(F(
"***Enter a negative number to switch back to scanner mode."));
125 radio.startListening();
126 radio.stopListening();
141 if (Serial.available()) {
142 int8_t c = Serial.parseInt();
144 c = min(125, max(0, c));
145 constCarrierMode = 1;
146 radio.stopListening();
148 Serial.print(
"\nStarting Carrier Wave Output on channel ");
153 constCarrierMode = 0;
154 radio.stopConstCarrier();
155 radio.setAddressWidth(2);
156 radio.openReadingPipe(0, noiseAddress[0]);
157 Serial.println(
"\nStopping Carrier Wave Output");
162 while (Serial.peek() != -1) {
163 if (Serial.peek() ==
'\r' || Serial.peek() ==
'\n') {
173 if (constCarrierMode == 0) {
175 memset(values, 0,
sizeof(values));
178 int rep_counter = num_reps;
179 while (rep_counter--) {
180 int i = num_channels;
186 radio.startListening();
188 bool foundSignal = radio.testRPD();
189 radio.stopListening();
192 if (foundSignal || radio.testRPD() || radio.available()) {
200 for (
int i = 0; i < num_channels; ++i) {
202 Serial.print(min(0xf, values[i]), HEX);
204 Serial.print(F(
"-"));
211 Serial.print(F(
"."));
218 for (uint8_t i = 0; i < num_channels; ++i)
219 Serial.print(i / 100);
223 for (uint8_t i = 0; i < num_channels; ++i)
224 Serial.print((i % 100) / 10);
228 for (uint8_t i = 0; i < num_channels; ++i)
229 Serial.print(i % 10);
233 for (uint8_t i = 0; i < num_channels; ++i)
234 Serial.print(F(
"~"));
Driver class for nRF24L01(+) 2.4GHz Wireless Transceiver.
#define delayMicroseconds(usec)