Interfeacing NRF24L01 with Arduino Pro Mini

Good Day Everyone,

I was using NRF24L01 with two Nodemcu's one of which was acting as transmitter and other was receiver for two way communication. Communication was successfully achieved and all the data was transmitted and received.

But due to size problem I moved to Arduino Mini on Transmitter side. I changed the Pin Numbers according to arduino Mini Configuration But result is very different.

Actually Transmitter is sending Two vales one is fixed etc. 2, and other is button state. When I checked on the receiver side only fixed value is receiving and when I pressed button on Transmitter side the fixed vales is changing from 2 to 6553 instead of changing from 0 to 1.

I also tested by transmitting 1 value from tramitter to receiver. It was successful but whenever I moved to two vales then above problem happens.

Without seeing your code (for both Tx and Rx) and your Pro Mini wiring diagram it is difficult to comment.

If this was my problem I would try the connection test program from this Simple nRF24L01+ Tutorial on the Pro Mini.

Another thing is to be sure the nRF24 has a good 3.3v power supply. A pair of AA alkaline cells (3v) is good for testing - with the battery GND connected to the Arduino GND.

...R

Here Is the Code for Transmitter (Arduino Pro Mini) and It is programming through Arduino UNO. Wriring Diagrams is as follows. And you can check the values in the picture. In the transmitter side these are good.
Arduino Mini Arduino UNO

Tx Tx
Rx Rx
5v VCC
GND GND
Reset Reset NRF 24L01

9 CE
10 CSN
11 MOSI
12 MISO
13 SCK
VCC 3.3V
GND GND

/*
2.* 
3.*  - Transmitter Code
4.*Wiring Diagram
5.* 
6.*
7.* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
8.*/
/*
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9, 10); // CE, CSN
const byte address[6] = "00001";
void setup() {
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_MIN);
radio.startListening();
}
void loop() {
if (radio.available()) {
char text[32] = "";
radio.read(&text, sizeof(text));
Serial.println(text);
}
}
*/

/*
2.* Arduino Wireless Communication Tutorial
3.* Example 1 - Transmitter Code
4.*
5.* by Dejan Nedelkovski, www.HowToMechatronics.com
6.*
7.* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
8.*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9, 10); // CE, CSN

const byte address[6] = "00001";
const int buttonPin = A1;
//boolean buttonState = 0;

struct dataStruct {
  int seat_value; 
   // int Seat_Value_1;   
     // int button_pin = D0;
    boolean buttonState = 0;
  } myData;
void setup() {
  Serial.begin(9600);
  
  pinMode(buttonPin, INPUT);
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
}
void loop() {
myData.buttonState = digitalRead(buttonPin);
myData.seat_value = 2;
radio.write(&myData, sizeof(myData));
Serial.println(myData.buttonState);
Serial.println(myData.seat_value);
delay(1000);
}

Here Is the Code for Receiver (Nodemcu) and Wriring Diagrams is as follows. And you can check the values in the picture. In the receiver side these are different from receiver, you can check in the image attached to it.
Nodemcu NRF 24L01

D4 CE
D2 CSN
D7 MOSI
D6 MISO
D5 SCK
3.3v 3.3V
GND GND

/*
 Transmitter Code
4.*
.*
7.* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
8.*/
/*
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(D4, D2); // CE, CSN
const byte address[6] = "00001";
void setup() {
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
}
void loop() {
const char text[] = "Hello World";
radio.write(&text, sizeof(text));
delay(1000);
}
*/
/*
2.* Arduino Wireless Communication Tutorial
3.* Example 1 - Receiver Code
4.*
5.* by Dejan Nedelkovski, www.HowToMechatronics.com
6.*
7.* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
8.*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(D4, D2); // CE, CSN

const byte address[6] = "00001";
const int ledPin =  D1; 
const int ledPin1 =  D8; 
//boolean buttonState = 0;
struct dataStruct {
  int seat_value; 
   // int Seat_Value_1;   
     // int button_pin = D0;
    boolean buttonState = 0;
  } myData;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(ledPin1, OUTPUT);
radio.begin();
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_MIN);
radio.startListening();
}
void loop() {
if (radio.available()) {
char text[32] = "";
radio.read(&myData, sizeof(myData));
Serial.println(myData.seat_value);
Serial.println(myData.buttonState);
if (myData.buttonState == HIGH){
//digitalWrite(ledPin, HIGH);
digitalWrite(ledPin1, LOW);
//digitalWrite(ledPin1, LOW);
}
else {
//digitalWrite(ledPin, LOW);
digitalWrite(ledPin1, HIGH);
//digitalWrite(ledPin1, HIGH);
}
/*
if (myData.seat_value == HIGH){
digitalWrite(ledPin, HIGH);
//digitalWrite(ledPin1, LOW);
//digitalWrite(ledPin1, LOW);
}
else {
digitalWrite(ledPin, LOW);
//digitalWrite(ledPin1, HIGH);
//digitalWrite(ledPin1, HIGH);
}
*/
}
}

