getting feedback on nrf24l01

Hi guys. Before the explaining problem I want to explain my project :

There is a plane with arduino uno and Nrf24L01, and a remote control with uno and nrf24l01.I send the pot values to plane from remote. The plane get the values but I want a feedback like " I recieve your message". How can I do that? Here is my codes :

-Reciever-

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


RF24 radio(9,10);
const uint64_t pipe = (0xF0F0F0F0E1LL);
const uint64_t pipe2 = (0xF0F0F0F0E2LL);
int Gaz; //
int UpDown;
int LeftRight;
int msg[3];
int Connected = 1;



void setup() {
radio.begin();
Serial.begin(57600);
 radio.openReadingPipe(1,pipe);
 radio.openWritingPipe(pipe2);
 radio.startListening();

 

}

void loop() {

if(radio.available()){
     bool done = false;
     while(!done){
       done = radio.read(msg,3);
       
         Serial.println(msg[0]);
         Serial.println(msg[1]);
         Serial.println(msg[2]);


         radio.stopListening();
         delay(5);
         radio.write(Connected,1);
         delay(5);
         radio.startListening();
     }
}

}

And the transmitter

#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3f, 16, 2);


// Verici Servoları
int  Gaz ;
int  SagSol;
int  Yukariasagi;

int Gazs; 
int SagSols;
int Yukariasagis; 

int Connected = 0;
int msg[3];
RF24 radio(9,10);
const uint64_t pipe = (0xF0F0F0F0E1LL);
const uint64_t pipe2 = (0xF0F0F0F0E2LL);

void setup() {
radio.begin();
radio.enableAckPayload();
Serial.begin(57600);
lcd.begin();
lcd.backlight();
lcd.clear();
lcd.write("asdf");
radio.openWritingPipe(pipe);
radio.openReadingPipe(1,pipe2);

}

void loop() {
 
Gaz = analogRead(0);
SagSol = analogRead(1);
Yukariasagi = analogRead(2);

Gazs = map(Gaz,23,175,0,255);
SagSols = map(SagSol,39,228,60,120);
Yukariasagis = map(Yukariasagi,40,226,55,125);


msg[0] = Gazs;
msg[1] = SagSols;
msg[2] = Yukariasagis;

radio.write(msg,sizeof(msg));

radio.startListening();


if(radio.available()){
  radio.stopListening();
  lcd.print("ok");
     }
    radio.stopListening();
   
   }

** edit **

And can we send message while we are recieving a message? For example I want to add other sensors into plane and can we send values while we getting other values?``

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :slight_smile:

The simple nrf24 demo tutorial might have information of interest.

There is no need for sending an "I got your packet" message, write() already returns whether the transmission succeeded.

You are using the old Maniacbug library, I would suggest to upgrade to the the newer TMRh20 library.
You will have to change the code slightly.

Can you help me about the code. I download the library but I don't know this library. Can you edit the code and write it if you have time?

LuckeRu:
Can you edit the code and write it if you have time?

I wont.

The main incompatibility of the two libraries is the signature of read, you could use something like

 if(radio.available()) {
    radio.read(msg, sizeof(msg));
    Serial.println(msg[0]);
    Serial.println(msg[1]);
    Serial.println(msg[2]);
  }

Your original code read only half the message.

  if (!radio.write(msg, sizeof(msg))) {
    Serial.println(F("could not send the packet properly"));
  }

That way you can check for delivery.

LuckeRu:
Can you help me about the code. I download the library but I don't know this library. Can you edit the code and write it if you have time?

See the code in the tutorial in the link in Reply #2

...R

I think I solve it. Everything works well. Thank you for reply. But I have a question. I set the "data send per second" to 1 milisecond. Can it damage/crash arduino or anything else?

LuckeRu:
I set the "data send per second" to 1 milisecond. Can it damage/crash arduino or anything else?

I don't think an nRF24 can send a message every millisec. I think a round-trip message and acknowledgement takes 3 to 5 millisecs. Trying to send too often might mean that messages get mixed up.

You also need to consider whether the receiving Arduino has time to do anything useful with the data it receives.

I find it hard to believe that a message rate of more than 10 per second is actually needed, and maybe 5 per second would be sufficient.

...R

LuckeRu:
I think I solve it. Everything works well. Thank you for reply. But I have a question. I set the "data send per second" to 1 milisecond. Can it damage/crash arduino or anything else?

Can you post your updated code please?
I will help others who use this thread.
Good to hear you got things working... Tom... :slight_smile:

The Transmitter

// SimpleTx - the master or the transmitter

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <LiquidCrystal_I2C.h>
#define CE_PIN   9
#define CSN_PIN 10
LiquidCrystal_I2C lcd(0x3f, 16, 2);
const byte slaveAddress[5] = {'R','x','A','A','A'};


