problem with arduino and NRF24L01+ ( I AM NEW TO ELECTRONICS )

my reciever code is this:


#include <SPI.h>
#include “nRF24L01.h”
#include “RF24.h”
int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int LED1 = 3;

void setup(void){
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();
pinMode(LED1, OUTPUT);}

void loop(void){
if (radio.available()){
bool done = false;
while (!done){
done = radio.read(msg, 1);
Serial.println(msg[0]);
if (msg[0] == 111){delay(10);digitalWrite(LED1, HIGH);}
else {digitalWrite(LED1, LOW);}
delay(10);}}
else{Serial.println(“No radio available”);}}


my transmitter code is

#include <SPI.h>
#include “nRF24L01.h”
#include “RF24.h”
int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int SW1 = 7;

void setup(void){
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipe);}

void loop(void){
if (digitalRead(SW1) == HIGH){
msg[0] = 111;
radio.write(msg, 1);}}


My error with reciever code while compiling is

C:\Users\YOgi\Documents\Arduino\RECIEVE-easy\RECIEVE-easy.ino: In function ‘void loop()’:

RECIEVE-easy:20: error: void value not ignored as it ought to be

done = radio.read(msg, 1);

^

exit status 1
void value not ignored as it ought to be


my transmitter gets compile but it shows error like

C:\Users\YOgi\Documents\Arduino\libraries\RF24-master\RF24.cpp:559:17: warning: invalid suffix on literal; C++11 requires a space between literal and identifier [-Wliteral-suffix]

printf_P(PSTR(“Data Rate\t = “PRIPSTR”\r\n”),pgm_read_word(&rf24_datarate_e_str_P[getDataRate()]));

^

C:\Users\YOgi\Documents\Arduino\libraries\RF24-master\RF24.cpp:560:17: warning: invalid suffix on literal; C++11 requires a space between literal and identifier [-Wliteral-suffix]

printf_P(PSTR(“Model\t\t = “PRIPSTR”\r\n”),pgm_read_word(&rf24_model_e_str_P[isPVariant()]));

^

C:\Users\YOgi\Documents\Arduino\libraries\RF24-master\RF24.cpp:561:17: warning: invalid suffix on literal; C++11 requires a space between literal and identifier [-Wliteral-suffix]

printf_P(PSTR(“CRC Length\t = “PRIPSTR”\r\n”),pgm_read_word(&rf24_crclength_e_str_P[getCRCLength()]));

^

C:\Users\YOgi\Documents\Arduino\libraries\RF24-master\RF24.cpp:562:17: warning: invalid suffix on literal; C++11 requires a space between literal and identifier [-Wliteral-suffix]

printf_P(PSTR(“PA Power\t = “PRIPSTR”\r\n”), pgm_read_word(&rf24_pa_dbm_e_str_P[getPALevel()]));

^

Sketch uses 3,774 bytes (11%) of program storage space. Maximum is 32,256 bytes.
Global variables use 205 bytes (10%) of dynamic memory, leaving 1,843 bytes for local variables. Maximum is 2,048 bytes.

Can you post a link to the guide you are following, and if it is not clear from the guide, where you got your RF24 libraries from.
Your receive code compiles perfectly for me.
Incidentally:

  1. you have typo. Receiver not Reciever.
  2. Try the Autoformat under the Tools menu.

i tried auto-format , but still it isn’t working.

this library , I am including !

RF24-master.zip (319 KB)

Karan02:
i tried auto-format , but still it isn't working.
. . .

But you did notice a vast improvement in the way the program was formatted, in comparison with what you posted ?

Interestingly, the RF24 library, which you found from somewhere, does indeed declare the read() function as void, which is what the compiler complaining about.

The version of the this library, which I have installed is, i believe, from GitHub - maniacbug/RF24: Arduino driver for nRF24L01 and that should be compatible with your example sketches. It declares the read() function as boolean, which is what your receiver sketch is assuming.

Try changing it from

done = radio.read(msg, 1);

to

radio.read(msg, 1);

