So, to simply put it, I've successfully managed to make a Leonardo (sender) and an Uno R3 (receiver) communicate using 2 nRF24L01 modules and the RF24 library.
The Leonardo sends data, the Uno receives it, I can work with data from both sides without a problem, perfect!
At least while I keep the USB connection active after uploading the sender sketch...
If I disconnect the Leonardo and then reconnect it, the Uno receives no more data...
After the disconnect-reconnect routine, the "L" led gets stuck, no blinking of any other status leds. Upon resetting with the board's button, the "L" led flashes, and right after it the "RX" led, and after stabilizing, still no communication whatsoever...
I have no idea why, to be honest, and was hoping anyone someone would be able to shed some light over this matter, as I'm struggling to finish an important project and it is vital that the system works on its own, without being connected to a computer...
It sounds as if the problem is at the sender so I would focus on getting information about what's happening inside the Leo. If you don't already have it, add print statements to show what happens during initialisation of the RF24 interface and whether any errors occur. Also add print statements to show what happens when the Leo tries to send subsequently: is the sketch actually getting as far as trying to send? Does the RF 24 library report that the send succeeded?
The communication sets up without problems after sketch upload, and as long as I keep the Leo connected.
No packets lost, data arrives at the receiver ok, and I get no errors whatsoever.
It's only when I try to use the Leo on its own (disconnecting and reconnecting the usb cable) that communication stops. Since it happens after losing the communication, I can't access the Serial monitor to see message dumps... It seems as though the Leo doesn't reset the communication... The only way to restart it is to re-upload the sketch.
The led sequence is totally different when I upload from what I get in the other cases. On upload the "L" led lights, flashes, and then the RX and TX blink and everything stabilizes. When I unplug and replug the USB, the "L" led gets stuck, and nothing else happens. On button reset, it blinks, Tx blinks, and nothing more.
Since the idea is to have this working off of battery, it's a bit troublesome...
ladansedesdamnes:
It's only when I try to use the Leo on its own (disconnecting and reconnecting the usb cable) that communication stops. Since it happens after losing the communication, I can't access the Serial monitor to see message dumps
Can you clarify whether the problem is loss of RF24 communication, or less of serial communication, after disconnecting/reconnecting the USB? If the serial connection isn't coming back up then you have a fundamental problem either preventing the Arduino from starting after a reset, or in the way you'd accessing the serial port on the PC.
What I know for sure is lost is RF24 communication.
I'll add some serial printing of data to see if serial communication still happens after reconnect and port reassign, but I believe it should still happen.
holmes4:
There's something wrong with your leo code .......
Mark
It IS possible (of course), but still weird that it works perfectly after sketch upload and while USB connection is maintained...
Not with the Leo!. As I recall it is normal to wait in setup() for the serial connection to be started on the Leo. And the Leo does not reset when the serial is opened!. eg this
Serial.begin(9600);
 // while the serial stream is not open, do nothing:
 while (!Serial) ;
this would cause your code to hang in setup(). See
holmes4:
Not with the Leo!. As I recall it is normal to wait in setup() for the serial connection to be started on the Leo. And the Leo does not reset when the serial is opened!. eg this
Serial.begin(9600);
// while the serial stream is not open, do nothing:
while (!Serial) ;
this would cause your code to hang in setup(). See
http://arduino.cc/en/Guide/ArduinoLeonardoMicro?from=Guide.ArduinoLeonardo
I'm actually already using that :)
> holmes4:
> You may want to look at using Serial1 and not Serial.
>
> Mark
How so? Can you point me to any resource about that?
Mark
I'm having this exact problem. I'm using a Romeo2 board, which is ATmega32u4 based, like the Leonardo and has an Xbee socket wired into Serial1 (D0, D1). It works right after upload, but fails to reconnect after a reset. I've followed the links and advise with no luck, tried the while loop:
Serial.begin(9600);
// while the serial stream is not open, do nothing:
while (!Serial) ;
Which hangs after a reset.
Any suggestions welcome!
// Test code. Runs once after upload
int led = 13;
void setup() {
 // initialize the digital pin as an output.
 pinMode(led, OUTPUT);
 Serial1.begin(9600);
 while (!Serial1) ; //hangs when this line is present. Blinks, but doesn't communicate when it's commented out.
 Serial1.println("Startup");
}
void loop() {
 digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
 delay(1000);       // wait for a second
 digitalWrite(led, LOW);  // turn the LED off by making the voltage LOW
 delay(1000);       // wait for a second
}
After banging away at this, I've come up with a solution. Setup wasn't hanging up in the while (!Serial1); loop. I was just being impatient. Adding a 7 second delay after the while fixed it (sent the next line of serial data out). Not sure why!
 while (!Serial1) ; //hangs when this line is present. Blinks, but doesn't communicate when it's commented out.
 delay(7000);
 Serial1.println("Startup");