arduino nrf24l01

i have two nrf24l01's but cant make them work together. im trying to make the values from my seriell plotter make my motors spin on the other arduino. if you have any suggestions pleace comment or contact me on olavsie@hotmail.com underneath you can see my transmitter and reciever code:

transmitter:

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

RF24 radio(7, 8); // CE, CSN

int value = 0;
const byte addresses[][6] = {"00001"};

void setup()
{
radio.begin();
radio.openWritingPipe(addresses[1]);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
}
void loop()
{
delay(5);
value = Serial.parseInt();

radio.write(&value, sizeof(value));
delay(5);
}

reciever:

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

RF24 radio(7, 8); // CNS, CE
Servo ESC1, ESC2, ESC3;

const byte addresses[6] = {"00001"};
boolean value = 0;

void setup()
{
radio.begin();
radio.openReadingPipe(1, addresses[1]);
radio.startListening();
ESC1.attach(3, 700, 2000);
ESC2.attach(4, 700, 2000);
ESC3.attach(5, 700, 2000);
Serial.begin(9600);
radio.startListening();
}

void loop()
{
delay(5);

if ( radio.available())
{
while (radio.available())
{
radio.read(&value, sizeof(value));
ESC1.writeMicroseconds(value);
ESC2.writeMicroseconds(value);
ESC3.writeMicroseconds(value);
}
}
}

Look at your use of radio.openWritingPipe(addresses[1]);
Arrays are 0 based

The receiver side r radio.openReadingPipe(1, addresses[1]); close to the same issue that is just an array of char and you are sending one char, just send address.

Try changing both lines to the following.
radio.openWritingPipe(addresses[0]);
radio.openReadingPipe(1, addresses);

i will watch this thread, I have about 15 of these in my house.

Romonaga:
Look at your use of radio.openWritingPipe(addresses[1]);
Arrays are 0 based

The receiver side r radio.openReadingPipe(1, addresses[1]); close to the same issue that is just an array of char and you are sending one char, just send address.

Try changing both lines to the following.
radio.openWritingPipe(addresses[0]);
radio.openReadingPipe(1, addresses);

i will watch this thread, I have about 15 of these in my house.

Thanks for the tip. i treid out the changes but it still seems like there is a connection problem between the reciever and transmitter.

OK lets take this one step at a time.

I assume you have downloaded and installed the RF24 Lib, that is clear so that requirement is solved.
Next is the issue of wiring, this can be tricky and if not done correctly will lead to frustration.

So while you work out sending me the info on what pins you used, I will put to some simple send and receive code together for you.

Have a look at this Simple nRF24L01+ Tutorial.

Wireless problems can be very difficult to debug so get the wireless part working on its own before you start adding any other features.

The examples are as simple as I could make them and they have worked for other Forum members. If you get stuck it will be easier to help with code that I am familiar with. Start by getting the first example to work

...R

Romonaga:
OK lets take this one step at a time.

I assume you have downloaded and installed the RF24 Lib, that is clear so that requirement is solved.
Next is the issue of wiring, this can be tricky and if not done correctly will lead to frustration.

So while you work out sending me the info on what pins you used, I will put to some simple send and receive code together for you.

i used the following:
vcc - 3.3v
gnd - gnd
csn - 8
ce - 7
mosi - 11
miso - 12
sck - 13

im using two peaces of the arduino uno board.

Robin2:
Have a look at this Simple nRF24L01+ Tutorial.

Wireless problems can be very difficult to debug so get the wireless part working on its own before you start adding any other features.

The examples are as simple as I could make them and they have worked for other Forum members. If you get stuck it will be easier to help with code that I am familiar with. Start by getting the first example to work

...R

i connected the rf24l01 as showed in the tutorial. then copied your codes to the reciever and transmittor. i got the following error:
Data Sent Message 0 Tx failed

on the reciever it said:
SimpleRx starting

i should also probably add that im using one with an antenna. this one to be excact:

https://www.ebay.com/itm/NRF24L01-PA-LNA-Wireless-Module-Antenna-1000-Meters-Long-Distance-/273204268732?ef_id=Cj0KCQjwov3nBRDFARIsANgsdoFS2g71k8oudkb0Epwp_R0kRQpx2E8PbjGxvZ4TyFg0N5_C659eO-waAqTTEALw_wcB:G:s

Olav24l01:
i connected the rf24l01 as showed in the tutorial. then copied your codes to the reciever and transmittor. i got the following error:
Data Sent Message 0 Tx failed

on the reciever it said:
SimpleRx starting

The info that was provided you was perfect, my only comment is that radio,begin() does return bool, it when it returns false for me, I know it is a wiring issue. For example, just used Robin2s sender, placed the code on a KNOWN working unit.

I changed the code to print if radio.begin() was true a message false a different message

