Go Down

Topic: Is "!radio.available()" OK to use? (Read 446 times) previous topic - next topic

JeromeAriola

The "!" means "not" right?

So I think that this is okay to use in nrf24l01. Will there be any issues?

BTW, if Robin2's here, I just wanted to ask, in creating radio, CE is the first value right? Some guy online flipped it, and now I'm unsure

Whandall

I just wanted to ask, in creating radio, CE is the first value right? Some guy online flipped it, and now I'm unsure
How about reading the documentation?

http://tmrh20.github.io/RF24/classRF24.html
Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

Robin2

BTW, if Robin2's here, I just wanted to ask, in creating radio, CE is the first value right? Some guy online flipped it, and now I'm unsure
You need to post your program so I can see all the details.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

JeromeAriola

How about reading the documentation?

http://tmrh20.github.io/RF24/classRF24.html
Thanks Whandall. I didn't know that existed

You need to post your program so I can see all the details.

...R
Here is a snippet:
Code: [Select]


void outOfRange()
{
  if(!radio.available())
  {
    hover();
  }
}



This is the other guy's code I was talking about

TX
Code: [Select]

/*
* Arduino Wireless Communication Tutorial
*     Example 1 - Transmitter Code
*               
* by Dejan Nedelkovski, www.HowToMechatronics.com
*
* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CNS, CE
const byte address[6] = "00001";
void setup() {
  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MIN);
  radio.stopListening();
}
void loop() {
  const char text[] = "Hello World";
  radio.write(&text, sizeof(text));
  delay(1000);
}


RX
Code: [Select]

/*
* Arduino Wireless Communication Tutorial
*       Example 1 - Receiver Code
*               
* by Dejan Nedelkovski, www.HowToMechatronics.com
*
* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CNS, CE
const byte address[6] = "00001";
void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening();
}
void loop() {
  if (radio.available()) {
    char text[32] = "";
    radio.read(&text, sizeof(text));
    Serial.println(text);
  }
}


In my testing of this code, I just put !radio.available that, when true, shows"Not Available" on serial monitor when RX is not detecting TX. I don't know, but all it is saying is Not available. The TX is plugged in, seems like it is not sending, and to be honest this is the first time I tested those radios :)

Perhaps the code is wrong? Or my hardware?

jremington

First make sure that you can send data between the radios in the normal way, following the simple examples.

Robin2

Here is a snippet:
I asked to see the program, not a snippet.

As @jremington has said, get a simple program working reliably before you start experimenting with other stuff.

...R
Simple nRF24L01+ Tutorial
Two or three hours spent thinking and reading documentation solves most programming problems.

JeromeAriola

Robin, I'm not sure but I think that the Simple Tutorial codes don't work. At least in my case. RX is saying DAta Received constantly.

Robin2

Robin, I'm not sure but I think that the Simple Tutorial codes don't work. At least in my case. RX is saying DAta Received constantly.
They work for me and for other Forum members.

Please post the actual code that YOU have uploaded to your two Arduinos.

...R

Two or three hours spent thinking and reading documentation solves most programming problems.

JeromeAriola

Basically this:
Code: [Select]


/*
* Arduino Wireless Communication Tutorial
*       Example 1 - Receiver Code
*               
* by Dejan Nedelkovski, www.HowToMechatronics.com
*
* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CNS, CE
const byte address[6] = "00001";
void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening();
}
void loop() {
  if (radio.available()) {
    char text[32] = "";
    radio.read(&text, sizeof(text));
    Serial.println(text);
    if(!radio.available())
  {
    Serial.print("Not Available");
  }
}



If you didn't notice the difference, this one has "if(!radio.available())"

Robin2

Basically this:
Figuring out problems with wireless programs can be very difficult.

You said that you could not get my programs to work and I asked you to post the code (a pair of programs) that YOU have uploaded to your two Arduinos while attempting to get my programs to work.

You have posted the code for some other program and that is not helpful.

Get my demo programs working first.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

JeromeAriola

#10
Sep 29, 2017, 03:31 am Last Edit: Sep 29, 2017, 03:47 am by JeromeAriola
I'm sorry...

It's literally a copy and paste of your code on the tut.

Now I'm thinking I have faulty parts. I bought these modules from eBay, but I would assume it works fine (as all my eBay arduinos, etc work well)

I will reinstall the lib (tmrh20) on my PC
Just to make it clear 9 is for CE and 10 is for CSN, right?

And how come the files like "RF24_config" are not #included? May that be the reason for my modules not working?

JeromeAriola

UPDATE: The modules work!!

I think it was just a library issue or a wiring. Sorry for calling your code faulty. How disrespectful of me!
It works.

Now do you think we can talk about !radio.available as a function for if the radios can't detect each other?

Whandall

Now do you think we can talk about !radio.available as a function for if the radios can't detect each other?
You can not use that function directly for that purpose, because it only signals the availability of a packet.
It will return false for 99% of the calls.

Failing sends, or no reception for some time (if the other station sends regularly), could be used.
Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

Robin2

Now do you think we can talk about !radio.available as a function for if the radios can't detect each other?
Not really. The problem is that 99.9% of the time radio.available() will return 0 (or false) even though there is nothing wrong with communication. It will only be positive when a message is received.

The best way to test for failed communication is to send a message at regular intervals (say 5 per second) and at the receiving end time the intervals between messages. If the interval is too long you will know there is a problem.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

JeromeAriola

I don't mean to be rude, but did you notice the "!" before the radio.available?

Anyway, can you demonstrate how that would be done. Like you would have done it?

Does it involve setRetries?

 I saw that in the Simple Tutorial you used "else" to send message if it fails. Is it that?

Go Up