Hi,
I am trying to fix the problem of communicating two nRf24l01+ together, one connected to Arduino Uno and another connected to Atmega328PU with 8Mhz external crystal. The bootloader on Atmega328PU is “Arduino Pro or Pro Mini” 3.3V 8Mhz. The problem is the nRf24L01+ on Atmega328PU is not responding (working). I am using RF24 library as shown in the code below. There are several things that I already tried:
1- To make sure that both nRf24L01+ modules work, I connected one to Arduino Uno and another to Arduino Mega and they work perfectly. So, the problem is not from the nRf modules.
2- I changed the external crystal of atmega328PU to 16 Mhz and changed the bootloader to Arduino Uno. Didn’t work again.
The circuit diagram is shown below:
The Transmitter Code:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
const int btn = 4;
int buttonState = 0;
int programState = 0;
void setup() {
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
pinMode(btn, INPUT);
}
void loop() {
buttonState = digitalRead(btn);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if ((buttonState == LOW) && (programState == 0)) {
programState = 1;
}
else if((buttonState == HIGH)&& (programState == 1)){
const char text[] ="Hello World"; // you can customize this text to your wish
radio.write(&text, sizeof(text));
programState = 0;
Serial.println("BUTTON");
delay(1000);
}
}
The Receiver Code:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
const int output = 2;
void setup() {
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_MIN);
radio.startListening();
pinMode(output,OUTPUT);
digitalWrite(output, LOW);
delay(1000);
}
void loop() {
if (radio.available()) {
char text[32] = "";
radio.read(&text, sizeof(text));
Serial.println(text);
if (strcmp(text,"Hello World")==0){
Serial.println("CORRECT");
digitalWrite(output, HIGH);
delay(2000);
digitalWrite(output, LOW);
delay(2000);
}
}
}