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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47#include <string>
48#include <iostream>
49#include <RF24/RF24.h>
50
51using namespace std;
52
53
54
55
56
57
58#define CSN_PIN 0
59#ifdef MRAA
60 #define CE_PIN 15
61#elif defined(RF24_WIRINGPI)
62 #define CE_PIN 3
63#else
64 #define CE_PIN 22
65#endif
66
67RF24 radio(CE_PIN, CSN_PIN);
68
69
70
71
72
73
74const uint8_t num_channels = 126;
75uint8_t values[num_channels];
76
77
78
79
80const uint8_t noiseAddress[][6] = {{0x55, 0x55}, {0xAA, 0xAA}, {0x0A, 0xAA}, {0xA0, 0xAA}, {0x00, 0xAA}, {0xAB, 0xAA}};
81
82const int num_reps = 100;
83
84void printHeader();
85
86int main(int argc, char** argv)
87{
88
89 cout << argv[0] << endl;
90
91
92 if (!radio.begin()) {
93 cout << "Radio hardware not responding!" << endl;
94 return 1;
95 }
96
97
98 cout << "\n!!! This example requires a width of at least 126 characters. "
99 << "If this text uses multiple lines, then the output will look bad."
100 << endl;
101
102
103 cout << "Select your Data Rate. "
104 << "Enter '1' for 1 Mbps, '2' for 2 Mbps, '3' for 250 kbps. "
105 << "Defaults to 1Mbps."
106 << endl;
107 string dataRate = "";
108 getline(cin, dataRate);
109 if (dataRate.length() >= 1 && static_cast<char>(dataRate[0]) == '2') {
110 cout << "Using 2 Mbps." << endl;
112 }
113 else if (dataRate.length() >= 1 && static_cast<char>(dataRate[0]) == '3') {
114 cout << "Using 250 kbps." << endl;
116 }
117 else {
118 cout << "Using 1 Mbps." << endl;
120 }
121
122
123 radio.setAutoAck(false);
124 radio.disableCRC();
125 radio.setAddressWidth(2);
126 for (uint8_t i = 0; i < 6; ++i) {
127 radio.openReadingPipe(i, noiseAddress[i]);
128 }
129
130
131 radio.startListening();
132 radio.stopListening();
133 radio.flush_rx();
134
135
136 printHeader();
137
138
139 while (1) {
140
141 memset(values, 0, sizeof(values));
142
143
144 int rep_counter = num_reps;
145 while (rep_counter--) {
146
147 for (int i = 0; i < num_channels; ++i) {
148
149
150 radio.setChannel(i);
151
152
153 radio.startListening();
155 bool foundSignal = radio.testRPD();
156 radio.stopListening();
157
158
159 if (foundSignal || radio.testRPD() || radio.available()) {
160 ++values[i];
161 radio.flush_rx();
162 }
163
164
165 if (values[i]) {
166
167 cout << hex << min(0xF, static_cast<int>(values[i])) << flush;
168 }
169 else {
170 cout << '-' << flush;
171 }
172 }
173 cout << '\r' << flush;
174 }
175 cout << endl;
176 }
177
178 return 0;
179}
180
181void printHeader()
182{
183
184 for (uint8_t i = 0; i < num_channels; ++i)
185 cout << static_cast<int>(i / 100);
186 cout << endl;
187
188
189 for (uint8_t i = 0; i < num_channels; ++i)
190 cout << static_cast<int>((i % 100) / 10);
191 cout << endl;
192
193
194 for (uint8_t i = 0; i < num_channels; ++i)
195 cout << static_cast<int>(i % 10);
196 cout << endl;
197
198
199 for (uint8_t i = 0; i < num_channels; ++i)
200 cout << '~';
201 cout << endl;
202}
203
204
Driver class for nRF24L01(+) 2.4GHz Wireless Transceiver.
#define delayMicroseconds(usec)