Hi,
I have been slowly going absolutely crazy trying to work out what I am doing wrong.
I have two Arduino Unos and two nRF24l01+s.
I have been messing with my own simple examples gleaned from here and elsewhere with no luck. I just get randon characters appearing on the serial monitor. I wrongly assumed I had a duff uno board or transceivers and ordered new parts. They arrived today and have connected together all new parts and I am still not getting the damn things to work!
I decided to use Robin2's Simple nRF24L01+ 2.4GHz transceiver demo.
I downloaded and installed the RF24-Master library from Github. Made sure there were no older versions of the library.
I have checked, rechecked, triple checked and quadruple checked the connections between the Unos and the transceivers. ( I even got my wife to check them!!!!)
I have copied and pasted the codes for Tx and Rx, from Robin's tutorial:
Tx or Master
[code]
// SimpleTx - the master or the transmitter
[code][code]
// SimpleTx - the master or the transmitter
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 8
#define CSN_PIN 9
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;
}
[/code]
And for the Rx or Slave:
[code]
// SimpleRx - the slave or the receiver
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 8
#define CSN_PIN 9
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;
}
}
[/code]
Here is the output from the serial monitor:
Data Sent Message 0 Tx failed
Data Sent Message 0 Acknowledge received
Data Sent Message 1 Tx failed
Data Sent Message 1 Acknowledge received
Data Sent Message 2 Tx failed
Data Sent Message 2 Acknowledge received
Data Sent Message 3 Tx failed
Data Sent Message 3 Acknowledge received
Data Sent Message 4 Tx failed
Data Sent Message 4 Acknowledge received
Data Sent Message 5 Tx failed
Data Sent Message 5 Acknowledge received
Data Sent Message 6 Tx failed
Data Sent Message 6 Acknowledge received
I am at my wit's end. If anybody could give me any hints tips, advice....As I say I have re-checked connections, even turned my wi-fi off, all new components.
CHeers
Steve
If you are powering the radios from the UNO's 3.3V pin, that may be the issue - simply not enough juice to reliably run the radios. Please post more info about the modules and the wiring.
Danois90,
Initially I was using the adapter board for the transceivers which have a 5V supply and a 3.3V regulator onboard.
The result was the same using those adapters, I suspected that one of those might be u/s so ditched them!
At this stage I would prefer if the OP makes no changes to my Tutorial code - it works as it is and an inexperienced person making changes can unwittingly introduce problems.
I note that the OP has in fact thought he could improve on a working program by changing the pin numbers.
@stevetyphoon, get the Tutorial programs working with no changes first. After that you can do what you want.
A common problem with nRF24 modules is insufficient 3.3v current from the Arduino 3.3v pin. This seems to be a particular problem with the nano. The high-power nRF24s (with the external antenna) will definitely need an external power supply. At least for testing try powering the nRF24 with a pair of AA alkaline cells (3v) with the battery GND connected to the Arduino GND.
If you are using the high-power nRF24s (with the external antenna) make sure there is sufficient distance between the two nRF24s so that the signal does not overwhelm the receiver - try 3 metres separation. If you are new to nRF24s it may be better to start with a pair of low power modules with the pcb antenna.
Robin2...Apologies for altering your code...I changed the pin numbers because my big fat fingers had trouble cramming the dupont pins in and had those other pin numbers from previous sketches!
I have run the communication test sketch as is. Result mainly zeros.
Then I have gone back to using the adapter board to ensure a good supply to the transceivers.
I have used combinations of 3 x 6Unos, 6x transceivers and 2x adapter boards.
Oh, and unplugging supply to Uno board after uploading sketch.
The result is mainly zeros.
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 am using the small transceivers without the power amp and big antenna.
I have had a lot of success with my projects in the past and usually can solve problems without asking for help...
I have built a mini-ROV with two Arduinos and RS485 serial comms, a big light show using addressable led strips, so I am not a complete novice and pretty confident that I am doing everything as I should!
Thanks for all the suggestions so far....As I said, I am completely flummoxed!
The first thing to do is to limit your options - too many options is just confusing.
If you have two Unos that work normally (with other programs) then stick with them.
Pick one of the Unos and get the connection test working with it - maybe you need to try two nRF24s, but unless you have done something weird I would not expect you to have more than one faulty device.
The most common cause of a failure of the connection test is incorrect wiring or loose connections. Because the test does not attempt to use the radio there should not be a power problem - but if you think there may be then use a couple of AA alkaline cells (3v) to power the nRF24.
Robin and others,
I've got it sorted!
All of the three original transceivers do not work, a bad batch by the look of it.
I connected up the new ones without using the adapter board with the results above then thought about the 3.3V supply not being enough so used the adapter boards again and YES, it works.
All the new ones do work.
Thanks for all your help, much appreciated.
Cheers
I got a bad batch of rf24s a while back. A single blob replaced the IC on the RF24s that I got before. Through testing with known good rf24s I found that they would receive but not transmit.