Hi there,
basically, I have two nRF24 with antennas and I'm trying to make them comunicate.
The transmitter is linked to a solo atmega328p with external 16mherz clock, the receiver is on an arduino UNO board.
This is the code for the Transmitter, on pin 8 I have a LED which blinks every second.
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7,8); //CE - CSN
const byte address[6] = "00001"; //Pipe
void setup() {
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MAX);
radio.setDataRate(RF24_250KBPS);
radio.stopListening();
}
void loop() {
digitalWrite(9, HIGH);
delay(1000);
digitalWrite(9, LOW);
delay(1000);
const char text[] = "nrftest";
radio.write(&text, sizeof(text));
}
And this is the code for the receiver:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7,8); //CE - CSN
const int led1 = 5;
const int led2 = 3;
const byte address[6] = "00001";
void setup() {
// put your setup code here, to run once:
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
radio.begin();
radio.openReadingPipe(1,address);
radio.setPALevel(RF24_PA_MAX);
radio.setDataRate(RF24_250KBPS);
radio.startListening();
}
void loop() {
char text[32] = "";
String transData = "Yolo";
if (radio.available()) {
radio.read(&text, sizeof(text));
transData = String(text);
if (transData == "nrftest") {
digitalWrite(led1, HIGH);
delay(500);
digitalWrite(led1, LOW);
delay(500);
}
else{
digitalWrite(led2, HIGH);
delay(500);
digitalWrite(led2, LOW);
delay(500);
}
}
}
Now, here is what happens:
-
When I power up the receiver, but not the transmitter led2 starts blinking so radio.available() == true, that's the first thing I don't understand;
-
When I power up the transmitter too led2 stops blinking and nothing happens;
-
Led1 (Comunication succesfull) does never blink;
Can someone help me to make them comunicate properly and explain me what's happening? Thanks a lot.
This is the schematics, I know It's kinda bad, but I couldn't find any other software, sorry: