< async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"">

Friday, August 1, 2014

Testing an nrf24l01 module with raspberry pi using poor mans (2.4Ghz)wifi scanner

ADVERTISEMENT
NRF24l01 modules from nordic offers an inexpensive solution for building two way wireless communication between micro-controllers. But often it is very difficult for a beginner to quickly test them and in many cases there will be minor issues which brings a lot of headaches for a beginner.

In this article, i will explain a very simple solution to wire these modules with a raspberry pi Rev 2 and build a poor mans wifi scanner ( a port from the arduino version , explained here). This is also a quick way to check that the wirings are correct and nrf module is working properly before going to a wireless link which uses multiple nrf modules

Poor mans wifi scanner using nrf24l01 -Raspberry pi version

There are eight/ ten connectors on the ntf modules (see here). Here we use 7 of them which includes 2 power supply lines. The connection is shown below

1) Power supply is 3.3v (important , else you will damage the module)
2) Ground should go to ground
3) SPI pins should go to corresponding GPIO (MOSI, MISO and CLK) see figure
4) CE and CSN see figure below

Connecting an nrf24l01 module to raspberry pi - [click to get a zoomed version]

After connecting the module to the raspberry pi, apply power to the pi (Note: Always unplug the Pi before playing with the GPIO pins)

I have uploaded all the codes on github , so you can easily install the software by 

 #install git  
 sudo apt-get install git  
 #move to home  
 cd ~  
 #clone the nrf24scannerPi repos  
 git clone https://github.com/riyas-org/nrf24scannerPi  
 cd ~/nrf24scannerPi  
 #install build-essential for compiling  
 sudo apt-get install build-essential  
 make  

Now run the program by typing sudo ./scanner which will output the 2.4ghz activity around you

scanning wifi channels with a single nrf24l01 module and raspberry pi


If you don't want to install git and compile the source, you can still test it by downloading the compiled binary here (unzip and do a chmod +x scanner followed by sudo ./scanner)