The newer (and better) TMRh20 version of the RF24 library does not return a value. That is one of its very few incompatibilities with the earlier maniacBug version

...R

Thank you so much! it worked with the new library !

i am a newbie, can you provide me some more simple examples so i can practice !

you're not gonna learn much running other people's code.
Now that you have the example running, read the radio's datasheet (book) and see what else you can get it to do.

In the zip file of the library you downloaded, there should be a directory of examples of varying degrees of complexity. Use examples from the same library package as the one you have currently installed, or you risk more compatibility issues, like you have already experienced.

Hi,

A lot of beginner How-To for nRF24L01 HERE:
http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo

There are links to the RF24 TMRH20 examples down the page a ways...

Incorrect data is being transmitted. As in if I try to transmit 111, then 111, 255 and 0 are all showing up randomly. Also, if the jumper wires move the slightest bit, then a no radio available signal is shown. After that, in a few seconds, 255, 111 and 0 are randomly sent again. Can anyone guide me on what might be wrong or what am I doing wrong.

my reciever code is this:


#include <SPI.h>
#include “nRF24L01.h”
#include “RF24.h”
int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int LED1 = 3;

void setup(void){
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();
pinMode(LED1, OUTPUT);}

void loop(void){
if (radio.available()){
bool done = false;
while (!done){
done = radio.read(msg, 1);
Serial.println(msg[0]);
if (msg[0] == 111){delay(10);digitalWrite(LED1, HIGH);}
else {digitalWrite(LED1, LOW);}
delay(10);}}
else{Serial.println(“No radio available”);}}


my transmitter code is

#include <SPI.h>
#include “nRF24L01.h”
#include “RF24.h”
int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int SW1 = 7;

void setup(void){
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipe);}

void loop(void){
if (digitalRead(SW1) == HIGH){
msg[0] = 111;
radio.write(msg, 1);}}

Karan02:
Can anyone guide me on what might be wrong or what am I doing wrong.

Post the pair of programs that are causing this. And please use the code button </> so your code looks like this and is easy to copy to a text editor

…R

my reciever code is this:


<#include <SPI.h>
#include “nRF24L01.h”
#include “RF24.h”
int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int LED1 = 3;

void setup(void){
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();
pinMode(LED1, OUTPUT);}

void loop(void){
if (radio.available()){
bool done = false;
while (!done){
done = radio.read(msg, 1);
Serial.println(msg[0]);
if (msg[0] == 111){delay(10);digitalWrite(LED1, HIGH);}
else {digitalWrite(LED1, LOW);}
delay(10);}}
else{Serial.println(“No radio available”);}}
/>


my transmitter code is
<
#include <SPI.h>
#include “nRF24L01.h”
#include “RF24.h”
int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int SW1 = 7;

void setup(void){
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipe);}

void loop(void){
if (digitalRead(SW1) == HIGH){
msg[0] = 111;
radio.write(msg, 1);}}
/>

You have not used the code tags as I requested. Please help us to help you.

In Reply #5 you seemed to say you are using the TMRh20 library which does not use

done = radio.read(msg, 1);

so perhaps the code you have posted is not the code you are using.

And please put every statement on a separate line - it makes code much easier to read.

Edit to add ...
There is another problem that I did not spot earlier.

In your Tx code you have

radio.write(msg, 1);

but you have defined the variable msg as int - which is 2 bytes - whereas you are only sending 1 byte.
It is much better to use

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

And I presume there is the same problem on the receiving side.

...R

thanks Robin2, I used your suggested library.

my reciever code is this:


#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int LED1 = 3;

void setup(void){
 Serial.begin(9600);
 radio.begin();
 radio.openReadingPipe(1,pipe);
 radio.startListening();
 pinMode(LED1, OUTPUT);}

void loop(void){
 if (radio.available()){
   bool done = false;    
   while (!done){
     done = radio.read(msg, sizeof(msg));      
     Serial.println(msg[0]);
     if (msg[0] == 111){delay(10);digitalWrite(LED1, HIGH);}
     else {digitalWrite(LED1, LOW);}
     delay(10);}}
 else{Serial.println("No radio available");}}

