Would someone please test this

I am trying to get the simple RF Rx/Tx sketches from the Starter Kit page to run - without success. The Rx sketch is

#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);
  }
}

The only change I have made to it is to comment out line 11 ( //while (!Serial); ) which I did because, as I understand that code, it would simply stall the sketch in setup().

The Tx sketch is

#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";
  radio.write(&text, sizeof(text));

  Serial.print("Sending ");
  Serial.println(text);

  delay(1000);
}

In this sketch I have instantiated Serial and called it to send a message during loop().

I have compiled these and uploaded them. My setup is Arduino 1.6.12, RF24(TMRh20) v. 1.1.7, Firmata v. 2,5,4, AVTBoards v. 1.6.13.

Serial Monitor for the Rx side prints nothing. On the Tx side it produces

Sending Hello World
Sending Hello World

Bizarrely it seems that the Tx sketch loops twice and then stops. In any case there is no communication.

Would some kind soul please try this out and let me know what happens for you. I have no idea what is wrong here and I’d like to know if you get the same result.

Thanks

I think it would be extremely useful if you told us which board(s) you use. while(!Serial) is only needed useful on specific boards (32U4 based as far as I know, definitely not on Unos and Megas).

it would simply stall the sketch in setup().

It checks (on those specific boards) if a connection between a computer and the Arduino has been established and only continues if it has.

Try adding this to TX setup():

radio.setPALevel( RF24_PA_MIN );

It reduces TX transmit power, if the radios are close together, full power may swamp the receiver.

Try the examples in this Simple nRF24L01+ Tutorial. They do work!

...R

Thanks to all

sterretje
The Arduino boards I am using are UNOs. The RF boards are nRF24L01s.

outsider
I’ll try that.

robin2
I have tried those programs (I have been working towards progressively simpler sketches), and I have similar problems. No communication.
Those two programs we agonized over (Trolley and Console) worked perfectly one morning, did not work that night, and haven’t worked since. I am trying to find out why.
There is some suggestion that an Arduino update has changed things. I have replaced all the hardware (in case I blew something up) and this is not my code. That really only leaves the development environment.

That’s why I would like an independent check on the current code.

OK, in that case while(!Serial); will not stall your setup() function; it also serves no purpose on an Uno board and it's not the cause of possible issues.

vagulus: Those two programs we agonized over (Trolley and Console) worked perfectly one morning, did not work that night, and haven't worked since. I am trying to find out why. There is some suggestion that an Arduino update has changed things. I have replaced all the hardware (in case I blew something up) and this is not my code. That really only leaves the development environment.

If this is a continuation of that project then WHY have you started another Thread. It is much easier to help if I can scroll back and read other stuff I (and others) have said.

I have tried those programs (I have been working towards progressively simpler sketches),

I hope it will be difficult to make my examples simpler - I put a lot of thought into making them simple.

From your other Thread (now locked, thankfully)

I am desperate for answers so I am attacking the problem from different angles in the hope of some inkling of a solution.

The shotgun approach to debugging never works - especially with wireless problems. You must be systematic. Eliminate possibilities one at a time.

...R

Hi robin2

This thread is about getting communication between two UNOs, via nFR24L01s, at what must be the most basic level. Right now, I cannot achieve that. When I can achieve that I hope to progress to the point where I can return to the older project and get that going again.

I added some Serial debug output to StarterRx

#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.setPALevel( RF24_PA_MIN );
  
  radio.openReadingPipe(0, rxAddr);
  radio.startListening();
}

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

    Serial.print("This was available : ");
    Serial.println(text);
  }
  else
  {
    Serial.println("Nothing available");
    delay(2000);
  }
}

This, without StarterTx being powered up, produces the output

This was available : 
This was available : 
This was available : 
This was available : 
This was available : 
This was available : 
This was available : 
This was available : 
This was available : 
This was available : 
This was available : 
This was available : 
This was available : 
This was available : 
This was available : 
This was available : 
This was available : 
This was available : 
This was available : 
This was available : 
This was available : 
This was available : 
This was available : 
This was available : 
This was available : 
This was available : 
This was available : 
This was available : 
This was available : 
This was available : 
This was available : 
This was available : 
This was available : 
This was available : 
This was available : 
This was available : 
This was available : 
This was available :

This must mean that the code line 25

  • if (radio.available())*
    is not being executed as it should.

What would cause that?

Try printing some markers, perhaps > and < around the text variable to see if anything not visible is there.

Here it is:

