Im working on a project with 2 Arduino nanos, each with its own NRF24l01. The transmitter has 2 buttons and a joystick, and the receiver is connected to a motor driver. Everything seems to be working (and was actually working when I tested it on a breadboard), but now the radios won't communicate.
This is the transmitter code:
#include "nRF24L01.h" // NRF24L01 library created by TMRh20 https://github.com/TMRh20/RF24
#include "RF24.h"
#include "SPI.h"
int SentMessage[1] = {000};
RF24 radio(9,10);
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
#define Button1 2
#define Button2 3
int button1=0;
int button2=0;
int xPosition = 0;
int yPosition = 0;
int directionX;
int directionY;
const int x_pin = A1;
const int y_pin = A2;
void setup() {
pinMode(Button1, INPUT);
pinMode(Button2, INPUT);
pinMode(x_pin, INPUT);
pinMode(y_pin, INPUT);
Serial.begin(9600);
pinMode(Button1, INPUT_PULLUP);
digitalWrite(Button1,HIGH);
pinMode(Button2, INPUT_PULLUP);
digitalWrite(Button2, HIGH);
radio.begin();
//radio.openWritingPipe(pipe);
radio.openWritingPipe(pipes[0]);
radio.openReadingPipe(1,pipes[1]);
}
This is the receiver code:
#include "nRF24L01.h" // NRF24L01 library created by TMRh20 https://github.com/TMRh20/RF24
#include "RF24.h"
#include "SPI.h"
int ReceivedMessage[1] = {000};
RF24 radio(9,10);
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
#define MotorIN1 2
#define MotorIN2 3
#define ENA 5
#define MotorIN3 7
#define MotorIN4 4
#define ENB 6
int pwmSignal = 0;
void setup(void) {
pinMode(MotorIN1, OUTPUT);
pinMode(MotorIN2, OUTPUT);
pinMode(ENA, OUTPUT);
Serial.begin(9600);
radio.begin(); // Start the NRF24L01
radio.openWritingPipe(pipes[1]);
radio.openReadingPipe(1,pipes[0]);
radio.startListening(); // Listen to see if information received
}
next in the receiver I have this:
void loop(void) {
while (radio.available()){
but the loop never seems to start? Im thinking that this is either because:
- The transmitter never transmits
- The receiver never receives
- One of the radio is not operating
Please help ! Im at a loss