NR24L01 problem when uses signal

So I have been working a project for a while which uses a NRF24L01 (has no 10 microfarad capacitor) and I found myself with a problem.

Here is the link of a youtube video the demonstrates everything about the project:

But in case you don't have time, basically is a car that can fire a dart, activate a buzzer, turn on lights and two wheels. It is controlled with a remote control and the car has two sensors: a HC SR04 and a light sensor built with a LDR and a resistor.

Right now it does not have a cable anymore, it has a 7.4 v battery with 1300 mAh (lippo battery).

Here is the problem, whenever the car loses signal I can't get it back (I have to switch it off and on) and it does the last command it receives (so if its last order was to go forward it will keep going forward).

Here it is the code:

of the car:

of the command:

Here it is what I tried to do:

  if (radio.available()) {
   radio.read(&dataSendFinal, sizeof(struct data));
   radio.writeAckPayload(1, &DataOutFinal, sizeof(DataOutFinal));
   Serial.println("Command:");
   dataSendFinal.print();
   Serial.println("Sensors");
   DataOutFinal.print();
  }else{
    wheelControl(0, 26, 27); //rignt wheel
    wheelControl(0, 28, 29); //left wheel
    digitalWrite(3,1);
    delay(25);
    digitalWrite(3,0);
    delay(25);
    digitalWrite(3,1);
    delay(25);
    digitalWrite(3,0);
    delay(25); //one of the LEDs blinks when radio is not available
  }

The modification is on the else statement, but it did not go well.

What happens is that it stops and it goes forward over and over again and it blinks the LED more times than, at least, I would expect. I pretend to find a way of making it stop when it loses signal, but it would be nice to find a way to make it able to get control again.

NOTE: in the video there is a GUI, I did not put the code, because I don't believe it is import.

You seem to use an outdated and buggy library for the NRF24L01.

I recommend Optimized High Speed NRF24L01+ Driver

  radio.writeAckPayload(1, &DataOutFinal, sizeof(DataOutFinal));
  radio.startListening();

I'm pretty shure you have to switch both statement, startListening clears all queues as far as I remember.

I will not debug any program that contains significant (above 10ms) delay() calls, sorry.

Hey thanks for the response!!!