Actually, single data is transmitted and received successfully, but when i try to transmit multiple data, then only one value is received on the receiver side and when i pressed push button on transmitter side, other fixed value getting change instead of changing the value of push button.
But it was not happening when I uploaded same program on Nodemcu

What is sizeof(int) on Pro Mini vs Nodemcu? How is the struct packed on Pro Mini vs Nodemcu? What is sizeof() resulting struct on Pro Mini vs Nodemcu? Is Endianness the same? Did you compare number of bytes sent vs number of bytes received?

gfvalvo:
I did not check the size, but i was sending only fixed digit "2" and Push Button state.

Try answering what was asked.

gfvalvo:
I Checked and successfully resolved this issue.
But arduino Mini works on 5V. is this may cause any disturbance ?

Did you consult the NRF24L01 data sheet? It has 5V tolerant digital inputs. Please post your solution so other people who may encounter the same problem can benefit from the advice.

aarg:
Yeah they are 5V tolerant. But for one way communication 5v are good. But when I started Two way communication It stopped and then I powered arduino Mini from 3.3v pin of UNO then communication is satisfactory but LED on Arduino Mini can Not sustain its ON state

I used short int instead of int in construct and it resolved the communication problem

struct dataStruct {
 short int seat_value;
   // int Seat_Value_1;   
     // int button_pin = D0;
   short int buttonState = 0;
  } myData;

engr_khalil:
Yeah they are 5V tolerant. But for one way communication 5v are good. But when I started Two way communication It stopped and then I powered arduino Mini from 3.3v pin of UNO then communication is satisfactory but LED on Arduino Mini can Not sustain its ON state

That does not make sense.

An nRF24 must be powered with not more than 3.6v but you can connect 5v signals to its input pins. If it stopped communicating it had nothing to do with sending 5v signals from an Arduino.

A much more likely cause of the problem is not enough current for the nRF24 power - as I mentioned in Reply #1

...R

I again Counter checked. Arduino Mini send data when it is connected to 3.3V pin of UNO. When I connect it with 5V pin of UNO it stops sending even on serial monitor it stops showing the values.

Robin2:
That does not make sense.

Communication is another problem when I connect Arduino Pro MIni with 5v pin of Arduino UNO to power it. I checked on serial monitor of Arduino Pro Mini. It only show data 1 time and then stopped but on the same time when I connect with 3.3V Pin of Arduino UNO it is showing data on serial monitor and also sending data.
Note: It is 2-way communication.

Robin2:
and Also for one way communication it does not bother either for 5v or 3.3v, it works perfectly on both. Only problem when I try to have 2-way communication

engr_khalil:
I again Counter checked. Arduino Mini send data when it is connected to 3.3V pin of UNO. When I connect it with 5V pin of UNO it stops sending even on serial monitor it stops showing the values.

I cannot visualise what you are trying to describe here.

