Problem: I cannot successfully execute the "Simple one way transmission" demo code from Post #2 of Simple nRF24L01+ 2.4GHz transceiver demo. The transmit side reads endless lines of "Data Sent Message 0 Tx failed" while the receive side shows only "SimpleRx Starting."
Background: I have been attempting to learn how to use RF transmitters for an upcoming project. I started with DroneBot Workshop's tutorial followed by the How to Mechatronics Tutorial. After a string of failures with the aforementioned tutorials, I found Robin2's "Simple one way transmission" tutorial. After those demo codes failed to yield desirable results, I began further troubleshooting. I have spent the past few weeks pouring over similar forum inquiries and applying the suggestions to my problem. This was to no avail.
Setup:
I am using the NRF24L01+PA+LNA modules with the external antenna and the necessary breakout boards. They are connected to Arduino Unos (1 genuine, 1 clone by ArdiBot) and powered with external 12V power supplies. Both systems are exact copies of each other and one of the setups is pictured below.
Code:
Transmit
// 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.setDataRate( RF24_1MBPS );
radio.setRetries(3,5); // delay, count
radio.openWritingPipe(slaveAddress);
//radio.setAutoAck(false);
//radio.setPALevel(RF24_PA_MIN);
}
//====================
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;
}
Receive
// 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.setDataRate( RF24_1MBPS );
radio.openReadingPipe(1, thisSlaveAddress);
radio.startListening();
//radio.setAutoAck(false);
//radio.setPALevel(RF24_PA_MIN);
}
//=============
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;
}
}
Serial Monitor:
Transmit
SSimpleTx 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
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
Data Sent Message 0 Tx failed
Data Sent Message 0 Tx failed
Data Sent Message 0 Tx failed
Receive
SimpleRx Starting
Diagnostic Output from CheckConnection.ino
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
SPI Speedz = 10 Mhz
STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1 = 0x4141417852 0x65646f4e32
RX_ADDR_P2-5 = 0x33 0xce 0x3e 0xe3
TX_ADDR = 0x4141417852
RX_PW_P0-6 = 0x20 0x20 0x20 0x20 0x20 0x20
EN_AA = 0x3f
EN_RXADDR = 0x03
RF_CH = 0x4c
RF_SETUP = 0x03
CONFIG = 0x0e
DYNPD/FEATURE = 0x00 0x00
Data Rate = 1 MBPS
Model = nRF24L01+
CRC Length = 16 bits
PA Power = PA_LOW
ARC = 5
AND NOW WITH ADDRESS AAAxR 0x41 41 41 78 52 ON P1
and 250KBPS data rate
SPI Speedz = 10 Mhz
STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1 = 0x4141417852 0x4141417852
RX_ADDR_P2-5 = 0x33 0xce 0x3e 0xe3
TX_ADDR = 0x4141417852
RX_PW_P0-6 = 0x20 0x20 0x20 0x20 0x20 0x20
EN_AA = 0x3f
EN_RXADDR = 0x03
RF_CH = 0x4c
RF_SETUP = 0x23
CONFIG = 0x0e
DYNPD/FEATURE = 0x00 0x00
Data Rate = 250 KBPS
Model = nRF24L01+
CRC Length = 16 bits
PA Power = PA_LOW
ARC = 5
Attempted Fixes:
- using breakout boards instead of direct wiring with a filter capacitor
- using other nRF24 modules (rotated through 6 total)
- cutting power to modules after each new upload
- adjusting power [radio.setPALevel(RF24_PA_MIN))
- adjusting data rate [radio.setDataRate( RF24_250KBPS ); & radio.setDataRate( RF24_1MBPS ))
- changing auto acknowledge (radio.setAutoAck(false))
In closing, this is my first post. My apologies in advance for any formatting errors or if I forgot to include anything. Any help is greatly appreciated.