The nRF24L01+ RF Module Part 1...

The nRF24L01 and nRF24L01+ RF are single chip 2.4 GHz Transceiver devices made by our old friend Nordic Semiconductors who, in their early days, were responsible for the Atmel AVR devices. The nRF24L01 is the original RF device and the nRF24L01+ or nRF24L01P, as it is also known, is the updated version.

The most common nRF24L01+ module
(8 signal pins)

Alternative nRF24L01+ module
(note the 10 signal pins)

Modules are available which are complete Transceivers with built-in antennas and IDC connectors. They operate in the 2.4 GHz ISM band with 126 channels available for the transmission/reception of digital data over short distances. nRF124L01 modules are available for as little as GBP 0.50p on eBay and, as long as you realise their limitations, they can be quite useful. I say limitations and I mean just that. If you read the blurb about these modules it is claimed that they have a range of up to 100 metres and I can confirm that this is true however, this is in clear air, line of sight and with correct orientation of the antennas.

Move the modules near to or inside buildings of any kind and the range drops significantly. Another factor is interference from electrical/electronic devices such as computers, televisions, microwave ovens, Wi-Fi Routers, DECT telephones, video senders, etc. etc. etc. Put simply, the nRF24L01 modules are intended for short range control functions such as garage door openers, remote controls and other such uses. Data can be sent reliably however as the nRF24L01 has significant error checking and re-transmission capabilities which make it very useful for the hobbyist.

An ideal example of where these modules can be used is in robotics where such things as servo or stepper motor control data can be sent to a remote robot and sensor data can be received back.

So, let me start by making one thing clear; there is a lot of nonsense being bandied about in various arenas such as forums and blogs where it is clear that the writers don't understand how the modules work. They discuss the lack of range, which is a major topic, and come up with various solutions, some correct, others not. I can only say that what I present here is from my own experiments, and lengthy trials. If you buy an nRF24L01 (the nRF24L01+ is the one you should really buy) it will work "out of the box" given the right software and conditions but, there is a lot you can do to improve the performance of the modules.

The very first step is to download the Product Specification from Nordic Semiconductor and read it!

The Hardware:

The picture on the left shows a typical nRF24L01 module which can be purchased on the Internet for as little as GBP 0.50p. They are usually sold in pairs or fours. Obviously, you need at least two modules to send and receive data.

Please be aware before we go any further that these modules have a maximum supply voltage of 3.3 Volts (minimum supply voltage is 1.9 Volts). If you try and run them off of a 5 Volt supply you will permanently damage them! Luckily, the designers of the nRF24L01 chip made the signal inputs 5 Volt tolerant which means that we can talk to them from normal 5 Volt logic.

The modules communicate via the SPI interface which is standard on the Arduino UNO but be careful if you intend to use them with stand-alone projects using other AVR devices. Although most AVR devices have an SPI interface, it is only used for programming on some devices. The Atmega328 will happily "talk" to a nRF24L01 module whereas an ATtiny85 will not without special libraries which reproduce the SPI signals on different pins. That said, another factor controlling which AVRs you can use is the available Flash and SRAM as the nRF24L01 libraries need a lot of space especially when it comes to the RF24Network library.

In addition to the normal SPI signals, SCK, MISO and MOSI, two other signals are required. These are Chip Enable (CE) which selects TX or RX and CSN which is the SPI Chip Select.

Thankfully the nRF24L01 library, RF24, which will be discussed later takes care of all the switching and chip selection for us but it is always worth knowing how it works. There are many powerful features within the nRF24L01 chip which can be used to create complex mesh networks of multiple modules. Data is CRC checked and a transmitting module can actually know that the data or payload it sent to another module has been received without having to ask for an acknowledgement form the target module.

The frequencies used by these modules are based in the 2.4 GHz band with a channel width of 1 - 2 MHz depending on the data rate chosen. Channels are allocated at 2.4GHz + channel_number x 1MHz for lower data rates. At higher data rates the channel width and spacing increases so that at 2Mbs data rate, the channel is 2MHz wide with a 2MHz spacing. This results in a total operating spectrum of 2.4GHz to 2.4525GHz. Any two modules communicating with each other MUST have the same channel number or else they will not work!