17 comments:

  1. pi@rpi00 ~/nrf24scannerPi $ sudo ./scanner
    Starting Poor Man's Wireless 2.4GHz Scanner.. [raspberry pi]

    Channel Layout
    > 1 2 3 4 5 6 7 8 9 10 11 12 13 14 <
    |WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW|100
    |WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW|100
    |WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW|100


    I've triple-checked the wiring and everything seems ok. I'm using the 3.3v pin of course. I've also cloned your git and installed/activated all the spi dependencies (the /dev/spidev0.0 and .1 are available) as per your instructions in this and other posts. Do you have any insight about what can be wrong? I'm on a raspbian updated OS, and using wifi to ssh my pi. Maybe the wifi antenna is interfering?

    Any advice would be great! Thanks in advance.

    ===========

    I have seen a similar problem when i was using some other modules (for e.g the one for driving tft display fbtft which also uses spi and i forgot to disable it ) which can give a strong signal like results on scanner. Apart from this, you have covered everything (accidental 5v, damaged nrfmodule, wrong pins, loose connections, also check pin changes with revision ie model B+)

    ReplyDelete
  2. Thank you for your prompt response! So, those WWs and the 100 come from a strong signal?
    My raspberry is a regular model B, I don't have any other SPI module running, and yes, I've checked with another nrf module. In fact, I'm able to run the scanner sketch on my arduino UNO without a problem (at least the serial screen shows the expected channels around) and I wanted to make it chat with my Pi. Thanks again for your great work. I'll continue investigating...

    ReplyDelete
    Replies
    1. OK, my fault... it was just a misplaced pin: MISO was connected to the NRF24 module's pin 8 instead of pin 7. Now the scanner works. I'd have checked it more thoroughly...

      Sorry for the nuisances and thanks again :)

      Delete
  3. can you give de code please

    ReplyDelete
  4. mine got really hot and now the rpi b+ wont turn on !!!! :D while hooked to the nrf +

    it works fine unplugged... im gonna have to try with another nrf since this one might have died on us :(

    ReplyDelete
    Replies
    1. You should really share what you did to fix it. What it a bad device, or was it plugged into 5V?

      Delete
  5. Hi, excuse me for digging this up again. I'm using an NRF24l01 clone (XN297 from Panchip) and I'm looking to use this wifi scanner to set it up on a Raspberry Pi 2 Model B.

    My question is, which files in the repository do I need to change to account for the pin changes on this revision of the board? Any pointers in getting this to work on another revision of the Raspberry Pi (common pitfalls etc...) would be greatly appreciated.

    ReplyDelete
    Replies
    1. Thanks James. It was based on this c/c++ library http://www.airspayce.com/mikem/bcm2835/ for BCM 2835. Scanner is located in https://github.com/riyas-org/nrf24scannerPi and propably the update should go to the files bcm2835.c and bcm2835.h. At present i didnt have a B+ board to test it, but am sure it wont be so difficult to get it work on B+ . Have a look at device tree support (under : http://www.airspayce.com/mikem/bcm2835/). Best regards

      Delete
    2. Thanks for the quick reply Riya, I'm still looking into getting it working. Currently when I run the scanner file it simply returns empty channels, I have a feeling I haven't adjusted for the change in pins between board revisions properly but am unsure exactly where to change it/how to check this.

      The Bcm2835 library is installed, SPI dependencies are loaded and the wiring is correct as per the diagram (I am a little unsure about CSN going to CE0/GPIO.10 and CE going to GPIO 6). I was thinking it would be the other way around with the Chip select/CSN pin be going to GPIO6 and Chip Enable/VE going to CE0 instead?

      Also, in scanner.cpp I noticed that the CE and CSN pins are defined as pins 22 and 24, I'm guessing these have to be changed to the raw numbers of the pins I'm using?

      Eg - line 35: uint8_t ce_pin = RPI_v2_GPIO_P1_22;

      Do I change this by going into the bcm2835 header and altering the raw bcm numbers in the pin declarations?

      I'm going to keep looking into this, my SSH via console cable stopped working at the same time as I installed this BCM library so I think my pins are being set differently because of it.

      Thanks,
      James

      Delete
    3. I guess the first 26 pins in all models of Pi has similar layout. So connection should be more or less the same. I wont recommend editing the header files. Instead, download the latest version from here www.airspayce.com/mikem/bcm2835/bcm2835-1.42.tar.gz which has support for B+ model and will solve your problems. The library on my github is the older one and i will update it soon.

      Best regards

      Riyas

      Delete
    4. Hi Riya, thanks for your help so far, I've had a bit of a look around for solutions to get this working with the Raspberry Pi 2 model B (40pin header) and came across this post

      https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=99227

      Where the post from Meandrey indicates 2 lines need changing, one in the bcm2835 header file and another in the makefile. I applied these changes and get empty channels when I run the scanner,

      However when I disconnect CSN I get the following

      http://tinypic.com/r/f2v411/8

      Does this look right to you? It looks allot noisier than the example you provided (neighboring networks overlapping?).

      I'm wondering why disconnecting slave select (forcing it low) causes the chip to work, maybe there's another line I need to change in this code to have the GPIO pin connected to CSN driven low properly.

      Let me know what you think

      Best regards,
      James

      Delete
    5. Thanks for the comments. Seems like a lot of signals or something wrong. In the scanner.cpp file, you can change the scanchannel functions a bit. Try replacing j<200 with j<100 or j<50 and see if it decrease the sensitivity a bit. Best regards

      Delete
  6. This comment has been removed by the author.

    ReplyDelete
  7. For RPi 2, there is a slight change in bcm2835.h file. Goto nano bcm2835.h, change #define BCM2835_PERI_BASE 0x20000000 to #define BCM2835_PERI_BASE 0x3F000000. make to compile. I've tested it for 3.18.7+v7 kernel version with Device tree turned off and SPI device turned on using raspi-config. Hope this crucial helps someone who stumbles across this for making it work on RPi 2. It is also documented on this thread. Link : https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=99227 Hope it helps. :)

    ReplyDelete
  8. There is no output when I am connecting it to my pi, the scanner program is running but no result

    ReplyDelete
    Replies
    1. Make sure spi is enabled/working. A damaged nrf module may also behave similarly. If you have an arduino, the module can be tested with it. See http://blog.riyas.org/2013/12/working-quick-start-guide-for-nrf24l01.html?m=1

      Delete