Please make two simple drawings that show all the connections for the working and the non-working cases and post photos of your drawings. See this Simple Image Posting Guide. Please DO NOT use Fritzing

...R

Good Day Every One.....

With Reference to the previous post. I stuck in 2-way communication between Arduino Pro Mini and Nodemcu. I tried a lot but no success. Also One way communication is successful. I try to change everything but did not get two way communication with success and unable to find the problem.

Note: This code is working nicely with Nodemcu to Nodemcu communication and also UNO to Nodemcu communication. And Also I tried many other programs by which One way communication is successful but I stuck when I go for two way communication and then Arduino Pro Mini can not receive data and shows "0" value on serial monitor. Arduino Pro Mini is programming and powering from UNO. Here is the Pin configuration,


Arduino Mini Arduino UNO

Tx Tx
Rx Rx
5v VCC
GND GND
Reset Reset NRF 24L01

9 CE
10 CSN
11 MOSI
12 MISO
13 SCK
VCC 3.3V
GND GND

Code For Arduino Mini

#include <SPI.h>
#include <RF24.h>
 
RF24 radio(9, 10); // CE, CSN
const byte addresses [][6] = {"00001", "00002"};
//byte addresses[][6] = {"1Node", "2Node"};
//const byte addresses[] = {"1Node"};
  int button_pin = A0;
   int led_pin2 = 2;
   int led_pin3 = 3;
 //  int Seat_Value1;
  short int seat_status;
 
struct dataStruct {
  int Seat_Value; 
   // int Seat_Value_1;   
     // int button_pin = D0;
    int Button_State;
  } myData;

  
 // struct dataStruct1 {
  //int Seat_numb; 
   // int Seat_Value1;   
     //int button_pin1 = D0;
    //int Button_State;
  //} myData1;
 
void setup() {
  Serial.begin(57600);
        pinMode(button_pin, INPUT);
      pinMode(led_pin2, OUTPUT);
      pinMode(led_pin3, OUTPUT);
  radio.begin();
  radio.setChannel(83);
  radio.setDataRate(RF24_250KBPS);
  radio.setPALevel(RF24_PA_LOW);
    //radio.openWritingPipe(addresses[0]);
    radio.openWritingPipe(addresses[1]);
  radio.openReadingPipe(1, addresses[0]);
  //radio.openWritingPipe(addresses[0]);
 // radio.openReadingPipe(pipe, addresses[1]);
  //radio.stopListening();
}
 
void loop() {
   radio.stopListening();
  int Seat_Value = 2;
  myData.Button_State = digitalRead(button_pin);
  myData.Seat_Value = Seat_Value;
  //myData.Button_State = Button_State;
  radio.write( &myData, sizeof(myData));
//radio.startListening();
//if (radio.available()){
//while(!radio.available());
//radio.read( &myData, sizeof(myData));  
  // if (myData.Seat_Value1 == 2)
   //         {
   //     digitalWrite(led_pin3, HIGH); 
   //     digitalWrite(led_pin2, LOW); 
//}
  //    else
   //   {
   //     digitalWrite(led_pin3, LOW);
   //     digitalWrite(led_pin2, HIGH);
    //  }
   // radio.startListening();
    delay(5);
    radio.startListening();
   //  if (radio.available()) {
   while (!radio.available())
   //{
         radio.read(&seat_status, sizeof(seat_status));
           Serial.println(seat_status);
            if (seat_status == 2)
    {
       digitalWrite(led_pin2, HIGH);
         digitalWrite(led_pin3, LOW);
    }
    else
    {
      digitalWrite(led_pin2, LOW);
        digitalWrite(led_pin3, HIGH);
    }
      //  radio.read( &myData1, sizeof(myData1));
        // radio.read(&mydata1, sizeof(mydata1));
   /*      if (myData1.Seat_Value1 == 2)
    {
       digitalWrite(led_pin2, LOW);
         digitalWrite(led_pin3, HIGH);
    }
    else
    {
      digitalWrite(led_pin2, HIGH);
        digitalWrite(led_pin3, LOW);
    } */

       /*     if (myData1.Button_State == HIGH)
            {
        digitalWrite(led_pin2, HIGH);
      }
      else
      {
        digitalWrite(led_pin2, LOW);
      }
            if (myData1.Seat_Value1 == 2)
            {
        digitalWrite(led_pin3, HIGH);
      }
      else
      {
        digitalWrite(led_pin3, LOW);
      } */
    //}
}
//}

