Hello, I can't get my nRF24 modules to work, I know it is not the modules because I have bought more modules and they are also not working. These are my connections. GND - gnd, VCC - 3.3V, CE - 5, CSN - 10, SCK - 13, MOSI - 11, MISO - 12. I have also tried switching CE to 7 and CSN to 8 but no success. I am using the code from Robin2.
TRANSMITTER
// SimpleTx - the master or the transmitter
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <printf.h>
#define CE_PIN 5
#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);
printf_begin();
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() {
radio.stopListening();
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;
}
RECIEVER
// SimpleRx - the slave or the receiver
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 5
#define CSN_PIN 10
const byte thisSlaveAddress[5] = {'R','x','A','A','A'};
RF24 radio(CE_PIN, CSN_PIN);
char dataReceived[10]; // this must match dataToSend in the TX
bool newData = false;
//===========
void setup() {
Serial.begin(9600);
Serial.println("SimpleRx Starting");
radio.begin();
radio.setDataRate( RF24_250KBPS );
radio.openReadingPipe(1, thisSlaveAddress);
radio.startListening();
}
//=============
void loop() {
getData();
showData();
}
//==============
void getData() {
if ( radio.available() ) {
radio.read( &dataReceived, sizeof(dataReceived) );
newData = true;
}
}
void showData() {
if (newData == true) {
Serial.print("Data received ");
Serial.println(dataReceived);
newData = false;
}
}
I am also using the library from Robin2's nRF24 demo.
I have the VCC connected to 3.3V and I have checked that my Arduino gives of 3.3V. When I run the SimpleTx code I get "Data Sent Message 0 Tx failed" in the Serial Monitor. When I run the SimpleRx code I get "Data received" in the Serial Monitor. I do not get any message in the Arduino logs other than "avrdude done. Thank you." so I guess there are no syntax problems. If you could help me out I would greatly appreciate it. Thanks in Advance :). I used this library - https://tmrh20.github.io/RF24/ and I got the code from here - Simple nRF24L01+ 2.4GHz transceiver demo - Exhibition / Gallery - Arduino Forum
Thanks for the reply, I tried the check connection code and I am getting this
"
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
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 too was having trouble with the NRF24L01+ modules and it all boiled down to incorrect wiring and poor connections with the fly leads (especially with a breadboard). Check and check again. One of them is working so you know the script is good on that arduino; try swapping the NRF24’s and see if the same arduino still works. If it does that shows the NRF24’s are ok.