Hello,
With reference to the joystick example that uses nRF24L01's RF24.h library to send and receive joystick analog values - can someone explain what these lines do? I'm quoting a few lines in my post, but I include the entire sketch at the bottom.
// NOTE: the "LL" at the end of the constant is "LongLong" type
const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe
In the MIRF library, the receiver has a "name", so senders can identify which receiver the data is meant for. Is this the purpoase of this "pipe" definition in RF24 library? So the sender and receiver have to use the same pipe value?
if ( radio.available() )
Does available() return true when there is a new packet? If the sender doesn't send anything, it just keeps printing "No radio available"?
while (!done)
{
// Fetch the data payload
done = radio.read( joystick, sizeof(joystick) );
Serial.print("X = ");
Serial.print(joystick[0]);
Serial.print(" Y = ");
Serial.println(joystick[1]);
}
Why is this in a while loop? While done is false (meaning it hasn't read the data yet), won't it keep printing trash for joystick[0] and joystick[1]?? Shouldn't the Serial.print be OUTSIDE the while loop? Else we're expecting the read() command to run just once, in which case I don't understand the purpose of the loop.
I know reading other people's code isn't much fun, so I appreciate any insights.
From http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo
/*-----( Import needed libraries )-----*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
/*-----( Declare Constants and Pin Numbers )-----*/
#define CE_PIN 9
#define CSN_PIN 10
// NOTE: the "LL" at the end of the constant is "LongLong" type
const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe
/*-----( Declare objects )-----*/
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
/*-----( Declare Variables )-----*/
int joystick[2]; // 2 element array holding Joystick readings
void setup() /****** SETUP: RUNS ONCE ******/
{
Serial.begin(9600);
delay(1000);
Serial.println("Nrf24L01 Receiver Starting");
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();;
}//--(end setup )---
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
if ( radio.available() )
{
// Read the data payload until we've received everything
bool done = false;
while (!done)
{
// Fetch the data payload
done = radio.read( joystick, sizeof(joystick) );
Serial.print("X = ");
Serial.print(joystick[0]);
Serial.print(" Y = ");
Serial.println(joystick[1]);
}
}
else
{
Serial.println("No radio available");
}