Poor Man's 2.4 GHz Scanner

Thanks!

These are all great ideas. It is helpful to hear some of these ideas for what would help new people. My own usage of the library has grown rather monstrous and complex, so I'm kind of losing perspective.

The problem is, as the usefulness increases so does the complexity, and then inversely goes the approachability.

My full-blown usage is a multi-hop mesh network with sensor nodes reporting readings back to a base unit that logs to a MySQL database. But, uh, good luck to new users figuring that all out.

I have this notion of writing a higher-level library that sits atop the RF24 library, and manages the mesh network details. That might make the complex stuff more approachable.

I'll try working up some examples based on your suggestions, though. If you think of more details on how a user might actually do something with those parts, do feel free to expound.

Hi, Wow, cool applications.. That should be really extensible with long-range radios.. like over a campus.

There are two levels of users to support. I am doing a workshop with guys here at the King Abdullah University of Science and Technology who are Supercomputer admins, Algorithm researchers, Unix/SQL weenies, BioDatabase guys etc. Then I have 9th graders. I think there can be a higher level API with the lower levels exposed so a user can learn and do more complex things.

So let's think about it a bit and try to figure out the appropriate levels...

Thanks for your work and your willingness!

This works great. (wondering the first thing I was going to build with these things.)

I made sure that all WiFi, Bluetooth, and (anything around 2.4Ghz) was off.
(I only got a few minor blips from some random device.)
Then I turned on the microwave.
On all chanels, I got very heavy interfierence.

So you can also put this as a microwave detector.

Awesome project.

Hey, sorry for hijacking the thread, above. I posted a new thread http://arduino.cc/forum/index.php/topic,62222.0.html for RF24, so as to keep this one on-topic.

Thanks for all the nice feedback!

Just a short note I forgot to mention in the intial post: the above listed scanner program switches off the Enhanced Shockburst feature of the nRF24L01+. As all libs available currently for nRF24L01+ do not initialize this feature of the chip correctly on start-up, you need to power down your circuit once before uploading and using another program/lib in order to reset the nRF24L01+. Otherwise programs which use the Enhanced Shockburst feature (basically all libs available for the nRF24L01+ do this) won't run.

The reason is that a simple reset (as happening for example when uploading new programs with the Arduino IDE) won't reset the nRF24L01+ to it's factory setting. However, simply unconnecting the power-supply and/or USB for a few seconds will do the trick.

Have fun! - cpixip

maniacbug:
new people

Hey, That's me! :slight_smile:

