I am trying to transfer data with the Nrf24l01. I'm working with an Arduino Mega for shipping and an Arduino Uno for reading. I have never been able to create or find a working program on the internet. I've done everything as stated in this topic: Simple nRF24L01+ 2.4GHz transceiver demo.
I don't know the Arduino Mega is properly connected.
VCC - 3.3V
GND-GND
CE - PWMpin 10
CSN - PWMpin 9
SCK - DIGITALpin 52
MOSI - DIGITALpin 51
MISO - DIGITALpin 50
Message printed at the sender: "Tx failed"
Message printed to the reader: "SimpleRx Starting"
program transmitter (MEGA)
// SimpleTx - the master or the transmitter
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 9
#define CSN_PIN 10
const byte slaveAddress[5] = {'R','x','A','A','A'};
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
char dataToSend[10] = "Message 0";
char txNum = '0';
unsigned long currentMillis;
unsigned long prevMillis;
unsigned long txIntervalMillis = 1000; // send once per second
void setup() {
Serial.begin(9600);
Serial.println("SimpleTx Starting");
radio.begin();
radio.setDataRate( RF24_250KBPS );
radio.setRetries(3,5); // delay, count
radio.openWritingPipe(slaveAddress);
}
//====================
void loop() {
currentMillis = millis();
if (currentMillis - prevMillis >= txIntervalMillis) {
send();
prevMillis = millis();
}
}
//====================
void send() {
bool rslt;
rslt = radio.write( &dataToSend, sizeof(dataToSend) );
// Always use sizeof() as it gives the size as the number of bytes.
// For example if dataToSend was an int sizeof() would correctly return 2
Serial.print("Data Sent ");
Serial.print(dataToSend);
if (rslt) {
Serial.println(" Acknowledge received");
updateMessage();
}
else {
Serial.println(" Tx failed");
}
}
//================
void updateMessage() {
// so you can see that new data is being sent
txNum += 1;
if (txNum > '9') {
txNum = '0';
}
dataToSend[8] = txNum;
}
I attached a rf24 module to my Mega and another to an Uno wired according to your code. I uploaded your code, without any changes, to the Mega and Uno. The code works fine on my setup.
The transmitter (Mega) prints in serial monitor:
Data Sent Message 0 Acknowledge received
Data Sent Message 1 Acknowledge received
Data Sent Message 2 Acknowledge received
Data Sent Message 3 Acknowledge received
Data Sent Message 4 Acknowledge received
From the reciever serial monitor prints:
Data received Message 0
Data received Message 1
Data received Message 2
Data received Message 3
Data received Message 4
So the code looks OK.
Looks like you may have miswired the CE and CSN pins?
In the text of your post (Mega wiring):
CE - PWMpin 10
CSN - PWMpin 9
In your code:
#define CE_PIN 9
#define CSN_PIN 10
Reply #30 in the simple rf24 tutorial has a program to test the wired connection between the processor and the radio module.
@ Railroader has a good point. The number one problem with using the rf24 modules is adequate power as pointed out in Robin2's simplerf24 tutorial. My rf24 modules have their own 3.3V regulators (LM1117 3.3) powered from the Arduino 5V. Like these adapters.
I have checked the wirering of the Arduino with this program (#30)
The Serial monitor prints this, but I don't know what it means:
CheckConnection Starting
FIRST WITH THE DEFAULT ADDRESSES after power on
Note that RF24 does NOT reset when Arduino resets - only when power is removed
If the numbers are mostly 0x00 or 0xff it means that the Arduino is not
communicating with the nRF24
I would say that there is a problem with communication between the processor and the radio module. Like Robin says in the post, if there are all zeros, there is a problem. Either bad module(s) or wiring. I actually got a batch of bad modules a couple of years ago. They would send but not receive ( or vice-versa, I don't remember).
Post clear photos of the wiring of your modules. Make sure that we can see where each wire goes. A photo of jumbled wiring has no value.
Did you see the issue with the CE and CSN pins that I pointed out in reply #2?