First run before doing anything I was to see the radio and send data.

I took off 2 wires and restarted and was told the radio.begin failed.

I took pins 7 and 8 off.

Ok is your one sending data in the same rooms as the receiver? If so, you might have a different issues and we need to set the PA level to low. radio.setPALevel(RF24_PA_LOW);

First do this, on his sender see if radio.begin() returns true;

I spent one day get upset as to why 6 new radios were not working on my network on these. I kept swapping it out with a good one, and it would not work.

I came to realize that there was a difference. One did not have an antenna, the new ones did. I had wanted to switch out all the sensors to these new ones. However, before I would put it back out, I would test it on the test network.

Long story, I had to lower the PA it was "over powering" the receiver.

Romonaga:
I spent one day get upset as to why 6 new radios were not working on my network on these. I kept swapping it out with a good one, and it would not work.

I came to realize that there was a difference. One did not have an antenna, the new ones did. I had wanted to switch out all the sensors to these new ones. However, before I would put it back out, I would test it on the test network.

Long story, I had to lower the PA it was "over powering" the receiver.

well, i tried to add the PA_LOW command, but it seems like it didnt do much. i also tried to change the code a bit just to see if i could recieve anything at all. i made this simple code, but all i recieve is the number 255 three times in a row before it stops.

transmittor:

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

RF24 radio(7, 8); // CE, CSN

int value = 0;
const byte addresses[][6] = {"00001"};

void setup()
{
radio.begin();
radio.openWritingPipe(addresses[0]);
radio.setPALevel(RF24_PA_LOW);
radio.stopListening();
}
void loop()
{
delay(5);
value = Serial.parseInt();

radio.write(&value, sizeof(value));
delay(5);
}

reciver:

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

RF24 radio(7, 8); // CNS, CE

const byte addresses[6] = {"00001"};
boolean value = 0;

void setup()
{
radio.begin();
radio.openReadingPipe(1, addresses);
radio.startListening();
Serial.begin(9600);
radio.setPALevel(RF24_PA_LOW);
}

void loop()
{
delay(5);
if ( radio.available())
{
while (radio.available())
{
radio.read(&value, sizeof(value));
Serial.print(value);
delay(100);
}
}
}

Ok this is a perfect simple example you have.

  1. Where is your Serial.begin(9600); in transmitter?
  2. Please check radio.begin(), I would like to know if it returns true or false.
  3. In your Transmit you are sending an int, I do not see you changing that value but you are sending on int. The receive side is trying to read a bool. This is an issue, match what you send to what you receive.

We have not even got past IF radio.begin() returns true.

Romonaga:
Ok this is a perfect simple example you have.

  1. Where is your Serial.begin(9600); in transmitter?
  2. Please check radio.begin(), I would like to know if it returns true or false.
  3. In your Transmit you are sending an int, I do not see you changing that value but you are sending on int. The receive side is trying to read a bool. This is an issue, match what you send to what you receive.

We have not even got past IF radio.begin() returns true.

  1. sorry, my mistake. just forgot it.
  2. how do i check my radio.begin()??? and how do i know if it returnes true or false?
  3. i changed the code to:

delay(5);
char value = Serial.read();
radio.write(&value, sizeof(value));

is this better, if not pls explain.

thanks for all the help by the way, it is really appreciated. as you might can tell i am quite new to the arduino "game" Xd

I made some tweeks to the code. I hope you can see the serial ports on both and please note I use 115200 as my serial rate. You might need to change that.

I tested this between 2 machines, I had packet loss due to the antenna, but I see packets.

Please run these and observer the output.
**** NOTE when i moved them a bit apart as I expected the packet loss stopped. *****
This bit of code allowed me to drop packet loss to Zero. But its not good form as it will leave it in a loop with a down receiver or sender. Once you get this going we will talk about acks so you can inusre packets were delivered.

      while(radio.write(&value, sizeof(value)) == false )
      {
        delay(200);
      }

As for your question
char value = Serial.read();
radio.write(&value, sizeof(value));
Please note that i removed this, when you are sending data both sides have to agree to what is being sent and received. Ways around this, but thats a more advanced topic. Lsts first use the very simple code I provided to get you running. I am here all night, soldering.

//Simple Sender

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

RF24 radio(7, 8); // CE, CSN

int value = 0;
const byte addresses[][6] = {"TEST"};

bool isRadioRunning = false;

void setup()
{
  
  if( (isRadioRunning = radio.begin()) == true)
  {
    Serial.println("Radio Begin Success");
    radio.openWritingPipe(addresses[0]);
    radio.setPALevel(RF24_PA_LOW);
    radio.stopListening();
  }
  else
  {
    Serial.println("Radio Begin Failed");
  }
}