I just got a pair of transceivers in the mail this morning from an eBay seller in China ($12.80 for 2 with free shipping). Don't need them yet, but figured that at that price they're be worth getting to play around with at some point, so will be keeping an eye on this thread (and Maniac's newly created one). :slight_smile:

Thanks for all the hard work guys.

cpixip:
As all libs available currently for nRF24L01+ do not initialize this feature of the chip correctly on start-up, you need to power down your circuit once before uploading and using another program/lib in order to reset the nRF24L01+.

Yes, indeed. I suppose this could be stated more broadly. The available libs do not reset the chip registers to the factory state on startup. If you want the factory state, you have to power cycle. Not sure this is "incorrect".

Hi maniacbug -

maniacbug:
... I suppose this could be stated more broadly. The available libs do not reset the chip registers to the factory state on startup. If you want the factory state, you have to power cycle. Not sure this is "incorrect".

... - as we are doing this for a hobby, it's probably ok. Just need to remember that only a power cycle gets your device in a properly defined state.

On the other hand, from a design point of view, any lib (for any device, not just the nRF24L01+) which only works if the device is in a certain state on start-up will fail under some circumstances.

Clearly something you want to avoid if that device is mission-critical ... :wink:

A lib which does not a full initialization will probably also fail in an application featuring a watchdog function - as this won't "reset" external chips properly when a restart is occuring. So it maybe a good idea to mention this fact for other users of a lib.

My code of the 2.4 GHz scanner above does of course violate this as well - it does assume that the nRF24L01+ is in the factory reset state when it starts. For a hobby project, I think this is ok. You just need to be aware that a simple reset won't get the nRF24L01+ back into a working state for other libraries/programs... :slight_smile:

Best, cpixip.

Hey thanks for making such a great tool - When i try to run this code i see a Series of M or Rs across the channels with no color - I really was unsure how to interpret it or if it is working correctly. Any help would be appreciated if this code still works on the current Arduino platform. Thanks again

Thanks for your comments. The colors were added in the inital example just for marking the different 2.4GHz component seen. Of course there are no colors available in the terminal prg of the Arduino IDE.

The amount of power in each channel is displayed in ASCII grey scale. This is an old technique from the time when lineprinters were the primary output of mainframe computers. Have a try on your favorite search engine to find out more (here's one link which came up Character representation of grey scale images).

There is no reason why the code should not work with current Arduinos as the code uses only standards. I have however no way of testing the UNO or newer devices - I do not own any of these.

In case you have doubts, try any of the newer RF24-libraries. Most of them feature a scanner example based on my old code. These libraries are pretty much up-to-date.

In any case - have fun!

The Poor Man's 2.4 GHz Scanner work great on my UNO, but it will not work on the Mega2560.
I changed the following in the program #define CE 53

Where do I make the changes for CSN 48, MOSI 51, MISO 50, SCK 52 ?
Any help would be great
Ron

really great work and very inspiring. i'm thinking about using wifi signals for indoor positioning.
as i understand, your design is not actually a wifi transmitter but really more like a listener and
is not able to communicate via standard wifi.
i could imagine that this is actually a bonus since probably the power consumption is less compared
to a fully fledged wifi connector such as sparkfun's wifly.

do you have any thoughts / tips /caveat about using your setup for indoor positioning? for example,
the network activity (if that correlates with the power on different bands, i don't know) should certainly
not be used, but actually the network strenght of the different routers around.
also, we possibly would need to find out about temporary signals and stationary signals (wifii routers
are pretty stationary and continous, bluetooth may move or be off, microwaves don't move but are
on and off at unpredictable times).

finally: would it make sense to use two such scanners on either end of the bot so that one could have
a "stereo" view on the singals? or are these wave lengths / the sample rate of the device not suitable?
sorry, i'm a newbie on all of this, but to use wifi signals as a reference for sensor fusing is really tempting.

Hello,

Very nice scanner! I really would like to use it.
I want to use the nrf24L01 in combination with a 2.4Ghz camera and want to see the free zone to set the channel.
I have two breakout board which both do not seem to work with the code.
I hooked them up on an Arduino mini pro and an Arduino uno to see if that was the problem.
I'm sorry for the long paste, but they both show something like:
(look at the end of the output, it finally produces something, but it is very little)
What am I doing wrong?

Starting Poor Man's Wireless 2.4GHz Scanner ...

Channel Layout
>      1 2  3 4  5  6 7 8  9 10 11 12 13  14                     <
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
>      1 2  3 4  5  6 7 8  9 10 11 12 13  14                     <
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
>      1 2  3 4  5  6 7 8  9 10 11 12 13  14                     <
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
>      1 2  3 4  5  6 7 8  9 10 11 12 13  14                     <
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
>      1 2  3 4  5  6 7 8  9 10 11 12 13  14                     <
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
>      1 2  3 4  5  6 7 8  9 10 11 12 13  14                     <
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|  *****-W*                                                      | 3
>      1 2  3 4  5  6 7 8  9 10 11 12 13  14                     <
|              ::::WW+++::    :+++:++++                          | 4
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
>      1 2  3 4  5  6 7 8  9 10 11 12 13  14                     <
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
|                                                                | 0
  • the nrf24 might not working properly. You might check this by creating some 2.4GHz traffic close to the nrf24. Put it in close vincinity of your WLAN (make sure it's on ;). Putting the nrf24 in the vincinity of a microwave (but don't put it into the microwave!!!) and switching that on for a few seconds should give you also a strong signal.

assadollahi:
do you have any thoughts / tips /caveat about using your setup for indoor positioning?

this is not a very precise 2.4GHz scanner as the nrf24 delivers only a single bit, "signal strength above threshold" (or not). You won't be able to use it for such a purpose. Other chips have a better output of reception strength, you might google around for these. This tiny hack is just good to spot channels of low activity, nothing more... :sunglasses:

Here is a blog post about implementing the poor man's 2.4G scanner using the RFToy:
http://weatherhelge.wordpress.com/2014/12/31/2-4ghz-scanner-using-rftoy/
the built-in OLED screen that comes with the RFToy is quite handy for display.

Hello Guys,

I still did not understand how this grey scale waterfall display works. I mean what does the numbers beside each line represent on the display? Can some one give quick explanation of code?

its kind of urgent as I am using this test in my project.

Thanks....

Hi what is the meaning of the numbers on the right side? at first it seems the strength of the signal, but i am unsure.

Here is clone with LCD1602a:

And here is code for communication density analysis. It is possible to show live spectrum (SW_MODE = 0), but packets are very short and for exploration of communication density is needed statical display rather with data collection over some time.

-64dB threshold is good for this case. Just place device for some time (half hour or so) near powered-off wifi-AP to check communication density at AP place. Then leave device (for half hour or so) at place from where you will connect to AP (AP still powered off). From both diagrams you can explore free channels right for your AP. If your AP is within one room, then you can make only one measurement.

Used Arduino Pro Micro 3.3V/8MHz, NRF module powered from Arduino VCC, Arduino and LCD1602a(5V) powered from RAW (3.7V Li-ion battery LIR2032 + TP4056 charger module hacked to 30mA charge current). Power consumption about 20mA (without backlight).

Compiler: Arduino 1.6.7

 /* A simple 2.4GHZ spectrum analyser with nrf24l01,character lcd and an arduino 
  *  
  * http://blog.riyas.org/2014/06/a-simple-24ghz-spectrum-analyser-arduino-lcd-shield.html
  * 
  * Connect the nrf module to the spi pins (10,11,12,13)  and A1 (for CE) and an lcd to pin 8,9,4,5,6,7 
  */

/*
 *  exact wifi channells map to 16 bars: (0), 1...13, (hole), 14
 */
 
 #include <SPI.h>  
 #include <LiquidCrystal.h>  
 // The LCD is conected to pins RS-8, EN-9, D4-4, D5-5, D6-6, D7-7, RW-GND, VO-GND  
 LiquidCrystal lcd(8, 9, 4, 5, 6, 7);  
 byte minibars[8][8];  
 //credits to Poor Man's Wireless 2.4GHz Scanner  
 // credits to all others  
 // uses an nRF24L01p connected to an Arduino  
 //   
 // Cables are:  
 //   CS    -> 10  
 //   MOSI   -> 11  
 //   MISO   -> 12  
 //   SCK   -> 13  
 // and CE    -> A1  
 //  
 // Modified from original code: March 2011 by Rolf Henkel  
 //  
 #define CE A1  
 // Array to hold Channel data  
 #define CHANNELS 94  
 int channel[CHANNELS];  
 // nRF24L01P registers we need  
 #define _NRF24_CONFIG   0x00  
 #define _NRF24_EN_AA    0x01  
 #define _NRF24_RF_CH    0x05  
 #define _NRF24_RF_SETUP  0x06  
 #define _NRF24_RPD     0x09  
 //SoftSPI<SOFT_SPI_MISO_PIN, SOFT_SPI_MOSI_PIN, SOFT_SPI_SCK_PIN, SPI_MODE> spi;  
 
byte CH_LEVEL[16];  

byte scan_time = 255;  // minimum 130 for system + 40 for AGC - sensitivity to packet density (cca 250us per packet)

byte SW_MODE = 1; // 0 = live wifi scanner   1 = spectrum occupy
byte SCAN_COUNT = 32; // No of scans per one display - sensitivity to density 
                      // SCAN_COUNT * 5 (MHz in ordinary channel) <256 
byte DISP_ZOOM = 1;  // ZOOM level 0=1, 1=2, 2=4, 3=8, 4=16, 5=32 ...
                     // full "strength" to 15 levels, but some saturation wanted

void LCDdemo(){   // Built the characters for bars.  
  for (byte j=0; j<=7; j++)   
  {  
   for (byte i=0; i<=7; i++)  
   {  
    if (i<=j)  
    { minibars[j][7-i] = B01110;}    
    else  
    { minibars[j][7-i] = 0;}  
   }  
  }   
  for (byte i=0; i<=7;i++)  
  {  
   lcd.createChar(i, minibars[i]);  
  }  
  lcd.begin(16, 2);     
  for (byte j=0; j<=7;j++)  
  {  
   lcd.setCursor(j, 0);  
   lcd.write(j);  
   lcd.setCursor(j, 1);  
   lcd.write(7);   
  }  
}


byte getRegister(byte r)   // get the value of a nRF24L01p register  
 {  
  byte c;  
  PORTB &=~_BV(2); //D10  
  //PORTC &=~_BV(1); //analogue 1 as SS  
  c = SPI.transfer(r&0x1F);  
  c = SPI.transfer(0);   
  PORTB |= _BV(2);  
  //PORTC |= _BV(1); //analogue 1 as SS  
  return(c);  
 }  
 

void setRegister(byte r, byte v)   // set the value of a nRF24L01p register  
 {  
  PORTB &=~_BV(2);  
  //PORTC &=~_BV(1);  
  SPI.transfer((r&0x1F)|0x20);  
  SPI.transfer(v);  
  PORTB |= _BV(2);  
  //PORTC |= _BV(1);  
 }  

 
void powerUp(void)  // power up the nRF24L01p chip  
 {setRegister(_NRF24_CONFIG,getRegister(_NRF24_CONFIG)|0x02);  
  delayMicroseconds(130);  
 }  
 
void powerDown(void){setRegister(_NRF24_CONFIG,getRegister(_NRF24_CONFIG)&~0x02); }    // switch nRF24L01p off  
void enable(void){  PORTC |= _BV(1);}    // enable RX   
void disable(void){PORTC &=~_BV(1);}     // disable RX  

void setRX(void)   // setup RX-Mode of nRF24L01p  
{ setRegister(_NRF24_CONFIG,getRegister(_NRF24_CONFIG)|0x01);  
  enable();  
  delayMicroseconds(scan_time);    // the recommended delay of 130 usec  
}  


void scanChannels(void)   // scanning all channels in the 2.4GHz band  
{ disable();  
  for( byte j=0 ; j<= SCAN_COUNT ; j++) 
   {for( byte i=0 ; i<CHANNELS ; i++)  
    {
    setRegister(_NRF24_RF_CH,i);  // select a new channel  
    setRX();  // switch on RX  
    disable();        // this is actually the point where the RPD-flag   is set, when CE goes low  
    if( getRegister(_NRF24_RPD)>0 )  channel[i]++;    // read out RPD flag; set to 1 if  received power > -64dBm  
   }  
  }  
 }  

  /*      https://upload.wikimedia.org/wikipedia/commons/thumb/8/84/NonOverlappingChannels2.4GHzWLAN-en.svg/720px-NonOverlappingChannels2.4GHzWLAN-en.svg.png
    WIFI MHz  NRF-CH  od-do
    -   2401     1    1-8
    1   2412    12    9-14
    2   2417    17    15-19
    3   2422    22    20-24
    4   2427    27    25-29
    5   2432    32    30-34
    6   2437    37    35-39
    7   2442    42    40-44
    8   2447    47    45-49
    9   2452    52    50-54
    10  2457    57    55-59
    11  2462    62    60-64
    12  2467    67    65-69
    13  2472    72    70-74
    --  2477    77    75-79
    14  2484    84    80-94

    802.11b - 20MHz (22MHz), ch. 1,6,11,14 - end 2.494 GHz
          g/n       16,25MHz (20MHz)   1,5,9,13 - end 2.4835 GHz
          n         33,75MHz (40MHz)    3,11  - end 2.4835 GHz
   */

void outputChannels(void)  
{  
  feedChannel(0, 1, 8);
  feedChannel(1, 9, 14);
  feedChannel(2, 15, 19);
  feedChannel(3, 20, 24);
  feedChannel(4, 25, 29);
  feedChannel(5, 30, 34);
  feedChannel(6, 35, 39);
  feedChannel(7, 40, 44);
  feedChannel(8, 45, 49);
  feedChannel(9, 50, 54);
  feedChannel(10, 55, 59);
  feedChannel(11, 60, 64);
  feedChannel(12, 65, 69);
  feedChannel(13, 70, 74);
  feedChannel(14, 75, 79);
  feedChannel(15, 80, 94);
}  

void feedChannel(byte CH_wifi, byte CH_low, byte CH_high)  
 {  
  byte strength = 0;  
  for( byte i=CH_low ; i<=CH_high ; i++){  
   strength = strength + channel[i];  
   if(CH_LEVEL[CH_wifi] < strength) CH_LEVEL[CH_wifi] = strength;
   if (SW_MODE == 0) {plot_minibars(CH_wifi, strength);}
   else              {plot_minibars(CH_wifi, CH_LEVEL[CH_wifi]);}
   channel[i] = 0; 
  }
}  


 void plot_minibars(byte location, byte strngth)  
 {  
  byte str_disp = strngth >> DISP_ZOOM; //ZOOM
  if (str_disp>15)  
  {  
   lcd.setCursor(location, 1);  
   lcd.write(7);  
   lcd.setCursor(location, 0);  
   lcd.write(7);  
  }  
  else if (str_disp>7)  
  {  
   lcd.setCursor(location, 1);  
   lcd.write(7);  
   lcd.setCursor(location, 0);  
   lcd.write(str_disp-8);    
  }  
  else  
  {  
   lcd.setCursor(location, 1);  
   lcd.write(str_disp);  
   lcd.setCursor(location, 0);  
   lcd.write(32);    
  }  
 }  




//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void setup()  
 {  
  LCDdemo();
  
  // Setup SPI  
  SPI.begin();  
  SPI.setDataMode(SPI_MODE0);  
  SPI.setClockDivider(SPI_CLOCK_DIV2);  
  SPI.setBitOrder(MSBFIRST);  

  pinMode(CE,OUTPUT);    // Activate Chip Enable  
  disable();  
  powerUp();    // now start receiver  
  setRegister(_NRF24_EN_AA,0x0);    // switch off Shockburst  
  // make sure RF-section is set properly   
  // - just write default value...   
  setRegister(_NRF24_RF_SETUP,0x0F);   
}  

void loop()   
 {   
  scanChannels();   
  outputChannels();   
 }

wifi.jpg

I keep getting the following error on the next to last "}"; the end of the "if" statement at the very end;
stray '\302' in program; \302 maps to a period; but there isn't one anywhere near this section. Any suggestions?