Hi there, i want to communicate between 2 arduino using nRF24L01 modules.
the probleme that the receiver can read only one message, if i do another transmission the receivere can't read the seconde message, please could you help me. ere is the code
//TX
#include <SPI.h>
#include <RF24.h>
#include <nRF24L01.h>
#include <printf.h>
// declare variables
RF24 radio(9,10); //ce,cs pin
const uint64_t add1 = 999;
char msg[10];
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
radio.begin();
printf_begin();
radio.openWritingPipe(add1);
radio.printDetails(); //check if there is an error appear when you try to connect nRF to arduino
}
void loop() {
// put your main code here, to run repeatedly:
}
void serialEvent()
{
memset(msg,' ',sizeof(msg));
Serial.readBytesUntil('\n',msg,sizeof(msg));
radio.write(msg,sizeof(msg));
}
//RX
#include <SPI.h>
#include <RF24.h>
#include <nRF24L01.h>
#include <printf.h>
// declare variables
RF24 radio(9,10); //ce,cs pin
const uint64_t add1 =999;
char msg[10];
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
radio.begin();
printf_begin();
radio.openReadingPipe(1,add1);
radio.startListening();
}
void loop() {
// put your main code here, to run repeatedly:
if(radio.available())
{
memset(msg,' ',sizeof(msg));
radio.read(msg,sizeof(msg));
Serial.println(msg);
}
}
How quickly do you send the second message? Maybe your receiver has not fully cleared it's receive buffer and reset the receive "listen" process before your second message arrives. It wouldn't seem to apply here, but I've also found that operating a transmit/receive pair in close proximity can overload the receiver front end unless the power is adjusted downward.
Hi thanks for the replay, i tried to send the second message with a diferent delay. but my receiver d'ont receiv rhe second mesage, but when i reset the sender th tx , it's works but only one message.
so i have to reset my tx every time when i send data.
Try sending a fixed piece of data that does not require any input by the user.
Make sure that the user input is working properly before extending the program to send the data
If you are using the ManiacBug version of the RF24 library that could be the problem. Remove it completely and use the TMRh20 version of the RF24 library
so i have to reset my tx every time when i send data.
Would it be because your code is in the void setup()? ? ?
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
radio.begin();
printf_begin();
radio.openWritingPipe(add1);
radio.printDetails(); //check if there is an error appear when you try to connect nRF to arduino
}
void loop() {
// put your main code here, to run repeatedly:
}
There is nothing in the void loop() to TX for the second time.
void setup() is executed ONCE and ONCE only when you RESET the arduino.
Try sending a fixed piece of data that does not require any input by the user.
Make sure that the user input is working properly before extending the program to send the data
If you are using the ManiacBug version of the RF24 library that could be the problem. Remove it completely and use the TMRh20 version of the RF24 library
I hope you mean "also" in the sense that you are using the same library as I am.
The words could mean that you are using the TMRh20 library as well as the ManiacBug library and that would confuse the Arduino IDE.
If you write the simple program I suggested and it does not work then post that code so we can help.