void loop()
{
  
  if(true == isRadioRunning)
  {
      value = value + 1;
      
      Serial.print("I am going To Send: ");
      Serial.println(value);
       
      radio.write(&value, sizeof(value));
      delay(200);
  }
  else
  {
    Serial.println("Radio Is Not Running");
  }
}
//Simple Receiver
#include <nRF24L01.h>
#include <RF24.h>
#include <SPI.h>

RF24 radio(7, 8); // CNS, CE

const byte addresses[6] = {"TEST"};                                                           
int value = 0;

void setup()
{
  Serial.begin(115200);
  if(true == radio.begin())
  {
    Serial.println("Radion Started");
   
    radio.openReadingPipe(1, addresses);
    radio.startListening();
    radio.setPALevel(RF24_PA_LOW);
  }
  else
  {
    Serial.println("Radion Not Started");
    
  }
}

void loop()
{
  delay(5);
  if ( radio.available())
  {
      radio.read(&value, sizeof(value));
      Serial.print("Value of: ");
      Serial.println(value);
  }
}

Olav24l01:
thanks for all the help by the way, it is really appreciated. as you might can tell i am quite new to the arduino "game" Xd

Its not a problem, I love these little radios and what they can do. Once we get you up and running I can explain what I am doing with them. I uses these on Rasbperry Pi's as well. Use them as my central node, talks to my DB server and any other stuff I need done.

As I said I have about 15 of them and plan more.

Romonaga:
I made some tweeks to the code. I hope you can see the serial ports on both and please note I use 115200 as my serial rate. You might need to change that.

I tested this between 2 machines, I had packet loss due to the antenna, but I see packets.

Please run these and observer the output.
**** NOTE when i moved them a bit apart as I expected the packet loss stopped. *****
This bit of code allowed me to drop packet loss to Zero. But its not good form as it will leave it in a loop with a down receiver or sender. Once you get this going we will talk about acks so you can inusre packets were delivered.

      while(radio.write(&value, sizeof(value)) == false )

{
       delay(200);
     }




As for your question
char value = Serial.read();
radio.write(&value, sizeof(value));
Please note that i removed this, when you are sending data both sides have to agree to what is being sent and received. Ways around this, but thats a more advanced topic. Lsts first use the very simple code I provided to get you running. I am here all night, soldering.



//Simple Sender

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

RF24 radio(7, 8); // CE, CSN

int value = 0;
const byte addresses[][6] = {"TEST"};

bool isRadioRunning = false;

void setup()
{
 
 if( (isRadioRunning = radio.begin()) == true)
 {
   Serial.println("Radio Begin Success");
   radio.openWritingPipe(addresses[0]);
   radio.setPALevel(RF24_PA_LOW);
   radio.stopListening();
 }
 else
 {
   Serial.println("Radio Begin Failed");
 }
}

void loop()
{
 
 if(true == isRadioRunning)
 {
     value = value + 1;
     
     Serial.print("I am going To Send: ");
     Serial.println(value);
     
     radio.write(&value, sizeof(value));
     delay(200);
 }
 else
 {
   Serial.println("Radio Is Not Running");
 }
}







//Simple Receiver
#include <nRF24L01.h>
#include <RF24.h>
#include <SPI.h>

RF24 radio(7, 8); // CNS, CE

const byte addresses[6] = {"TEST"};                                                          
int value = 0;

void setup()
{
 Serial.begin(115200);
 if(true == radio.begin())
 {
   Serial.println("Radion Started");
 
   radio.openReadingPipe(1, addresses);
   radio.startListening();
   radio.setPALevel(RF24_PA_LOW);
 }
 else
 {
   Serial.println("Radion Not Started");
   
 }
}

void loop()
{
 delay(5);
 if ( radio.available())
 {
     radio.read(&value, sizeof(value));
     Serial.print("Value of: ");
     Serial.println(value);
 }
}

got this error on the line " if(true == radio.begin()) "

" invalid operands of types 'bool' and 'void' to binary 'operator==' "

new error, same line:

"void value not ignored as it ought to be"

Olav24l01:
new error, same line:

"void value not ignored as it ought to be"

Ok now we are getting some where. Where did you get your RF24 Lib From?

This is the one I am using, lets both make sure we are using the same one. http://tmrh20.github.io/RF24/

As you will see, the version I am using provides a bool on begin. http://tmrh20.github.io/RF24/classRF24.html#a048a20c73c7d9b2e02dcbae6fb9c4ba8

You will want to use this version, and we can talk about why later if you like.

thank you so much. i will do this first thing in the morning. il get back to you with an uptade afterwards

Olav24l01:
thank you so much. i will do this first thing in the morning. il get back to you with an uptade afterwards

Also, please in the sender, add a Serial.begin, seems I left that out, you will not see output.