First of all I do beleive I have the last version, because you have helped me in the past and you told to update it so I did, but I will check it later (can't do it now).

I don't get it why the startListenning statement is after that, even with the explanation, but considering that it has been working fine I will not change it, for now.

The delays is just a temporary thing, I am thinking to change all of them a replace them with a "millis() function process", it's ok if you don't want to debug. One more thing, do you think it is usefull to put the code of the GUI program, even by the fact it does not interfere with the communication?

If you want to remember the time you helped me here is the post:
https://forum.arduino.cc/index.php?topic=472438.0

For my R/C model train projects I send a message at regular intervals (about 10 per second) and if the receiver fails to get 10 messages in succession it stops the train.

Get rid of ALL the delay()s in the car program - every one of them. You need loop() to repeat as fast as possible - hundreds or thousands of times per second. Have a look at how millis() is used to manage timing without blocking in Several things at a time

Why have you got stopListening() in the car program - it should be listening all the time.

...R
Simple nRF24L01+ Tutorial

As I said I intend to do that later on, this was just a test. What I pertend to do is to make it do a specific action when it gets out of range and I do not know how to make the program understand that it is out of range. I have tried a few things, this was just one of them, which did not work well.

ddmdavid01:
As I said I intend to do that later on, this was just a test. What I pertend to do is to make it do a specific action when it gets out of range and I do not know how to make the program understand that it is out of range. I have tried a few things, this was just one of them, which did not work well.

Robin2 told you how his train knows it has a problem. You can do the same thing in your car.

Paul

I have tried to do the solution with the radio.available and it did not work. I suspect it won't work (that is why I asked again) but I can't test it right now. However I can't test it now, I can only try next week.

ddmdavid01:
However I can't test it now, I can only try next week.

We can wait.

When you have completed your tests and if it is not working as you want please post the latest versions of both programs. And give us a clear description of what it actually does and what it should be doing.

...R

Ok thanks. SO before I tried to do something about it, when range was lost it would do it's last "order" (if it was to go forward, it would go forward forever). I tried to fix this by giving him the order to stop in case there was no communication available, but it ended up not working in the way I expected. It just stops and goes forward over and over again.

ddmdavid01:
I tried to fix this by giving him the order to stop in case there was no communication available, but it ended up not working in the way I expected. It just stops and goes forward over and over again.

How [expletives deleted] are we supposed to help when you have not posted the code that is giving that result. Clearly you are not doing it the right way. There are a million wrong ways and I don't know which of them you have chosen without seeing your code.

...R

but I have this is the part responsible for that:

  if (radio.available()) {
   radio.read(&dataSendFinal, sizeof(struct data));
   radio.writeAckPayload(1, &DataOutFinal, sizeof(DataOutFinal));
   Serial.println("Command:");
   dataSendFinal.print();
   Serial.println("Sensors");
   DataOutFinal.print();
  }else{
    wheelControl(0, 26, 27); //rignt wheel
    wheelControl(0, 28, 29); //left wheel
    digitalWrite(3,1);
    delay(25);
    digitalWrite(3,0);
    delay(25);
    digitalWrite(3,1);
    delay(25);
    digitalWrite(3,0);
    delay(25); //one of the LEDs blinks when radio is not available
  }

ddmdavid01:
but I have this is the part responsible for that:

[more expletives deleted]

Just post the complete program.

...R

But the full code is in the github links!!!!! Can you see them when you click on them? If not, just tell and I will change (the code is to big to put in a post).

ddmdavid01:
But the full code is in the github links!!!!! Can you see them when you click on them? If not, just tell and I will change (the code is to big to put in a post).

Have you not changed anything between your Original Post and Reply #13 to take account of the various Replies you have received?

Assuming you have, then it is important to enable us to compare the original and the changed versions - and it is much easier to follow along with your development of the project if a specific version of the program is associated with a specific post. For example your Reply #9 seemed to imply some particular tests you had done - what is the program that gave rise to your comments in that Reply?

Help us to help you.

...R

Ok now I get it, but the thing is the code which does its last order is the code without that piece I "highlighted" but I will put the other code without it as soon as I can. I will also record what is happenning because it is easier to see than to explain.

So here it is the video explaining what is happening with my project:

Note: you can just comment the delay functions if there is the need to debug.

One more thing:

For my R/C model train projects I send a message at regular intervals (about 10 per second) and if the receiver fails to get 10 messages in succession it stops the train.

How exactly did you implement that, because I do not see much difference from what I did.

ddmdavid01:
So here it is the video explaining what is happening with my project:

I have looked at the first 50 seconds or so. It does not tell me anything new. Nor does it invalidate what I have been recommending. I am not prepared to watch long videos - other than Hercule Poirot detective stories.

Note: you can just comment the delay functions if there is the need to debug.

I have no idea what that refers to. You STILL have not posted the code as I requested in Reply #10

How exactly did you implement that, because I do not see much difference from what I did.

I told you that in Reply #4. All you need to do is record the value of millis() when a message arrives. If the difference between millis() and the saved value exceeds 1000 (for example) it means there has been no message in the last second.

...R

First the "comment of the delay function" is explained in the end, but in a nutshell is you can remove it in order to test it (it has no difference, since it is required in that moment for the hole robot to stop and receive nothing, basically if you want to test it you can take it of)

If you mean the code without the thing I tried here it is:

The only difference is the else statement that I highlighted does not exist.

If you check the 1:11 you will see that is the robot response, that is why I uploaded (most of the video I explain what is the difference between both programs and show what happens)

So just to be clear. What you do is send a message every 0.1 seconds and if it does not receive all 10 it stops (can the message be like a number or something)?

ddmdavid01:
If you mean the code without the thing I tried here it is:

I am fast losing patience ...

Let's see if we can start over.

Post the latest version of your program (here - not on another website) and tell us what it actually does and what you want it to do that is different.

But before you do, please take account of the rest of my comments here as you may wish to take account of them in your code before you post anything.

So just to be clear. What you do is send a message every 0.1 seconds and if it does not receive all 10 it stops (can the message be like a number or something)?

Yes, and the message can be anything you want. I normally send the latest instruction (in my case the value from analogRead() and the position of the direction switch) even though it has not changed. That way, if one message was lost a change would be picked up at the next message. Sending data only when there is a change (without any repeats) is a risky strategy.

...R