Hello, I'm super new to using Arduino, so my level of knowledge is pretty much just what I can decode from tutorials.
I cannot seem to get my NRF24L01+ modules to communicate with each other, and I can't figure out what the problem is.
I'm using two Arduino Unos, each with an NRF (see wiring diagram).
I've been trying to use a variety of codes to get it to work, and I followed Robin2's Simple tutorial here, trying several of their sample codes, every one giving me a variety of error codes and/or nonresponses. Here's the SimpleTx and SimpleRx codes I've been using for my master and slave, respectively:
// SimpleTx - the master or the transmitter
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 5
#define CSN_PIN 7
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");
pinMode(10,OUTPUT);
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 intend on using the SS pin for a secondary device on my master, which is why I switched the pins around. However, I've done no such thing for the slave Uno and that seems to make no difference)
The error I get with this is
SimpleTx Starting
Data Sent Message 0 Tx failed
Data Sent Message 0 Tx failed
Data Sent Message 0 Tx failed
Data Sent Message 0 Tx failed
Data Sent Message 0 Tx failed
Over and over again, about once a second.
For the slave:
// SimpleRx - the slave or the receiver
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 9
#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;
}
}
And the only thing I get in the serial monitor is:
SimpleRx Starting
I have about 10 NRF24 modules that I've switched out, four of which I've soldered 10uf capacitors onto the GND and VCC pins just in case, and I also have a spare Uno that I've switched out as well.
I've also tried rolling back the RF24 library to the 1.1.17 that was suggested in that thread, and I've tried the Getting Started code, as well as Robin's ackPayload example in that same thread.
I've also tried the Check Connection code that was posted
// 18 Mar 2018 - simple program to verify connection between Arduino
// and nRF24L01+
// This program does NOT attempt any communication with another nRF24
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <printf.h>
#define CE_PIN 9
#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);
printf_begin();
Serial.println("CheckConnection Starting");
Serial.println();
Serial.println("FIRST WITH THE DEFAULT ADDRESSES after power on");
Serial.println(" Note that RF24 does NOT reset when Arduino resets - only when power is removed");
Serial.println(" If the numbers are mostly 0x00 or 0xff it means that the Arduino is not");
Serial.println(" communicating with the nRF24");
Serial.println();
radio.begin();
radio.printDetails();
Serial.println();
Serial.println();
Serial.println("AND NOW WITH ADDRESS AAAxR 0x41 41 41 78 52 ON P1");
Serial.println(" and 250KBPS data rate");
Serial.println();
radio.openReadingPipe(1, thisSlaveAddress);
radio.setDataRate( RF24_250KBPS );
radio.printDetails();
Serial.println();
Serial.println();
}
void loop() {
}
And I get the results:
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
STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1 = 0x000000001c 0x0000000070
RX_ADDR_P2-5 = 0x38 0x38 0x1c 0xc6
TX_ADDR = 0x6c6c6c6cec
RX_PW_P0-6 = 0xe0 0x1c 0xe0 0x38 0x38 0x1c
EN_AA = 0x3f
EN_RXADDR = 0x1c
RF_CH = 0x38
RF_SETUP = 0x1c
CONFIG = 0x08
DYNPD/FEATURE = 0x38 0x38
Data Rate = 2MBPS
Model = nRF24L01
CRC Length = 8 bits
PA Power = PA_HIGH
AND NOW WITH ADDRESS AAAxR 0x41 41 41 78 52 ON P1
and 250KBPS data rate
STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1 = 0x000000001c 0x0000000070
RX_ADDR_P2-5 = 0x38 0x38 0x1c 0xc6
TX_ADDR = 0x6c6c6c6cec
RX_PW_P0-6 = 0xe0 0x1c 0xe0 0x38 0x38 0x1c
EN_AA = 0x3f
EN_RXADDR = 0x1c
RF_CH = 0x38
RF_SETUP = 0x1c
CONFIG = 0x08
DYNPD/FEATURE = 0x38 0x38
Data Rate = 2MBPS
Model = nRF24L01
CRC Length = 8 bits
PA Power = PA_HIGH
Which to me says it has a clear connection?
I really though it was my hardware, but I've double and triple checked my connections, switched out my wires, switched out my microcontrollers, added capacitors, and cycled through all 10 of my RF24s... so it must be something with my setup. Any help appreciated.