my transmitter code is

#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int SW1 = 7;

void setup(void){
 Serial.begin(9600);
 radio.begin();
 radio.openWritingPipe(pipe);}

void loop(void){
 if (digitalRead(SW1) == HIGH){
 msg[0] = 111;
 radio.write(msg, sizeof(msg));}}

1)my code is working fine but sometimes, slightest movement in jumper wires causes loss in connectivity. I want to use this modules at some hard place so it must be able to bear vibrations and some slight movements . are there any solutions for this ? what if i do soldering with this modules with arduinos through some wires?

  1. can you tell me how to send char ? i tried it in transmitter code by just replacing int with char and change message 111 with “111” . but it shows error with compiling
    it gives error message :

error: invalid conversion from ‘const char*’ to ‘char’ [-fpermissive]

msg[0] =“111”;

Karan02:
1)my code is working fine but sometimes, slightest movement in jumper wires causes loss in connectivity.

I have no idea what jumper wires you are talking about. You need to make a pencil drawing showing all the wiring and post a photo of the drawing. In this case a photo of the jumper wire would also be useful - but note the word "also".

  1. can you tell me how to send char ?
    [/quote]
    If you want to send chars instead of ints you just need to change
int msg[1];

to

char msg[1];

You will still be able to use the line

msg[0] = 111;

However I have no idea if that will solve the problem that leads you to ask the question. As usual, tell us what you want to happen.

...R

PS...
I have now tried to compile your TX code with the TMRh20 version of the RF24 library and, as expected, it fails on the line done = radio.read(msg, sizeof(msg)); - which I advised you to change way back in Reply #4.

That strongly suggests to me that you are wasting both our time by posting the wrong code.

...R

My understanding is that he originally attempted to use the THRh20 version of the RF24 library. He had compilation errors because his sketch was incompatible with this library ( read function return type ), so he reverted to the “Maniac Bug” version of RF24.

I have also had stability problems with nRF240L01 modules, especially the version with the power amplifier where even the position the antenna could cause it to fail.

This guide has chapter devoted power problems with this module and resolution:
http://arduino-info.wikispaces.com/Nrf24L01-2.4Ghz-HowTo

6v6gt:
My understanding is that he originally attempted to use the THRh20 version of the RF24 library. He had compilation errors because his sketch was incompatible with this library ( read function return type ), so he reverted to the "Maniac Bug" version of RF24.

That is not how I read Reply #5 combined with Reply #13 - quite the opposite.

However clear confirmation from the OP would be a great help.

I recommend the TMRh20 version of the library. I had problems myself with ManiacBug's version.

...R

no robin2 !
i am working with this lib that you suggested.

can you tell me , which type of data is fastest transmitted?(like int , char ,etc )
i want to control my RC plane with this module.

RF24-master.zip (202 KB)

@6v6gt , but i also used regulators , that are shown in your link.

-my all connection is perfect.
-my code get compiles easily.
-prints 111 on receiver side serial monitor.
but some slight movements causes disturbance in results !

Like sometimes , i move some jumper wires slightly on transmitting side , no radio available pops up in serial monitor and then again catches up connectivity ! so i think my jumper wires are weak for connections.
are there any solutions for this !

here are my physical connections photos.

Karan02:
i am working with this lib that you suggested.

As far as I can see that is NOT the TMRh20 library. I think you still have the older ManiacBug version. Unfortunately TMRh20 does not make it easy to tell them apart. The read() function in RF24.cpp is different.

Posting the library file (as you have done) is not nearly as useful as posting a link to the place from where you downloaded it.

I suspect the most practical thing to do would be to delete the existing library completely and then download and install the TMRh20 version.

On my own PC I have given the files from the TMRh20 version names that clearly show what they are (e.g. TMRh20RF24.cpp) - but that may be complicated if you are new to the Arduino system.

can you tell me , which type of data is fastest transmitted?(like int , char ,etc )
i want to control my RC plane with this module.

The type of data has no influence on the speed. What matters is the number of bytes transmitted. Don't worry about this until a problem actually shows up.

...R