RF24 radio(CE_PIN, CSN_PIN); // Create a Radio

int dataToSend[3];
char txNum = '0';
int GazE;
int SagSolE;
int YukariAsagiE;

unsigned long currentMillis;
unsigned long prevMillis;
unsigned long txIntervalMillis = 1; // send once per second


void setup() {
lcd.begin();
lcd.backlight();
lcd.setCursor(0,0);

    Serial.begin(9600);

    Serial.println("SimpleTx Starting");

    radio.begin();
    radio.setDataRate( RF24_250KBPS );
    radio.setRetries(3,5); // delay, count
    radio.openWritingPipe(slaveAddress);
}

//====================

void loop() {

      GazE = map(analogRead(0),23,200,0,255);
      SagSolE = map(analogRead(2),37,260,70,120);
      YukariAsagiE = map(analogRead(1),35,230,65,125);

      if (GazE > 255) // My pot is  too unbalanced. ( Sometimes it can show up to "200" value)
      GazE = 255;

      if (GazE < 0)
      GazE = 0; //( "Gaz" Means Throttle. "GazE" Means Throttle Edited)
      
      if (SagSolE > 120) // "Sag Sol" Means Left Right. "SagSolE" Means Left Right Edited)
      SagSolE = 120;

      if (SagSolE < 70)
      SagSolE = 70;
      
      if (YukariAsagiE > 125) // "Yukari Asagi" Means Up Down. "YukariAsagiE" Means Up Down Edited)
      YukariAsagiE = 125;

      if (YukariAsagiE < 65)
      YukariAsagiE = 65;
   
   
   
   dataToSend[0] = GazE;
   dataToSend[1] = YukariAsagiE;
   dataToSend[2] = SagSolE;
    
    
    
    currentMillis = millis();
    if (currentMillis - prevMillis >= txIntervalMillis) { // I dont understand anything here 
        send();
        prevMillis = millis();
    }
}

//====================

void send() {

    bool rslt;
    rslt = radio.write( &dataToSend, sizeof(dataToSend) );


    if (rslt) {
        
        lcd.print("Connected"); // If its connected , it prints to lcd connected :p
        lcd.setCursor(0,0);
        
    }
    else {
        
        
        lcd.print("Connection Lost"); // If connection lost , it prints connection lost and clear it because if it connect again it writes "Connectedn Lost"
        delay(1000);
        lcd.clear();
      
    }
}

//================

And the Reciever

// SimpleRx - the slave or the receiver

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>
#define CE_PIN   9
#define CSN_PIN 10

const byte thisSlaveAddress[5] = {'R','x','A','A','A'};

RF24 radio(CE_PIN, CSN_PIN);

int dataReceived[3]; // this must match dataToSend in the TX
bool newData = false;
int int1;
int int2;
int int3;


Servo UpDown;
Servo LeftRight;
int Throttle;

void setup() {

    UpDown.attach(6);
    LeftRight.attach(5);
    Serial.begin(9600);
    Serial.println("SimpleRx Starting");
    radio.begin();
    radio.setDataRate( RF24_250KBPS );
    radio.openReadingPipe(1, thisSlaveAddress);
    radio.startListening();
}

//=============

void loop() {
    getData();
    showData();
    UpDown.write(int2);
    LeftRight.write(int3);
    digitalWrite(3,int1);
}

//==============

void getData() {
    if ( radio.available() ) {
        radio.read( &dataReceived, sizeof(dataReceived) );
        newData = true;
        int1 = dataReceived[0];
        int2 = dataReceived[1];
        int3 = dataReceived[2];
    }
}

void showData() {
    if (newData == true) {
        Serial.println(int1);
         Serial.println(int2);
          Serial.println(int3);
        newData = false;
    }
}

You say you want to send a message every millisecond (which, as i said earlier, is much too fast) but then you have delay(1000) in your code which means the maximum rate of sending cannot be more than one per second.

This my not work very well

      GazE = map(analogRead(0),23,200,0,255);
      SagSolE = map(analogRead(2),37,260,70,120);
      YukariAsagiE = map(analogRead(1),35,230,65,125);

because you are reading from different input pins. It would be better like this so that it discards the first reading after every change of pin

     GazE = analogRead(0);
      GazE = map(analogRead(0),23,200,0,255);

      SagSoIE = analogRead(2);
      SagSolE = map(analogRead(2),37,260,70,120);

      YukariAsagiE = analogRead(1);
      YukariAsagiE = map(analogRead(1),35,230,65,125);

...R

but the delay starts only you get disconnected. And everything works well (actually one think is not). I change the code as you write. Now the problem is this " Unstable Potantiometer - Programming Questions - Arduino Forum "

well everything stopped working :frowning:

ok. The problem is "radio.setDataRate( RF24_250KBPS )"