Nodemcu NRF 24L01

D4 CE
D2 CSN
D7 MOSI
D6 MISO
D5 SCK
3.3v 3.3V
GND GND

Code for Nodemcu

#include <SPI.h>
#include <RF24.h>
//#include <Servo.h>
 
RF24 radio(D4, D2); // CE, CSN
const byte addresses [][6] = {"00001", "00002"};
//byte addresses[][6] = {"1Node", "2Node"};
//const byte addresses[] = "1Node";
//const byte pipe = 1;
  int button_pin1 = D0;
   int led_pin = D1;
   int led_pin1 = D8;
   int seat_status;
  // boolean button_state1 = 0;
struct dataStruct {
  int Seat_Value;  
  //int Seat_Value1;     
     // int button_pin = D0;
    int Button_State;
  //  byte led_pin;
 //   byte led_pin1;
  } myData;

 // struct dataStruct1 {
 // int Seat_numb; 
 //  int Seat_Value1;   
     // int button_pin = D0;
 //  int Button_State;
 // } myData1;



 
void setup() {
  pinMode(button_pin1, INPUT);
     pinMode(led_pin, OUTPUT);
     pinMode(led_pin1, OUTPUT);
  // led_pin.attach(D1);
 //  led_pin.attach(D8);
   
 // myServo_1.attach(5);
 // myServo_2.attach(6);
  radio.begin();
  radio.setChannel(83);
  radio.setDataRate(RF24_250KBPS);
  radio.setPALevel(RF24_PA_LOW);
  radio.openWritingPipe(addresses[0]);
  radio.openReadingPipe(1, addresses[1]);
  //radio.startListening();
  //radio.startListening();
}
 
void loop() {
radio.startListening();
//int Seat_Value1 = 3;
  if (radio.available()) {
    while (radio.available()) {
      radio.read( &myData, sizeof(myData) );
     // led_pin.write(myData.Button_State);
    //  led_pin.write(myData.Seat_Value);
      if (myData.Button_State == HIGH)
            {
        digitalWrite(led_pin, HIGH);
      }
      else
      {
        digitalWrite(led_pin, LOW);
      }
      if (myData.Seat_Value == 2)
            {
        digitalWrite(led_pin1, HIGH);
    //          delay(5);
   //   radio.stopListening();                             //This sets the module as transmitter
    //  int seat_status = 2;
   //   radio.write(&seat_status, sizeof(seat_status));  //Sending the data
   //   delay(5);
        //radio.stopListening();
        //int Seat_Value1 = 2;
       // myData1.Button_State = digitalRead(button_pin1);
      //  myData1.Seat_Value1 = Seat_Value1;
      // radio.write(&myData1, sizeof(myData1));
       //myData.Seat_Value1 = Seat_Value1;
     //radio.write(&myData, sizeof(myData));  
      }
      else
      {
        digitalWrite(led_pin1, LOW);
      }
      
     // }
  //  }
    }
              delay(5);
      radio.stopListening();                             //This sets the module as transmitter
      int seat_status = 2;
      radio.write(&seat_status, sizeof(seat_status));  //Sending the data
     // delay(5);
} 
}
//}

after removing all the commented out code, there not much left to your code

#include <SPI.h>
#include <RF24.h>
RF24 radio(9, 10);
// CE, CSN
const byte addresses [][6] = {"00001", "00002"};
//byte addresses[][6] = {"1Node", "2Node"};
//const byte addresses[] = {"1Node"};
int button_pin = A0;
int led_pin2 = 2;
int led_pin3 = 3;
//  int Seat_Value1;
short int seat_status;
struct dataStruct {
    int Seat_Value;
    int Button_State;
} myData;

void setup() {
    Serial.begin(57600);
    pinMode(button_pin, INPUT);
    pinMode(led_pin2, OUTPUT);
    pinMode(led_pin3, OUTPUT);
    radio.begin();
    radio.setChannel(83);
    radio.setDataRate(RF24_250KBPS);
    radio.setPALevel(RF24_PA_LOW);
    radio.openWritingPipe(addresses[1]);
    radio.openReadingPipe(1, addresses[0]);
}

void loop() {
    radio.stopListening();
    int Seat_Value = 2;
    myData.Button_State = digitalRead(button_pin);
    myData.Seat_Value = Seat_Value;
    radio.write( &myData, sizeof(myData));
    delay(5);
    radio.startListening();
    while (!radio.available())
         radio.read(&seat_status, sizeof(seat_status));
    Serial.println(seat_status);
    if (seat_status == 2)
    {
        digitalWrite(led_pin2, HIGH);
        digitalWrite(led_pin3, LOW);
    }

    else
    {
        digitalWrite(led_pin2, LOW);
        digitalWrite(led_pin3, HIGH);
    }

}

i don't understand why you call both stopListening() and startListening() in loop(). I would have thought you would call startListening() once in setup();

it doesn't make sense to perform radio.read(), repeatedly (!), when there is nothing available.

   while (!radio.available())
         radio.read(&seat_status, sizeof(seat_status));

The lines of code that reads the radio and does something with what is read should be inside an if

   if (radio.available())  {
        radio.read(&seat_status, sizeof(seat_status));
        Serial.println(seat_status);
    }

i see no attempt to transmit which I assume requires a radio.write()

Thanks gcjr. Can you please tell me what is the problem in code below. This code is working fine Nodemcu to Nodemcu communication but when I replaced One Nodemcu with Arduinio Pro Mini. It starts Misbehaving

This is the code for Arduino Pro Mini

  #include <SPI.h>
    #include <nRF24L01.h>
    #include <RF24.h>
    RF24 radio(D4, D2); // CE, CSN
    const byte addresses [][6] = {"00001", "00002"};  //Setting the two addresses. One for transmitting and one for receiving
    int button_pin = D0;
    int led_pin = D1;
    int seat_value1;
   int led_pin3 = D8;
   // boolean button_state = 0;
  //  boolean button_state1 = 0;

struct dataStruct {
  int seat_value; 
   // int Seat_Value_1;   
     // int button_pin = D0;
    int Button_State;
  } myData;
    
    void setup() {
      pinMode(button_pin, INPUT);
      pinMode(led_pin, OUTPUT);
      pinMode(led_pin3, OUTPUT);
      radio.begin();                           //Starting the radio communication
      radio.openWritingPipe(addresses[1]);     //Setting the address at which we will send the data
      radio.openReadingPipe(1, addresses[0]);  //Setting the address at which we will receive the data
      radio.setPALevel(RF24_PA_MIN); //You can set it as minimum or maximum depending on the distance between the transmitter and receiver. 
    }
    void loop() 
    {  
      delay(5);
      radio.stopListening();                             //This sets the module as transmitter
      myData.Button_State = digitalRead(button_pin);
      myData.seat_value = 2;
      radio.write(&myData, sizeof(myData));  //Sending the data
      delay(5);
  /*    if (button_state == HIGH)
        {
        digitalWrite(led_pin2, HIGH);
      }
      else
        {
        digitalWrite(led_pin2, LOW);
      }
*/
      
      radio.startListening();                            //This sets the module as receiver
      while(!radio.available());                         //Looking for incoming data
      radio.read(&seat_value1, sizeof(seat_value1)); //Reading the data
      if (seat_value1 == 2)
      {
        digitalWrite(led_pin3, HIGH);
         digitalWrite(led_pin, LOW);
      }
      else
      {
        digitalWrite(led_pin3, LOW);
        digitalWrite(led_pin, HIGH);
      }
    }

