Optimized high speed nRF24L01+ driver class documentation v1.4.8
TMRh20 2020 - Optimized fork of the nRF24L01+ driver
Loading...
Searching...
No Matches
examples/scanner/scanner.ino

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.

Inspired by cpixip. See http://arduino.cc/forum/index.php/topic,54795.0.html

1/*
2 * Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
3 * Updated 2020 TMRh20
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
8 */
9
25#include "RF24.h"
26#include "printf.h"
27
28//
29// Hardware configuration
30//
31
32#define CE_PIN 7
33#define CSN_PIN 8
34// instantiate an object for the nRF24L01 transceiver
35RF24 radio(CE_PIN, CSN_PIN);
36
37//
38// Channel info
39//
40
41const uint8_t num_channels = 126;
42uint8_t values[num_channels];
43
44//
45// Setup
46//
47
48void setup(void) {
49 //
50 // Print preamble
51 //
52
53 Serial.begin(115200);
55 Serial.println(F("\n\rRF24/examples/scanner/"));
56
57 //
58 // Setup and configure rf radio
59 //
60
61 radio.begin();
62 radio.setAutoAck(false);
63
64 // Get into standby mode
65 radio.startListening();
66 radio.stopListening();
67 radio.printDetails();
68
69 //delay(1000);
70 // Print out header, high then low digit
71 int i = 0;
72 while (i < num_channels) {
73 Serial.print(i >> 4, HEX);
74 ++i;
75 }
76 Serial.println();
77 i = 0;
78 while (i < num_channels) {
79 Serial.print(i & 0xf, HEX);
80 ++i;
81 }
82 Serial.println();
83 //delay(1000);
84}
85
86//
87// Loop
88//
89
90const int num_reps = 100;
91bool constCarrierMode = 0;
92
93void loop(void) {
94 /****************************************/
95 // Send g over Serial to begin CCW output
96 // Configure the channel and power level below
97 if (Serial.available()) {
98 char c = Serial.read();
99 if (c == 'g') {
100 constCarrierMode = 1;
101 radio.stopListening();
102 delay(2);
103 Serial.println("Starting Carrier Out");
104 radio.startConstCarrier(RF24_PA_LOW, 40);
105 } else if (c == 'e') {
106 constCarrierMode = 0;
107 radio.stopConstCarrier();
108 Serial.println("Stopping Carrier Out");
109 }
110 }
111 /****************************************/
112
113 if (constCarrierMode == 0) {
114 // Clear measurement values
115 memset(values, 0, sizeof(values));
116
117 // Scan all channels num_reps times
118 int rep_counter = num_reps;
119 while (rep_counter--) {
120 int i = num_channels;
121 while (i--) {
122 // Select this channel
123 radio.setChannel(i);
124
125 // Listen for a little
126 radio.startListening();
128 radio.stopListening();
129
130 // Did we get a carrier?
131 if (radio.testCarrier()) {
132 ++values[i];
133 }
134 }
135 }
136
137
138 // Print out channel measurements, clamped to a single hex digit
139 int i = 0;
140 while (i < num_channels) {
141 if (values[i])
142 Serial.print(min(0xf, values[i]), HEX);
143 else
144 Serial.print(F("-"));
145
146 ++i;
147 }
148 Serial.println();
149
150 } //If constCarrierMode == 0
151}
Driver class for nRF24L01(+) 2.4GHz Wireless Transceiver.
Definition: RF24.h:116
@ RF24_PA_LOW
Definition: RF24.h:50
#define delay(milisec)
#define delayMicroseconds(usec)
void printf_begin(void)
Definition: printf.h:33