RF24 by TMRh20, problems using radio.write() and radio.available()

Hi.

My project require communication between two arduino unos, so i'm using the nRF24L01 transreciever with the base module NRF24LD1 and the TMRh20 library (v3.0) available through library manager in Arduinos IDE . I've tried a lot of different approaches but i simply cannot get anything to work.

Physical setup:

Using the standard pins:
7 - CE
8 - CSN
13 - SCK
11 - MO
12 - MI

the reciever code:

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(7, 8);

const byte rxAddr[6] = "00001";

void setup()
{
  while (!Serial);
  Serial.begin(9600);
  
  radio.begin();
  
  radio.openReadingPipe(0, rxAddr);
  radio.startListening();
}

void loop()
{
  if (radio.available())
  {
    char text[32] = {0};
    radio.read(&text, sizeof(text));
    Serial.println("text: ");
    Serial.print(text);
    
  }
}

The transmitter code:

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(7, 8);

const byte rxAddr[6] = "00001";

void setup()
{
  Serial.begin(9600);
  radio.begin();
  radio.setRetries(15, 15);
  radio.openWritingPipe(rxAddr);
  
  radio.stopListening();
}

void loop()
{
  const char text[] = "Hello World";
  Serial.println("pre");
  radio.write(&text, sizeof(text));
  Serial.println("post");
  delay(1000);
}

For the reciever I have this problem:
No matter what i do, the radio.available() returns true, even though there are no transmitter sending data. I can remove all wires completely so the arduino is blank, but still the radio.available() returns true. (the serial monitor shows infinite of "text: ")

For the transmitter I have this problem:
The program stops at the radio.write(), (the serial monitor only show "pre"). If I pull out the nRF24L01 module from the base socket, the program goes past the .write() function, but then it obviously dosn't send any data, (the serial monitor shows "pre, post" in one second interval).

I know the hardware is working, I got a fellow student to upload his code, used for controlling a drone, to my arduino, and it worked fine. Unfortunately he is not using the TMRh20 library, but some other library made specially for the drone, using other pins etc.

So far i have:

  • Tried three different arduinos, all behave the same.
  • powered up the circuit by an external powersupply 5 V.
  • Installed previous version of TMRh20 library (v2.0).
  • Looked over (100 times) that pins are correctly wired.
  • tried most of the example codes from different places, none of them made any differance
  • tried th use the ICSP pins instead of 11,12,13 pin
  • measured the resistance of the wires

If someone can point out a obvious mistake I've made, I couldn't be more happy. I simply do not know any more things to check for. For me it sounds like a hardware connection error, but if it is, I can't find it.

F-LJ:
No matter what i do, the radio.available() returns true, even though there are no transmitter sending data.

You probably have a wiring error.

F-LJ:
I can remove all wires completely so the arduino is blank, but still the radio.available() returns true.

That is a wiring error.

Whandall:
That is a wiring error.

Well, obviously correct : ). My guess was that the .available() function would return false if there was nothing attached to the arduino. Is that not the case?

F-LJ:
My guess was that the .available() function would return false if there was nothing attached to the arduino. Is that not the case?

No.

The garbage returned from the SPI requests to nonexistant slaves is often interpreted as 'available()'.

I can remove all wires completely so the arduino is blank, but still the radio.available() returns true.

There is an interesting lesson in that result!

Have a look at this Simple nRF24L01+ Tutorial.

It can sometimes be useful to power off the Arduino after uploading a program in order to cause the nRF24 to reset.

However, like the others I suspect a wiring error or perhaps a faulty nRF24

...R

Thank you for suggestions :slight_smile: I've read the post you linked to, and found it helpful, but it didn't solve my problem though.

I'm quite sure the wiring is correct according to the list in first post. I've measured the resistance of the wires and they are ok. Earlier today i've tested the hardware (wires, arduino, nRF24LD1 and nRF24L01) on my fellow students code and drone, and it worked.

I cannot understand what else there is to do about the hardware. Any suggestion of things i've might overlooked or a different approach to the problem?

Can the problem be caused by somthing other than hardware?

F-LJ:
Thank you for suggestions :slight_smile: I've read the post you linked to, and found it helpful, but it didn't solve my problem though.

Did you try any of my examples? if so tell me which one and tell me exactly what happened when you tried it.

I'm quite sure the wiring is correct according to the list in first post. I've measured the resistance of the wires and they are ok. Earlier today i've tested the hardware (wires, arduino, nRF24LD1 and nRF24L01) on my fellow students code and drone, and it worked.

You need to describe EXACTLY what you did in as much detail as possible, including the wiring diagrams and the programs used

Did you try both of your own nRF24L01+ modules with the drone?

I presume "nRF24LD1" is a typo

...R

I've tried your code yesterday, didn't get it to work then. I'll try again tomorrow and will give you more details :slight_smile:

The code and wiring diagram for the drone is not important, the point is that the hardware is working. Did only test one of the nRF24 circuits, though. I'll do some more testing and provide more details tomorrow.

nRF24LD1 = what i thought was the name of the base module which you plug the nRF24L01 circuit into. I now understand that the "D" was a misread "0". :slight_smile:

Thank you for your help.

F-LJ:
The code and wiring diagram for the drone is not important, the point is that the hardware is working.

To my way of thinking it is vitally important.

Presumably there was something different in the code or the wiring that allowed it to work. Unless, of course, the problem is a fault in the module you did not try.

...R

I think I know what the problem is. The IC om my RF sender is nRF24L01 and not the "+" version. The non+ version is a bit older, and i suspect it is not compatible with the TMRh20 library. Someone who can confirm this?

If that's the case, do anyone know what the difference is regarding SPI interface between the + and non+ version. Is it possible to make a minor change to the library to make it work?

Update: Found this library, and it worked perfectly. Looks like the TMRh20 library is not compatible with the non+ version.