Intro: The TRUTH About the Nrf24L01 Transceiver
Jimmy Wales said: "We are in the very beginnings of the internet. Lets use it wisely"
The truth about the nrf24L01 transceiver is that it is very easy to use and fun to work with if you do certain things correctly. Unfortunately the internet contains a lot of information about this radio that is dated and no longer applies or never applied or never worked or is just plain stupid and can lead to confusion. There are videos and other instructables that deal with this radio, but there is always room for more. So, both to share what I have learned and document my efforts I present this instructable.
Step 1: What Am I Talking About?
The nrLF2401 and variants are a 2.4Ghz transceiver (radio) that is capable of both transmitting and receiving a data stream of packets. It is a great place to start if you want to work with radios given the relatively small number of control registers that need to be programmed for most purposes, the simple operating flow, and the small investment needed. (< one dolla ). As with most transceivers, this one uses the SPI bus to connect to your compute platform. There are more expensive, and more complicated radios out there but you can do a lot with this one. You will need two of them and two compute platforms to experiment with . I use an Arduino Pro Mini module that I build up for most of my playing around, but I have put this radio on to several other newer platforms such as the Intel D2000 (quark2) and the ESP8266 with no problems. I will publish a separate instructable on these other platforms shortly to document what I did. Also, as I will cover in more detail later ( this is a shameless plug for other instructables) , I have also created both a C++ and C, full bit bang (no spi controller needed, just five IO pins) version of what I consider to be the only driver library you need if you are working with an Arduino. I will also cover this in a separate instructable.
Here is a clip of the first page of the nrLF2401(+) data sheet package. This gives you an idea of the radios capabilities.
Step 2: Hardware That I Use for Testing
To make development with the nrf24l01 easy, I selected the Arduino Pro Mini as my compute. The form factor is small and it is fully featured. I built up some small modules that allow me to easily plug parts in and out and have a stable platform to hook into other systems.
I would like to give an unsolicited testimonial for the BPS SB4 Snappable BreadBoard. I found these on Amazon and have been delighted with the quality and flexibility. The arrangement of connected pads make it easy to create small, professional prototypes. I have attached a picture.
One caveat is that the radio is a 3.3 V part. I am using a 3.3V Pro Mini which makes interfacing easy. It is not suggested to hook up a 5 V Pro Mini.
A great website to use for reference is MySensors.org. There is a page on this site that has the pinouts for both the Arduino Pro Mini and the nrf24. This site has examples and code for many things as well. I suggest that before you use their higher level Sensor library that you spend time with the RF24 driver library. Once you understand how this code works, you will be in a much better position to use higher level code.
To do any work with radios you will need to build up two modules. That way one module can transmit and the other receive. Makes sense. This means you need two (2) of everything :)
Note the .01 uF Capacitor between the power and ground pins. This is absolutely required. Two are even better but one will work. If you don't do this, your radios will likely be very flaky or not work! Although I should have known better, this took me a while to fully understand. And yes, others have documented this.
I assume that you know how to create a sketch and flash it.
Step 3: The Library Code
The radio library that everyone uses was written by maniac bug. His repo is now maintained by TMRh20. We are all indebted to them for their hard work.
If you google nrf24l01 you will be presented with many choices that may or may not be relevant. Do not waste your time and go to this link:
Download the zip file of this library and using the library installer , load the library into your Arduino libraries folder. I assume that you are using at least version 1.6.4 so you have the new installer.
Note for Mac Users:
From personal experience, if you upgrade to anything greater than Arduino1.6.3 on a macbook pro and have been using Arduino for a while you may have issues with starting and crashing. This is a result of left over 1.5.X code. I recently posted a question on the arduino forum under alias stumpygreg and got a great answer so look there if you are experiencing this.
Step 4: The Example to Run First
After spending quite a bit of time working with what are supposed to be simple examples I decided to simplify one of the examples to make it even simpler. Just a transmit or receive of three incrementing integers. Wherever you store your sketches, create a folder called RF24 and inside this folder a folder called "SimpleExample" . Copy the two files into this folder. Open the sketch in Arduino and flash onto both experimental modules. Make sure you pick the correct board and processor. Choose one module to be the transmitter and open the Serial Monitor for that port. You should see something like screen shot 1. Enter a capital T into the send box and hit Send. You should see the something like the second screenshot. Now go back to the receive port and look at the Monitor and you should see something like the third screen shot. You are now transmitting from one radio to another.
Step 5: Some Things to Know
The radio has a lot of flexibility and you should read the data sheet to fully understand what the radio can do. A couple of things need to be explained.
First, you should understand the concept of channels. Even though the radio transmits on "2.4Ghz" this is just the general frequency. There are actually 126 RF channels at a couple of Mhz spacing that start at 2.4Ghz. The radio driver sets the channel to 76 under the assumption that this part of the spectrum will not be busy. In my case this was actually the busy part if the spectrum and I set the channel to 1.
Second, the default is for the transmitter to come up with full power. Since you are likely to have the two radios right next to each other, I set the power to low which lowers the "flaky factor" for the radio since there is less current draw peaks. This would be set up to higher power depending on use.
So, read the data sheet and I hope this instructable was useful.