This is a Getting Started tutorial, that provides the reader with a broad overview on how to get a project working using the popular NRF24L01+ modules. In this project the user will set up two communication nodes. The “sender” node increments an internal counter and transmits this to the “receiver”. The counter signal is just an example and can easily be replaced with a more useful signal, such a sensor signal or otherwise. The receiver node waits to get the signal and once received displays it on the LCD. Before continuing to the next increment of the counter, the sender node waits to get an acknowledgment from the receiver to ensure the transmission was successful.
This tutorial is set up to utilize some of the features of the NRF-Shield and how they can be utilized. In that spirit, two different Arduino microcontrollers, two different NRF24L01+ versions, two different hardware selection pin configurations, and finally two different ways to power the RF communication modules are employed. With all these complementary differences, the flexibility of the NRF-Shield is explored. The user may wish to simplify this arrangement as they see fit, by reducing these various differences. Furthermore, in terms of advanced RF communication concepts the script is kept as simple as possible. There are many advanced concepts of RF communication that are not covered in this tutorial.
The following hardware is the minimum required to get two NRF24L01+ modules talking to each other:
- 1x PTSolns Prototype PCB Microcontroller Shield for Arduino Uno (NRF-Shield Deluxe)
o This package includes two NRF-Shields and extra hardware required for assembling the shields as
used in this tutorial. Soldering is required.
- 2x Arduino microcontroller (Uno R3, Mega, Leonardo or Due)
o The NRF-Shield is compatible with all of the mentioned Arduino microcontrollers. In this tutorial one Uno and one Mega are used.
- 2x NRF24L01+ transceiver (Mini, Standard, +PA+LNA)
o In this tutorial one Standard-sized NRF24L01+ and one NRF24L01+PA+LNA is used. However, any of these three transceivers as shown in Fig. 1 would work for this tutorial.
- 1x LCD with I2C ‘backpack’ module
- 4x Male-to-female dupont wires
- Benchtop power supply, or equivalent
The Arduino IDE software is required. This can be downloaded freely. Once this software is installed, there are some sub-steps the user may, or may not, have to do in order to get the software setup correct. These steps are as follows:
- Depending on which FTDI USB to TTL serial converter module is used, a special driver, such as the CH340 driver, might have to be installed. This is a well-documented driver for which there are many tutorials available. The tutorial we recommend is called “Tutorial: First time using the Nano Microcontroller” by PTSolns. However, if genuine Arduino microcontrollers are used no special driver will be required.
- The script shown in Section 5 below requires some libraries to be installed within the IDE software. Open Tools\Manage Libraries … and search for and install the following: “LiquidCrystal_I2C”, “RF24”, “SPI”.
Setting Up The Hardware
In this section the sender and receiver nodes are assembled. As mentioned above, the two nodes are set up differently in some key aspect in order to highlight particular features of the NRF-Shield. However, the user may wish to alter this setup as they see fit. The final product as will be done in this tutorial should look like similar to what is shown in Fig. 2.
The sender and receiver nodes are discussed in the following subsections. The hardware required to assemble these boards is included in the Deluxe package, excluding the RF modules, wires and the LCD.
The sender node is shown in Fig. 3. It can be seen that the standard sized NRF24L01+ is used, along with the Arduino Mega. Assembly of the receiver is straight-forward. A 2X4 pin female header is soldered into the “NRF Interface” footprint. The standard sized NRF24L01+ is connected into this female header.
Next, a 1X15 pin male header is soldered along the hardware selection pins. 2-pin jumper caps are placed on the following selections: 3V3, D9, D7, and D3. The 3V3 selection is to use the onboard 3.3V supply to power the module. D7 and D9 will be used in the corresponding script. D3, the interrupt pin, is not used in this tutorial.
Finally, header pins connecting the NRF-Shield to the Arduino are standard male headers. Although the shield is fully stackable, it is not recommended to do so. RF communication works best with least obstruction to the antenna. Note here a 1X15 Pin male header was used between the 1X8 pin and 1X6 pin header footprints of the Arduino, with the 9th pin pulled out after soldering the row into place. TIP: place the male headers into the Arduino before soldering to ensure the rows are parallel and the shield fits well.
The receiver node is shown in Fig 4. It can be seen that the larger sized NRF24L01+PA+LNA is used, along with the Arduino Uno R3. There is slightly more assembly on this node, but there is lots of overlap to the sender node. The user should reproduce all the solder joints done as on the sender node.
Regarding the NRF module, the one used on the receiver node has a long PCB and a large antenna. If the RF module does not already have this, the user should solder 1X2 pin male headers onto the RF module on either side of the antenna footprint. In the corresponding footprint on the NRF-Shield, the user should solder 1X2 pin female header. TIP: It is easiest to first put into place these small headers and then soldering them. Although adding these 1X2 pin headers is not required, it is strong recommended as they add structural support for the RF module.
For the hardware selection pins, the following are set: VR, D10, D8, D2. The VR selection is to use the external voltage supply to power the module. This requires the user to install a 3.3V voltage regulator and two smoothing capacitors (these components are included in the Deluxe package). Note that the footprint for the voltage regulator is designed such that any permutation of the Vin, Vout, GND pins are accepted. This is useful in case the user wants to use a different regulator that has a different pinout configuration. It is generally a good idea to use the VR selection with the external voltage regulator when operating the RF module on max power (set in the script), as the NRF24L01+PA+LNA may draw too much current under certain situations that can result in unstable communication. As with the sender node, the receiver node does not utilize the interrupt pin (D2 in this case).
Finally, the user should solder a 4-pin screw terminal (included in the Deluxe package) on the I2C footprint #3 and connect the LCD. Note that the LCD is interfaced by the use of the “backpack”, which allows the LCD to be connected only by four wires through the I2C bus and power. Most LCD modules come with this backpack already installed.
Setting Up The Software
The scripts for the sender and receiver in this tutorial have been reduced to the bare minimum. This is to keep the coding as simple as possible and get started as quickly as possible. However, the user is reminded that many of the details relating to the operation of RF modules are omitted.
The sender and receiver scripts are outlined below. Both the sender and receiver parts are contained in the same script. When uploading the sender side simply uncomment the line #define COMPILE_TX, and comment out the line #define COMPILE_RX and vice versa when uploading the receiver side. Further note that in this tutorial two different Arduino microcontrollers are used and hence the corresponding selection has to be made in the IDE software.
Please see the following download to get the INO file for Arduino IDE.
Notice in the script on lines 17 and 21 the CE and CSN pins are selected as they correspond to the respective hardware selection that was done in Section 4. Being able to select between different CE and CSN pins (as well as the interrupt, which is not used in this tutorial) is quite useful. Such as, for example, if a different part of the project/stack uses a pin that would otherwise have been required by the RF module had the hardware selection pins not been available on the board.
Results And Conclusion
With both the sender and the receiver scripts successfully uploaded, the communication between the nodes should be established. To see the results, the receiver microcontroller should be plugged in to the computer running the Arduino IDE via the USB, and the IDE Monitor opened (“Tools\Serial Monitor”). The Serial.print command will write the output to the IDE Monitor. If all is successful the monitor should print out an integer that increments every two seconds, similar to what is shown in 5.
Furthermore, the LCD should be displaying the incremented counter, updating approximately every second. The LCD printout can be seen in Figure 6.
This tutorial showed highlighted of the features of the NRF-Shield. Most notably these include:
- Ability to interface three common sizes of the NRF24L01+ RF module.
- Ability to change hardware pins, which is reflected in the corresponding script.
- Ability to power the RF module with two different methods.
- Compatibility with a range of Arduino microcontrollers.
“RF is hard.” – D. Cornish
The following are suggestions for troubleshooting. There are several things that can go wrong, or might prevent the project from working as intended. This is true for any electronic DYI project, but particularly so when dealing with RF devices.
If code is not uploading
- Try changing the USB cable.
- Ensure proper port within IDE is selected.
- Try loading a generic example (e.g. “Hello World”) that came with IDE installation. Ensure that the generic example is working before moving on. For this, disconnect all LoRa connections, so that you can ensure the programmer and microcontroller has not defective.
- In the IDE software, under File\Preferences enable “Show verbose output during:” on “compilation” and “upload”. Read the output upon trying to upload the script. You can copy and paste parts of the output and search online in forums. More than likely the issue has been covered extensively online.
If hardware is not working
- Ensure that the sender node has the correct corresponding script loaded by uncommenting line 7 and commenting line 8. Vice versa for the receiver node.
- Using a multimeter on DC voltage setting, ensure that VCC to GND reads correct values.
- Disconnect power. Using a multimeter on conductivity setting, check all connections between all components.
- Ensure the hardware selection pins for the sender and receiver node are exactly as set in the corresponding scripts.
- Throughout the script place output snippets to help debug. Something similar to: Serial.println(“goto x”); where x is a number you change so you know what code has been excluded.