The nRF24L01 uses what are termed "Pipes" which can be considered as pipelines within the specified channel and this arrangement means that up to 6 modules, via separate pipes, can be listened to by a single master module on a single channel but, for the purposes of this tutorial we are only going to deal with single module to single module communication.

The Radio Frequency bit:

This section is going to get a bit "techy" so skip it if you like but, you never know, it may be of interest. I am trying to make this as understandable as possible and I have therefore taken some liberties with the descriptions to help with clarity. If you are a radio expert, please give me some slack. Radio Frequency or RF is an entire subject on its own but I thought it would be useful to cover the basics. All radio communication relies on the generation of an electromagnetic wave which is sent out from the transmitter and is received by the receiver. This is known as the carrier wave and it can be used to carry data in many ways.  The picture on the left shows  sine waves as they would appear on an oscilloscope. There are many waveform shapes but the purest is the sine wave. A sine wave is generated when a voltage rises and falls linearly over time so, for example, if I had a potentiometer fed with 5V and was able to accurately turn it from one end to the other and back again, the result would be something like a sign wave if I was able to capture the output on an oscilloscope.

The sine wave is not limited to radio by the way as discussed above and, for example, if you were to connect your home's AC wiring to an oscilloscope (DO NOT DO THIS!) you would see 50 or 60  of these waves occurring continuously every second (depending on where you live). If your home supply is DC (Direct Current) you wouldn't see anything I'm afraid.

The Amplitude of the signal would be 120 VAC, 220 VAC or whatever your mains voltage is. As the mains voltage of your home uses Alternating Current the signal will be alternating between 0 and maximum voltage. The waveform shown is a result of the voltage rising and falling over time so, in a UK home, the signal is completing one full cycle 50 times per second. In the old days we used to call this "cycles per second" whereas nowadays we use the term "Hertz" or Hz" which is the same thing. Therefore, in a UK home the mains frequency is 50 Hertz or Hz and in other parts of the world it could be 60 Hz

Alternating current in wiring produces electromagnetic waves as a result of the changing voltage but they are at such a low frequency that we don't really notice their effect. If you were able to increase the frequency of the supply in your home from 50 Hz to a much higher frequency such as 1 million Hz you would be able to hear it clearly on a radio receiver capable of tuning to that frequency.

Radio Frequency is just that i.e. electromagnetic waves created by rising and falling currents which can be received at a distance by a radio receiver. We can't use wiring such as that in your home to transmit RF waves as this would be incredibly inefficient and would fail on so many levels so the solution is to create the electromagnetic waves in an antenna or aerial. In its simplest form an antenna can be a piece of wire on which we create an rising and falling current. If we choose the correct length of wire the maximum amount of electromagnetic output is radiated and will therefore travel the greatest distance. This brings us into the area of wavelength.

The wavelength of an electromagnetic wave is the distance that a single cycle of a wave travels in one second and the length of an antenna, in simple terms, would equal the wavelength of the wave. For example, the ideal situation would be where a current applied to the end of an antenna would complete one cycle (rise to maximum and return to zero) by the time the wave reached the end of the antenna thus producing the maximum possible electromagnetic wave output. If the antenna is too short or too long, the electromagnetic wave produced will not carry the full power applied.

The wavelength of an electromagnetic wave is determined by the frequency of the radio signal and the speed of light. If you want to know the wavelength of a radio signal you have to do a simple bit of mathematics to work out how far a wave would travel in one second. We know that electromagnetic waves travel at the speed of light so:.

wavelength in metres = speed of light in metres/frequency in Hz. The speed of light is defined as 299,792,458 metres per second but for simplicity this is usually rounded up to 300,000,000 metres per second so, lets take the frequency of our home mains supply and see how long an antenna we would need to radiate the maximum RF output.

 

300,000,000 metres per second

 = 6000,000 metres or 6000 Km
50 Hz

So, from the above we can see that we would need an antenna 6000 Km long! Of course, we are not going to do this as nothing practical would be forthcoming but, I hope you get the idea. Elsewhere in these tutorials I cover MSF time transmissions from Anthorn in Cumbria in the UK so let's look at the antenna needed for this radio signal which is transmitted at 60 KHz or 60,000 Hz.

 

300,000,000 metres per second

 = 5,000 metres or 5 Km
60000 Hz

That's a bit better but do they really have an antenna 5 Km long? Well no, they don't because it is possible to use shorter antennas or designs to achieve high RF output with shorter antenna lengths. For example, it is possible to use an antenna which is half (half wave) or even a quarter (quarter wave) the length of the ideal length and special types of antenna can reduce significantly the space need to house the antenna by folding them etc .

Let's look at the antenna required for an nRF24L01 module using the same equation as above (remember the frequency is ~2.4GHz).

 

300,000,000 metres per second

 = 0.125 metres or 125 mm
2400,000,000 Hz

The ideal antenna length is 125 mm but this is still longer than the antenna on the nRF24L01 module isn't it? Yes it is so, the designers opted for an antenna that is nearer to a quarter wave antenna which would be 31.25 mm long. If you measure the length of the convoluted antenna on the module you will find that it is close to the quarter wave length. There's more to it than that I'm afraid as the module's antenna is a specialist type called a "Folded Inverted F" antenna which is an area I don't want to get into in this tutorial. Just let me say that the copper on the back of the module's PCB is just as important in RF terms as the visible antenna on the component side! The module design is a compromise between physical size and performance.

Modulation:

Carrier waves don't contain any data or other information. They are simply a constant electromagnetic wave so we need to add to this to send our data. In the early days of radio signals were sent by pressing a switch which caused a huge spark to jump a gap on the transmitter which in turn sent out electromagnetic waves. These transmitters didn't have a frequency as they splattered across a huge range of frequencies at the same time. The switch became a Morse Key as Morse was the code used to send messages at that time. Pretty quickly proper RF transmitters appeared which sent signals on a specific frequency and radio as we know it today was born.

It isn't practical, with a few exceptions, to constantly transmit a carrier wave and just interrupt it when we want to send a message so Morse code was sent by using the Morse Key to switch the carrier wave on in short bursts, short for a "Dot" and longer for a "Dash". this allows others to use the same frequency when we are not using it. Pretty soon it was realised that audio data could be sent via radio and AM was born. AM (Amplitude Modulation) is a form of transmission where the carrier wave is "modulated" by altering the amplitude of the carrier wave with the level of the audio signal. This method of transmission is still in use today although FM (Frequency Modulation) is a more modern method of transmitting audio and other data by shifting the frequency of the carrier wave with the audio modulation.

The MSF transmitter, and other similar transmitters do use a constant carrier wave which is turned off when data is sent.

Modern DAB (Digital Audio Broadcasting) is also becoming more popular and it sends its data in digital packets using another from of modulation similar to our next subject. FSK (Frequency Shift Keying) is a method of sending digital data (binary 1s and 0s) in a similar way to that originally used in Morse code. Instead of turning the carrier wave on and off, FSK switches the carrier wave on at the start of the transmission and then shifts the frequency of the carrier wave in accordance with the data bits being sent. Using FSK allows for more than just 1s and 0s to be sent as different shifts in the carrier wave frequency can be decoded differently.

The nRF24L01 uses a form of FSK and sends its data in bursts or "packets" which are received by the receiver and decoded. This enables us to gather all our data together and send it in one go which is much more efficient. In more sophisticated systems, the receiver can reconstruct the packetised data even if it gets out of synchronisation by requesting that lost packets be re-transmitted. Unfortunately, it takes some serious software to do this and it is not within the scope of this tutorial.

The last fact that you need to know and understand is that the higher the frequency of a radio transmission, the more care is needed to receive it. The term "line of sight" really comes into play at higher frequencies as the signal is more prone to all sorts of interaction with buildings and other objects. Very low frequency transmissions such as the MSF transmitter in Cumbria, UK will go through almost anything. The signal from your nRF24L01 module will not. Transmission power is also a major factor but we'll get on to that later.

Had enough? Let's move on to Part 2...