Introduction

ESP8266 & NR24L01

Having two or more MCU boards be able to communicate with each other wirelessly over a distance opens lots of possibilities like remotely monitoring sensor data, controlling robots, home automation and the list goes on. And when it comes down to having inexpensive yet reliable 2-way RF solutions, no one does a better job than nRF24L01+ transceiver module from Nordic Semiconductor.nRF24L01+ (plus) transceiver module can often be obtained online for less than two dollars, making it one of the most inexpensive data communication options that you can get. And best of all, these modules are super tiny, allowing you to incorporate a wireless interface into almost any project. I will also post some tutorial links where I have interfaced NRF24L01 with other microcontrollers. If you have any queries about it, ask in the comments and I will resolve it.

This article uses Platformio as ide and C -code for programming.

Hardware Introduction

ESP8266 MODULE

Espressif’s ESP8266EX delivers a highly integrated Wi-Fi SoC solution to meet users’ continuous demands for efficient power usage, compact design and reliable performance in the Internet of Things industry. 

With the complete and self-contained Wi-Fi networking capabilities, ESP8266EX can perform either as a standalone application or as the slave to a host MCU. When ESP8266EX hosts the application, it promptly boots up from the flash. The integrated high speed cache helps to increase the system performance and optimize the system memory. Also, ESP8266EX can be applied to any microcontroller design as a Wi-Fi adapter through SPI/SDIO or UART interfaces. 

ESP8266EX integrates antenna switches, RF balun, power amplifier, low noise receive amplifier, filters and power management modules. The compact design minimizes the PCB size and requires minimal external circuitries. 

Besides the Wi-Fi functionalities, ESP8266EX also integrates an enhanced version of Tensilica’s L106 Diamond series 32-bit processor and on-chip SRAM. It can be interfaced with external sensors and other devices through the GPIOs. Software Development Kit (SDK) provides sample codes for various applications. 

Espressif Systems’ Smart Connectivity Platform (ESCP) enables sophisticated features including:

  • Fast switch between sleep and wakeup mode for energy-efficient purpose.
  • Adaptive radio biasing for low-power operation.
  • Advance signal processing.
  • Spur cancellation and RF coexistence mechanisms for common cellular, Bluetooth, DDR, LVDS, LCD interference mitigation.
Sơ đồ chân ESP8266 - Nên sử dụng chân nào

Features

Graphical user interface, application

Description automatically generated

ESP8266 Processor

The ESP8266EX integrates a Tensilica L106 32-bit RISC processor, which achieves extra low power consumption and reaches a maximum clock speed of 160 MHz. The Real-Time

Operating System (RTOS) and Wi-Fi stack allow 80% of the processing power to be

available for user application programming and development. The CPU includes the

interfaces as below:

• Programmable RAM/ROM interfaces (iBus), which can be connected with memory

controller, and can also be used to visit flash.

• Data RAM interface (dBus), which can be connected with a memory controller.

• AHB interface which can be used to visit the register. 

Memory

ESP8266EX Wi-Fi SoC integrated memory controller and memory units including SRAMand ROM. MCU can access the memory units through iBus, dBus, and AHB interfaces. All Memory units can be accessed upon request, while a memory arbiter will decide the running sequence according to the time when these requests are received by the

processor. 

Power

ESP8266EX is designed with advanced power management technologies and intended for mobile devices, wearable electronics and the Internet of Things applications. The low-power architecture operates in the following modes:

 • Active mode: The chip radio is powered on. The chip can receive, transmit, or listen. 

• Modem-sleep mode: The CPU is operational. The Wi-Fi and radio are disabled. • Light-sleep mode: The CPU and all peripherals are paused. Any wake-up events (MAC, host, RTC timer, or external interrupts) will wake up the chip.

 • Deep-sleep mode: Only the RTC is operational and all other parts of the chip are powered off.

ESP8266 Analog Pin Description

NRF24L01

NRF24L01 (Sensor Description) 

NRF24L01 is a single chip radio transceiver for the world wide 2.4 – 2.5 GHz ISM band. The transceiver consists of a fully integrated frequency synthesizer, a power amplifier, a crystal oscillator, a demodulator, modulator and Enhanced ShockBurst™ protocol engine. Output power, frequency channels, and protocol setup are easily programmable through a SPI interface. Current consumption is very low, only 9.0mA at an output power of -6dBm and 12.3mA in RX mode. Built-in Power Down and Standby modes makes power saving easily realizable. 

