4

I am trying to fix the problem of communicating between two nRF24L01+ together, one connected to an Arduino Uno and another connected to an ATmega328PU with an 8 MHz external crystal.

The bootloader on the ATmega328PU is “Arduino Pro or Pro Mini” 3.3 V, 8 MHz.

The problem is that the nRF24L01+ on the ATmega328PU is not responding (working). I am using the RF24 library as shown in the code below.

There are several things that I have already tried:

  1. To make sure that both nRF24L01+ modules work, I connected one to an Arduino Uno and another to an Arduino Mega and they work perfectly. So, the problem is not with the nRF modules.
  2. I changed the external crystal of the ATmega328PU to 16 MHz and changed the bootloader to Arduino Uno; didn’t work again.

The circuit diagram is shown below:

enter image description here

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)&amp;&amp; (programState == 1)) {
  const char text[] =&quot;Hello World&quot;; // you can customize this text to your wish
  radio.write(&amp;text, sizeof(text));
  programState = 0;
  Serial.println(&quot;BUTTON&quot;);

  delay(1000);

} }

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); }
} }

ocrdu
  • 1,795
  • 3
  • 12
  • 24
Jon depoy
  • 61
  • 3

1 Answers1

0

Assuming a basic test of the MCU works, say the blink sketch works at normal speed (0.5 Hz), try this format of the constructor:

RF24 radio(7, 8, 4000000); // set SPI speed to 4MHz instead of default 10MHz

The default of 10MHz maybe too high for your MCU configuration.

From https://github.com/nRF24/RF24/blob/master/COMMON_ISSUES.md

Some more things to try:

EDIT

Most Nrf24L01 problems are related to an inadequate power supply. Some 3.3 volt power supplies, say those of a Nano where the 3.3 volts is derived from the USB/UART adaptor, don't work well here. You could try adding two capacitors across the power rails at the point on the breadboard where the power for the nrf24L01 is taken. Use a 100nF ceramic and a 10 to 100uF electrolytic. You barebones atmega328p should anyway have its own decoupling capacitor as close as possible to the chip's power pins. Use a 100nF ceramic.

The link above has other trouble shooting measures.

6v6gt
  • 1,192
  • 6
  • 8