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

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

Use ctrl+C to exit

1/*
2 Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 version 2 as published by the Free Software Foundation.
7
8
9 03/17/2013 : Charles-Henri Hallard (http://hallard.me)
10 Modified to use with Arduipi board http://hallard.me/arduipi
11 Changed to use modified bcm2835 and RF24 library
12
13 */
14
26#include <cstdlib>
27#include <iostream>
28#include <RF24/RF24.h>
29
30using namespace std;
31
32/****************** Linux ***********************/
33// Radio CE Pin, CSN Pin, SPI Speed
34// CE Pin uses GPIO number with BCM and SPIDEV drivers, other platforms use their own pin numbering
35// CS Pin addresses the SPI bus number at /dev/spidev<a>.<b>
36// ie: RF24 radio(<ce_pin>, <a>*10+<b>); spidev1.0 is 10, spidev1.1 is 11 etc..
37#define CSN_PIN 0
38#ifdef MRAA
39 #define CE_PIN 15 // GPIO22
40#else
41 #define CE_PIN 22
42#endif
43// Generic:
44RF24 radio(CE_PIN, CSN_PIN);
45/****************** Linux (BBB,x86,etc) ***********************/
46// See http://nRF24.github.io/RF24/pages.html for more information on usage
47// See http://iotdk.intel.com/docs/master/mraa/ for more information on MRAA
48// See https://www.kernel.org/doc/Documentation/spi/spidev for more information on SPIDEV
49
50// Channel info
51const uint8_t num_channels = 126;
52uint8_t values[num_channels];
53
54const int num_reps = 100;
55int reset_array = 0;
56
57int main(int argc, char** argv)
58{
59 // Print preamble
60
61 // print example's name
62 printf("%s", argv[0]);
63
64 //
65 // Setup and configure rf radio
66 //
67 radio.begin();
68
69 radio.setAutoAck(false);
70
71 // Get into standby mode
72 radio.startListening();
73 radio.stopListening();
74
75 radio.printDetails();
76
77 // Print out header, high then low digit
78 int i = 0;
79
80 while (i < num_channels) {
81 printf("%x", i >> 4);
82 ++i;
83 }
84 printf("\n");
85
86 i = 0;
87 while (i < num_channels) {
88 printf("%x", i & 0xf);
89 ++i;
90 }
91 printf("\n");
92
93 // forever loop
94 while (1) {
95 // Clear measurement values
96 memset(values, 0, sizeof(values));
97
98 // Scan all channels num_reps times
99 int rep_counter = num_reps;
100 while (rep_counter--) {
101
102 int i = num_channels;
103 while (i--) {
104
105 // Select this channel
106 radio.setChannel(i);
107
108 // Listen for a little
109 radio.startListening();
111 radio.stopListening();
112
113 // Did we get a carrier?
114 if (radio.testCarrier()) {
115 ++values[i];
116 }
117 }
118 }
119
120 // Print out channel measurements, clamped to a single hex digit
121 i = 0;
122 while (i < num_channels) {
123 if (values[i])
124 printf("%x", min(0xf, (values[i] & 0xf)));
125 else
126 printf("-");
127
128 ++i;
129 }
130 printf("\n");
131 }
132
133 return 0;
134}
135
136// vim:ai:cin:sts=2 sw=2 ft=cpp
Driver class for nRF24L01(+) 2.4GHz Wireless Transceiver.
Definition: RF24.h:116
#define delayMicroseconds(usec)