NRF24L01 specification:

Features of the nRF24L01 include: 

• Radio X Worldwide 2.4GHz ISM band operation 

  • 126 RF channels 
  • Common RX and TX pins 
  • GFSK modulation 
  • 1 and 2Mbps air data rate 
  • 1MHz non-overlapping channel spacing at 1Mbps 
  • 2MHz non-overlapping channel spacing at 2Mbps

• Transmitter 

  • Programmable output power: 0, -6, -12 or -18dBm 
  • 11.3mA at 0dBm output power

• Receiver 

  • Integrated channel filters 
  • 12.3mA at 2Mbps 
  •  -82dBm sensitivity at 2Mbps
  • -85dBm sensitivity at 1Mbps 
  • Programmable LNA gain 

• Power Management 

  • Integrated voltage regulator 
  • 1.9 to 3.6V supply range 
  • Idle modes with fast start-up times for advanced power management 
  • 22uA Standby-I mode, 900nA power down mode 
  • Max 1.5ms start-up from power down mode 
  • Max 130us start-up from standby-I mode 

• RF Synthesizer 

  • Fully integrated synthesizer 
  • No external loop filter, VCO varactor diode or resonator 
  •  Accepts low cost ±60ppm 16MHz crystal

• Enhanced ShockBurst™ 

  • 1 to 32 bytes dynamic payload length 
  • Automatic packet handling 
  • Auto packet transaction handling 
  • 6 data pipe MultiCeiver™ for 1:6 star networks

Enhanced ShockBurst™ uses ShockBurst™ for automatic packet handling and timing. During transmit, ShockBurst™ assembles the packet and clocks the bits in the data packet into the transmitter for transmission. During receive, ShockBurst™ constantly searches for a valid address in the demodulated signal.

When ShockBurst™ finds a valid address, it processes the rest of the packet and validates it by CRC. If the packet is valid the payload is moved into the RX FIFO. The high speed bit handling and timing is controlled by ShockBurst™.

Enhanced ShockBurst™ features automatic packet transaction handling that enables the implementation of a reliable bi-directional data link. An Enhanced ShockBurst™ packet transaction is a packet exchange between two transceivers, where one transceiver is the Primary Receiver (PRX) and the other is the Primary Transmitter (PTX). An Enhanced ShockBurst™ packet transaction is always initiated by a packet transmission from the PTX, the transaction is complete when the PTX has received an acknowledgment packet(ACK packet) from the PRX.

GND is the Ground Pin. It is usually marked by encasing the pin in a square so it can be used as a reference for identifying the other pins.

VCC supplies power for the module. This can be anywhere from 1.9 to 3.9 volts. You can connect it to 3.3V output from your Arduino. Remember connecting it to a 5V pin will likely destroy your nRF24L01+ module!

CE (Chip Enable) is an active-HIGH pin. When selected the nRF24L01 will either transmit or receive, depending upon which mode it is currently in.

CSN (Chip Select Not) is an active-LOW pin and is normally kept HIGH. When this pin goes low, the nRF24L01 begins listening on its SPI port for data and processes it accordingly.

SCK (Serial Clock) accepts clock pulses provided by the SPI bus Master.

MOSI (Master Out Slave In) is SPI input to the nRF24L01.

MISO (Master In Slave Out) is SPI output from the nRF24L01.

IRQ is an interrupt pin that can alert the master when new data is available to process.

Power Consumption

PTX operation

You activate PTX mode by setting the CE pin high. If there is a packet present in the TX FIFO the nRF24L01 enters TX mode and transmits the packet. If Auto Retransmit is enabled, the state machine checks if the NO_ACK flag is set. If it is not set, the nRF24L01 enters RX mode to receive an ACK packet. If the received ACK packet is empty, only the TX_DS IRQ is asserted. If the ACK packet contains a payload, both TX_DS IRQ and RX_DR IRQ are asserted simultaneously before nRF24L01 returns to standby-I mode.

If the ACK packet is not received before timeout occurs, the nRF24L01 returns to standby-I mode. It stays in standby-I mode until the ARD has elapsed. If the number of retransmits has not reached the ARC, the nRF24L01 enters TX mode and transmits the last packet once more.

While executing the Auto Retransmit feature, the number of retransmits can reach the maximum number defined in ARC. If this happens, the nRF24L01 asserts the MAX_RT IRQ and returns to standby-I mode.