And this is the code for Nodemcu

 #include <Firebase.h>
#include <FirebaseArduino.h>
#include <FirebaseCloudMessaging.h>
#include <FirebaseError.h>
#include <FirebaseHttpClient.h>
#include <FirebaseObject.h>

#include <ArduinoJson.h>

#include <ESP8266WiFi.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>


//State;
RF24 radio(D4, D2); // CE, CSN
const byte addresses [][6] = {"00001", "00002"};    //Setting the two addresses. One for transmitting and one for receiving
 
   //Firebase settings
#define FIREBASE_HOST "fsr-button-f.firebaseio.com"     ///////// iot-distance-sensor.firebaseio.com    // 
#define FIREBASE_AUTH "17e91lJscwoh8Sm2ln10GDG4Qj24sEF1PlmIByf0"                                      //// wPzyU2AyRhHXjmyHYATAfB6gzbHHViMbkq6moH1f0   //
#define WIFI_SSID "TANVEER"
#define WIFI_PASSWORD "basit666"
#define fsrpin A0
int fsrreading;


int button_pin1 = D0;
int seat_value1;
//boolean button_state = 0;
//boolean button_state1 = 0;
//boolean seat_number = 0;
int led_pin1 = D1;
int led_pin2 = D8;
struct dataStruct {
  int seat_value; 
   // int Seat_Value_1;   
     // int button_pin = D0;
    int Button_State;
  } myData;
//struct Pack {
 // int button1;
 // int seat;
//} packet;


void setup() {

 // Connect to Wi-Fi
    Serial.print("Wi-Fi...");
    WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
    Serial.print("Connecting...");
    while (WiFi.status() != WL_CONNECTED)
    {
        Serial.print(".");
        delay(500);
    }
    Serial.println();
    Serial.print("Connected to: ");
    Serial.println(WiFi.localIP());

    Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);

  
  pinMode(button_pin1, INPUT);
  pinMode(led_pin1, OUTPUT);
  pinMode(led_pin2, OUTPUT);
  //pinMode(led_pin3, OUTPUT);
 fsrreading = analogRead(fsrpin);
  
  Serial.begin(9600);
  radio.begin();                            //Starting the radio communication
  radio.openWritingPipe(addresses[0]);      //Setting the address at which we will send the data
  radio.openReadingPipe(1, addresses[1]);   //Setting the address at which we will receive the data
  radio.setPALevel(RF24_PA_MIN);            //You can set it as minimum or maximum depending on the distance between the transmitter and receiver.
}

void loop() 
{

    fsrreading = analogRead(fsrpin);
   Firebase.setFloat("fsrreading", fsrreading);

  delay(5);
  radio.startListening();                    //This sets the module as receiver
  if (radio.available())                     //Looking for incoming data
  {
    radio.read(&myData, sizeof(myData));
    Firebase.setFloat("Button_State", myData.Button_State);
  Firebase.setFloat("seat_number", myData.seat_value);
    
    
    if(myData.Button_State == HIGH)
  {
     digitalWrite(led_pin1, HIGH);
  }
  else
  {
     digitalWrite(led_pin1, LOW);
  }
   if(myData.seat_value == 2)
   {
    digitalWrite(led_pin2, HIGH);
  }
  else
  {
     digitalWrite(led_pin2, LOW);
  }
  delay(5);

   /*     if (button_state1 == HIGH)
        {
        digitalWrite(led_pin3, HIGH);
      }
      else
        {
        digitalWrite(led_pin3, LOW);
      }
  */
  
  radio.stopListening();                           //This sets the module as transmitter
  //button_state1 = digitalRead(button_pin1);
  //packet.seat = 2;
  seat_value1 = 2;
  radio.write(&seat_value1, sizeof(seat_value1));   //Sending the data
  }
}