#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.setPALevel( RF24_PA_MIN );
  
  radio.openReadingPipe(0, rxAddr);
  radio.startListening();
}

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

    Serial.print("This was available : >");
    Serial.print(text);
    Serial.println("<");
  }
  else
  {
    Serial.println("Nothing available");
    delay(2000);
  }
}

returns

This was available : ><
This was available : ><
This was available : ><
This was available : ><
This was available : ><
This was available : ><
This was available : ><
This was available : ><
This was available : ><
This was available : ><
This was available : ><
This was available : ><
This was available : ><
This was available : ><
This was available : ><
This was available : ><
This was available : ><
This was available : ><
This was available : ><
This was available : ><
This was available : ><
This was available : ><
This was available : ><
This was available : ><
This was available : ><
This was available : ><
This was available : ><
This was available : ><

If you try one of my examples (which I am very familiar with) and it does not work it will be much easier to help.

Trying to figure out what is wrong with another program is a bit like looking for a needle in a haystack.

...R

Hi [robin2[/b]

I am sure these are yours:

SlaveSwapRoles reports

SlaveSwapRoles Starting
Data received

Just one cycle, no repeat. MasterSwapRoles reports

Data Sent Message 0  Acknowledge received
Data received 0, 0

Data received 0, 0

Data received 0, 0

Data received 0, 0

Data received 0, 0

Data received 0, 0

Data received 0, 0

Data received 0, 0

Data received 0, 0

Data received 0, 0

Data received 0, 0

Data received 0, 0

Data received 0, 0

Data received 0, 0

Data received 0, 0

There is a top line which contains some strange character (the ‘y’ has two dots over it like an umlaut):

…yMasterSwapRoles Starting

SlaveSwapRoles.ino (1.94 KB)

MasterSwapRoles.ino (1.99 KB)

This morning I set up as mirror set of Arduinos at College, mirroring the setup at Home. These are: Arduino IDE v 1.6.12; RF24(TMRh20) v. 1.1.7; Firmata v. 2.5.4; AVR Boards v. 1.6.13.

I compiled and uploaded the two pairs of sketches I have posted in this thread, neither worked. I get the same garbage results I get at Home. I am not posting them here because I am working with a laptop and cutting and pasting is a hassle.

I did not write this code, the Arduino sets are (to the best of my ability) identical, the PCBs used are new, the sets are independent and separate. I am forced to the conclusion that something has changed in the Arduino IDE which has stopped these things working. My questions are "What has changed?", and "How can I fix it?"

That is why the headline of this thread asks for someone independent to try running these programs. I'd like to know if they work for you, then, if they do, why they do not work for me. I know it is asking someone to walk the extra mile for me but I am certain that, if the boot were on the other foot, I would oblige.

I really need some help here.

Thanks

"How can I fix it?"

Download and install an earlier version of the IDE to test your hypothesis

I notice that in this morning's post I forgot to say that the boards are UNOs and the RF PCBs are nRF24L01s.

UKHeliBob When my working code stopped working it was recommended that, to cure the problem, I should update to the IDE v. 1.6.12 - which I have done. I think I was on 1.6.10 before that, but the change didn't fix the problem.

Perhaps I should not have specifically named the IDE as the culprit as I should have included all the other packages associated with it and which get updated every now and then (AVR Boards and Firmata being examples). Since [u]downdating[/u] all these things would get me into a complexity way beyond my comprehension I am really reluctant to try it.

What is the latest IDE version that you know it worked on ? You could install that as a test. I have resisted the temptation to upgrade the IDE until I want/need any of the features that the newer versions provide.

I have been doing all my programming with IDE 1.6.3 and, before that, 1.5.6-r2

I will look at the programs in Reply #11 later today. However you should try the simpler first programs in my tutorial first.

Maybe you are suffering from radio interference. Have you tried changing your nRF24s to work on a different channel? However that seems less likely if you have the same problem at two locations.

When you put together the college apparatus did you use different nRF24s from the ones you used at home - to eliminate the possibility of a faulty nRF24?

Have you got a 10µF capacitor across Vcc and GND for the nRF24 module?

Make pencil drawings showing exactly how everything is connected for both the Tx and Rx and post a photo of the drawings

As you are experiencing, it can be very difficult to debug wireless problems and a very cautious and systematic approach is needed.

...R

UKHeliBob: What is the latest IDE version that you know it worked on ? You could install that as a test. I have resisted the temptation to upgrade the IDE until I want/need any of the features that the newer versions provide.

I had 1.6.10 and, when I first had trouble with working programs suddenly not working, I was advised to update it to 1.6.12. That didn't solve the problem, but now I am a bit scared that downdating will result in a hotchpotch of IDE and associated packages - a complexity way beyond my realm. When I first found programs not working it was just after the IDE popped up a message saying updates were available, and I took them. Don't ask me what they were, but I think one of tem was Firmata. There could have been others.

robin2

  1. I have at times changed both the channel and the signal power on the radios
  2. The nRF24s in the College setup are new, those at home have been replaced during the search for the solution
  3. Yes, the capacitors are in place - also there is a stabilized 3.3 V power supply (see attached)
  4. Both radios are physically wired up the same way. The pins are attached according to the RF24 (TMRh20) column of the table in Terry’s webpage (unless the CE and CSN pins are allocated differently in the actual sketches) - see JPEG.

I am currently trying to get a clean copy of SimpleRx and SimpleTx but I have a problem with copying them. I used the [Select] link on the webpage to select them but they both pasted in with a rash of stray \240s and \302s. I have eliminated all of them except

Compiling sketch...
"C:\Users\Rick\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.3-arduino2/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10612 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Users\Rick\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.13\cores\arduino" "-IC:\Users\Rick\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.13\variants\standard" "-IC:\Users\Rick\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.13\libraries\SPI\src" "-ID:\Documents\Arduino\libraries\RF24" "C:\Users\Rick\AppData\Local\Temp\arduino_build_522166\sketch\SimpleRX.ino.cpp" -o "C:\Users\Rick\AppData\Local\Temp\arduino_build_522166\sketch\SimpleRX.ino.cpp.o"
SimpleRX:14: error: stray '\302' in program

 RF24 radio(CE_PIN, CSN_PIN);

 ^

SimpleRX:14: error: stray '\240' in program

I’ve tried all the text editing tricks I know to clear this one (in both programs without success). Perhaps you would be so kind as to attach clean copies to your next post.

Thanks

Red Wings Power Supply Info.pdf (92.3 KB)

SimpleRX:14: error: stray '\240' in program

Usually means that you have got Unicode characters in the source code that the IDE (any version) cannot deal with. The cause is usually copying code from a Web page.

Try this pair of programs

Receive

//https://www.youtube.com/watch?v=D40cgHyBLL4

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

RF24 myRadio (7, 8);
struct package
{
  int id;
  float temperature;
  char  text[100];
}  data = {1, 0.0, ""};

byte addresses[][6] = {"0"};
const byte tonePin = 3;

void setup()
{
  Serial.begin(115200);
  delay(1000);
  pinMode(tonePin, OUTPUT);
  myRadio.begin();
  myRadio.setChannel(115);
  myRadio.setPALevel(RF24_PA_MAX);
  myRadio.setDataRate( RF24_250KBPS ) ;
  myRadio.openReadingPipe(1, addresses[0]);
  myRadio.startListening();
}

void loop()
{
  if ( myRadio.available())
  {
    int previousID = data.id;
    myRadio.read( &data, sizeof(data) );
    if (data.id != previousID + 1)
    {
      Serial.println("\t\t\t\t\tlost data");
    digitalWrite(tonePin, HIGH);
    delay(200);
    digitalWrite(tonePin, LOW);
    }
    Serial.print(data.temperature);
    Serial.print("\t");
    Serial.println(data.text);
    digitalWrite(tonePin, HIGH);
    delay(50);
    digitalWrite(tonePin, LOW);
  }
}

Transmit

//https://www.youtube.com/watch?v=D40cgHyBLL4

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

RF24 myRadio (7, 8);
byte addresses[][6] = {"0"};

struct package
{
  int id;
  float temperature;
  char  text[100];
}  data = {1, 0.0, ""};

void setup()
{
  Serial.begin(115200);
  delay(1000);
  myRadio.begin();
  myRadio.setChannel(115);
  myRadio.setPALevel(RF24_PA_MAX);
  myRadio.setDataRate( RF24_250KBPS ) ;
  myRadio.openWritingPipe( addresses[0]);
  delay(1000);
}

void loop()
{
  sprintf(data.text, "A string of text %d", data.id);  //32 bytes max packet size !
  myRadio.write(&data, sizeof(data));
  data.id = data.id + 1;
  data.temperature = data.temperature + 0.1;
  delay(100);
}

I did not write them but used them to experiment with RF24. There is a Youtube video to go with them. URL in the programs.