Ok, here's the deal: When I connect the nRF24L01's they don't communicate. I get "No Radio" on serial Port.
But when I give a command, in this case when I Pull joystick UP, they communicate and get the command. Here is the question: How can I keep them in touch all the time they are active?
I'm using Arduino Uno as Transmitter with Funduino Joystick Shield, Arduino Due as Receiver. And I'm using RF24 Library v1.1.5
The Transmitter Code:
#include <JoystickShield.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 9
#define CSN_PIN 10
JoystickShield joystickShield;
const uint64_t pipe = 0xE8E8F0F0E1LL;
RF24 radio(CE_PIN, CSN_PIN);
byte movement;
String movementt;
void setup() {
radio.begin();
radio.openWritingPipe(pipe);
radio.stopListening();
Serial.begin(9600);
delay(100);
joystickShield.calibrateJoystick();
}
void loop() {
radio.startListening();
radio.available();
joystickShield.processEvents();
if (joystickShield.isUp()) {
radio.stopListening();
movement = 'U';
radio.write(&movement,1);
Serial.println(movement);
Serial.println(sizeof(movement));
}
if (joystickShield.isRightUp()) {
radio.stopListening();
movement = 'S';
}
if (joystickShield.isRight()) {
radio.stopListening();
movement = 'R';
}
if (joystickShield.isRightDown()) {
radio.stopListening();
movement = 'S';
}
if (joystickShield.isDown()) {
radio.stopListening();
movement = 'D';
}
if (joystickShield.isLeftDown()) {
radio.stopListening();
movement = 'S';
}
if (joystickShield.isLeft()) {
radio.stopListening();
movement = 'L';
}
if (joystickShield.isLeftUp()) {
radio.stopListening();
movement = 'S';
}
if (joystickShield.isJoystickButton()) {
radio.stopListening();
movement = 'J';
}
if (joystickShield.isUpButton()) {
radio.stopListening();
movement = 0;
radio.write(&movement,1);
}
if (joystickShield.isRightButton()) {
radio.stopListening();
movement = 'B';
}
if (joystickShield.isDownButton()) {
radio.stopListening();
movement = 'C';
}
if (joystickShield.isLeftButton()) {
radio.stopListening();
movement = 'D';
}
if (joystickShield.isEButton()) {
radio.stopListening();
movement = 'E';
}
if (joystickShield.isFButton()) {
radio.stopListening();
movement = 'F';
}
if (joystickShield.isNotCenter()){
radio.stopListening();
movement = 'N';
}
Serial.print("x ");
Serial.print(joystickShield.xAmplitude());
Serial.print(" y ");
Serial.println(joystickShield.yAmplitude());
radio.startListening();
delay(500);
}
The Receiver Code:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 7
#define CSN_PIN 8
#include <printf.h>
const uint64_t pipe = 0xE8E8F0F0E1LL;
RF24 radio(CE_PIN, CSN_PIN);
byte movement = 3;
String movementt;
void setup() {
radio.begin();
radio.openReadingPipe(1, pipe);
pinMode(13, OUTPUT);
Serial.begin(9600);
delay(100);
}
void loop() {
digitalWrite(13, LOW);
radio.startListening();
while (radio.available()) {
//Serial.println("While.");
radio.read(&movement, 1);
if(char(movement)== 'U'){digitalWrite(13,HIGH);}
Serial.println(char(movement));
}Serial.println("No radio.");
}