If the CE is high and the TX FIFO is empty, the nRF24L01 enters Standby-II mode.

PRX Operation:

You activate PRX mode by setting the CE pin high. The nRF24L01 enters RX mode and starts searching for packets. If a packet is received and Auto Acknowledgement is enabled the nRF24L01 decides if this is a new packet or a copy of a previously received packet. If the packet is new the payload is made available in the RX FIFO and the RX_DR IRQ is asserted. If the last received packet from the transmitter is acknowledged with an ACK packet with payload, the TX_DS IRQ indicates that the PTX received the ACK packet.with payload. If the No_ACK flag is not set in the received packet, the PRX enters TX mode. If there is a pending payload in the TX FIFO it is attached to the ACK packet. After the ACK packet is transmitted, the nRF24L01 returns to RX mode.

A copy of a previously received packet might be received if the ACK packet is lost. In this case, the PRX discards the received packet and transmits an ACK packet before it returns to RX mode.

Function:

Multiceiver:

Multiceiver is a feature used in RX mode that contains a set of 6 parallel data pipes with unique addresses. A data pipe is a logical channel in the physical RF channel. Each data pipe has its own physical address decoding in the nRF24L01.

nRF24L01 configured as PRX (primary receiver) can receive data addressed to six different data pipes in one frequency channel.Each data pipe has its own unique address and can be configured for individual behavior.Up to six nRF24L01s configured as PTX can communicate with one nRF24L01 configured as PRX. All data pipe addresses are searched for simultaneously. Only one data pipe can receive a packet at a time. All data pipes can perform Enhanced ShockBurst™ functionality

Auto Acknowledgement

Auto acknowledgment is a function that automatically transmits an ACK packet to the PTX after it has received and validated a packet. The auto acknowledgement function reduces the load of the system MCU and can remove the need for dedicated SPI hardware. This also reduces cost and average current consumption. The Auto Acknowledgement feature is enabled by setting the EN_AA register.

Auto Retransmission (ART)

The auto retransmission is a function that retransmits a packet if an ACK packet is not received. It is used at the PTX side in an auto acknowledgement system. You can set up the number of times a packet is allowed to be retransmitted if a packet is not acknowledged with the ARC bits in the SETUP_RETR register.

PTX enters RX mode and waits a time period for an ACK packet each time a packet is transmitted.

NRF24L01+

NRF24L01 comes in an advanced version. It is  2.4GHz NRF24L01+PA+LNA SMA Wireless Transceiver Antenna.This board features a reverse polarized SMA connector for maximum RF range. And there is PA and LNA circuit on board, with the external antenna it can reach a longer distance than the one without these parts.This module comes with the 2.4G antenna (2DB), with a 250Kbps transmission rate on open-air it can reach the 800-1K meters communication distance.

Its features are :

  • Voltage: 3-3.6V (recommended 3.3V) V.
  • Maximum output power: +20dBm.
  • Power-down mode current: 4.2uA.
  • Operating Range: 1Km
  • Antenna Gain (peak): 2Dbi.
  • 2MB rate (Open area): 520m.
  • 1MB rate (Open area): 750m.
  • 250Kb rate (Open area): 1100m.
  • It uses 2.4GHz global open ISM band, with license free.
  • Facilitate the development for customers, without development RF part.
  • Low cost: integrated with high-speed signal processing parts associated with RF protocol, such as: automatically resend lost packets and generate acknowledge signal;

Package Includes :

  • 1 x 2.4GHz NRF24L01 Transceiver module.
  • 1 x SMA Antenna

Specification:

 

Schematic Diagram

Pin Connection Table

Source Code

FOR TRANSMITTER

#include <SPI.h> 
#include "nRF24L01.h" 
#include "RF24.h" 
#include <Arduino.h>
char msg[6] = "hello"; 
RF24 radio(4,2,7,6,5); 
const uint64_t pipe = 0xE8E8F0F0E1LL; 
void setup(void) { 
Serial.begin(115200); 
radio.begin(); 
radio.setChannel(2); 
radio.setPayloadSize(7); 
radio.setDataRate(RF24_250KBPS); 
radio.openWritingPipe(pipe); 
} 
void loop(void) { 
Serial.println("send ..."); 
radio.write(msg, 6);
delay(3000); 
} 

Code explanation

#include <SPI.h> 
#include "nRF24L01.h" 
#include "RF24.h" 
#include <Arduino.h>
char msg[6] = "hello";

Include the library SPI.H, nRF24L01.h, RF24.h,Arduino.h

We are considering a message “Hello”

RF24 radio(4,2,7,6,5); 
const uint64_t pipe = 0xE8E8F0F0E1LL;

An RF module (short for radio-frequency module) is a (usually) small electronic device used to transmit and/or receive radio signals between two devices. In an embedded system it is often desirable to communicate with another device wirelessly. This wireless communication may be accomplished through optical communication or through radio-frequency (RF) communication. 

Creating an instance. 

const uint64_t pipe = 0xE8E8F0F0E1LL;

it’s the password between the devices, and it has to be the same in both codes.

void setup(void) { 
Serial.begin(115200); 
radio.begin(); 
radio.setChannel(2); 
radio.setPayloadSize(7); 
radio.setDataRate(RF24_250KBPS); 
radio.openWritingPipe(pipe); 

Opens serial port, sets data rate to115200 bps 

radio.begin() starts the wireless communication 

To start, initialize the radio and set its channel. The function, radio.setChannel() sets what frequency the master and slave will talk to each other. This needs to be the same on both devices for them to correctly talk to each other. Setting the payload size to the needed value radio 

set RF data rate – lowest rate for longest range capability.

void loop(void) { 
Serial.println("send ..."); 
radio.write(msg, 6);
delay(3000); 
} 

The last setup step is to open a writing pipe for the NRF module. Then at last we are sending the message and giving the delay as 3000.

FOR RECEIVER 

#include <SPI.h> 
#include "nRF24L01.h" 
#include "RF24.h"
#include <Arduino.h>
char msg[6]; 
RF24 radio(4,2); 
const uint64_t pipe = 0xE8E8F0F0E1LL; 
void setup(void){ 
Serial.begin(115200); 
radio.begin(); 
radio.setChannel(2); 
radio.setPayloadSize(7); 
radio.setDataRate(RF24_250KBPS); 
radio.openReadingPipe(1,pipe); 
radio.startListening(); 
} 
void loop(void){ 
if (radio.available()){ 
radio.read(msg, 6); 
Serial.println(msg);
delay(10); 
} 
else{ 
//Serial.println("No radio available"); 
} 
} 

Code explanation

#include <SPI.h> 
#include "nRF24L01.h" 
#include "RF24.h"
#include <Arduino.h>

Include the library SPI.H, nRF24L01.h, RF24.h,Arduino.h

char msg[6]; 
RF24 radio(4,2); 
const uint64_t pipe = 0xE8E8F0F0E1LL;

We are considering a character of length 6.

Creating an instance. 

An RF module (short for radio-frequency module) is a (usually) small electronic device used to transmit and/or receive radio signals between two devices. In an embedded system it is often desirable to communicate with another device wirelessly. This wireless communication may be accomplished through optical communication or through radio-frequency (RF) communication. 

const uint64_t pipe = 0xE8E8F0F0E1LL;

it’s the password between the devices, and it has to be the same in both codes. 

void setup(void){ 
Serial.begin(115200); 
radio.begin(); 
radio.setChannel(2); 
radio.setPayloadSize(7); 
radio.setDataRate(RF24_250KBPS); 
radio.openReadingPipe(1,pipe); 
radio.startListening(); 
} 

Opens serial port, sets data rate to115200 bps 

radio.begin() starts the wireless communication 

To start, initialize the radio and set its channel. The function, radio.setChannel() sets what frequency the master and slave will talk to each other. This needs to be the same on both devices for them to correctly talk to each other. Setting the payload size to the needed value radio 

set RF data rate – lowest rate for longest range capability. 

void loop(void){ 
if (radio.available()){ 
radio.read(msg, 6); 
Serial.println(msg);
delay(10); 
} 
else{ 
//Serial.println("No radio available"); 
} 
} 

The last setup step is to open a writing pipe for the NRF module. radio.startListening set the module as receiver. 

Then we add a loop which checks radio.available(), If it’s available then read it and display that its available else print its not available.

Github-link

https://github.com/iottrends/iottrends/tree/main/NRF24L01

0 0 votes
Article Rating
Previous articleHow to Interface Raspberry Pi Zero with GPS | SparkFun SAM-M8Q
Next articleHow to Interface Raspberry Pi Pico with NRF24L01
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments