Notifications
Clear all

Arduino RC Project using Two nRF24L01+ Modules

12 Posts
3 Users
1 Likes
484 Views
(@kabass)
Member
Joined: 6 months ago
Posts: 2
Topic starter  

Being new to Arduino and radio control, any assistance with the following will be greatly appreciated.

End goal of the project is to use to nRF24L01+ Modules to create a remote with two potentiometers and a joystick to control two 5V servo motors and a 12V DC motor. 

The issue I have been having is getting any communication between the two modules. As a guide I used DroneBot Workshop's video (The nRF24L01 - Wireless Joystick for Arduino Robot Car with nRF24L01+). 

Both Arduinos are wired as indicated in the diagram from the video. 

Wiring Diagram PER VIDEO

Two Arduino Uno clones & Two nRF24 antenna modules where used both wired according to the diagram above. (Note the nRF24 power adaptor was used) 

image
image

I even checked every wire in the circuit with a volt-meter to ensure each was functional. Then I downloaded the latest radiohead library as indicated in the video (RadioHead website)

image

 NOTE: Arduino IDE used is 2.2.1

Then I loaded radiohead example codes for both the client and server.

Arduino Uno 1: (Client) 

// nrf24_client.pde
// -*- mode: C++ -*-
// Example sketch showing how to create a simple messageing client
// with the RH_NRF24 class. RH_NRF24 class does not provide for addressing or
// reliability, so you should only use RH_NRF24 if you do not need the higher
// level messaging abilities.
// It is designed to work with the other example nrf24_server.
// Tested on Uno with Sparkfun NRF25L01 module
// Tested on Anarduino Mini ( http://www.anarduino.com/mini/)  with RFM73 module
// Tested on Arduino Mega with Sparkfun WRL-00691 NRF25L01 module


#include <SPI.h>
#include <RH_NRF24.h>


// Singleton instance of the radio driver
RH_NRF24 nrf24;
// RH_NRF24 nrf24(8, 7); // use this to be electrically compatible with Mirf
// RH_NRF24 nrf24(8, 10);// For Leonardo, need explicit SS pin
// RH_NRF24 nrf24(8, 7); // For RFM73 on Anarduino Mini


void setup()
{
  Serial.begin(9600);
  while (!Serial)
    ; // wait for serial port to connect. Needed for Leonardo only
  if (!nrf24.init())
    Serial.println("init failed");
  // Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm
  if (!nrf24.setChannel(1))
    Serial.println("setChannel failed");
  if (!nrf24.setRF(RH_NRF24::DataRate2Mbps, RH_NRF24::TransmitPower0dBm))
    Serial.println("setRF failed");    
}



void loop()
{
  Serial.println("Sending to nrf24_server");
  // Send a message to nrf24_server
  uint8_t data[] = "Hello World!";
  nrf24.send(data, sizeof(data));
 
  nrf24.waitPacketSent();
  // Now wait for a reply
  uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];
  uint8_t len = sizeof(buf);


  if (nrf24.waitAvailableTimeout(500))
  {
    // Should be a reply message for us now  
    if (nrf24.recv(buf, &len))
    {
      Serial.print("got reply: ");
      Serial.println((char*)buf);
    }
    else
    {
      Serial.println("recv failed");
    }
  }
  else
  {
    Serial.println("No reply, is nrf24_server running?");
  }
  delay(400);
}
Arduino Uno 2: (Server)
// nrf24_server.pde
// -*- mode: C++ -*-
// Example sketch showing how to create a simple messageing server
// with the RH_NRF24 class. RH_NRF24 class does not provide for addressing or
// reliability, so you should only use RH_NRF24  if you do not need the higher
// level messaging abilities.
// It is designed to work with the other example nrf24_client
// Tested on Uno with Sparkfun NRF25L01 module
// Tested on Anarduino Mini ( http://www.anarduino.com/mini/)  with RFM73 module
// Tested on Arduino Mega with Sparkfun WRL-00691 NRF25L01 module


#include <SPI.h>
#include <RH_NRF24.h>


// Singleton instance of the radio driver
RH_NRF24 nrf24;
// RH_NRF24 nrf24(8, 7); // use this to be electrically compatible with Mirf
// RH_NRF24 nrf24(8, 10);// For Leonardo, need explicit SS pin
// RH_NRF24 nrf24(8, 7); // For RFM73 on Anarduino Mini


void setup()
{
  Serial.begin(9600);
  while (!Serial)
    ; // wait for serial port to connect. Needed for Leonardo only
  if (!nrf24.init())
    Serial.println("init failed");
  // Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm
  if (!nrf24.setChannel(1))
    Serial.println("setChannel failed");
  if (!nrf24.setRF(RH_NRF24::DataRate2Mbps, RH_NRF24::TransmitPower0dBm))
    Serial.println("setRF failed");    
}


void loop()
{
  if (nrf24.available())
  {
    // Should be a message for us now  
    uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];
    uint8_t len = sizeof(buf);
    if (nrf24.recv(buf, &len))
    {
//      NRF24::printBuffer("request: ", buf, len);
      Serial.print("got request: ");
      Serial.println((char*)buf);
     
      // Send a reply
      uint8_t data[] = "And hello back to you";
      nrf24.send(data, sizeof(data));
      nrf24.waitPacketSent();
      Serial.println("Sent a reply");
    }
    else
    {
      Serial.println("recv failed");
    }
  }
}

 

Then using two computers as shown in the video guide. One computer running the server and Second computer running the client, I received the following on each serial monitor. 

Arduino Uno 1: (Client Serial Monitor) 

Cilent Serial Monitor

(Claiming no reply is heard from the server) 

 

Arduino Uno 2: (Server Serial Monitor) 

Server INT FAILED

(Claiming Init Failed) 

 

The "Hello World" message was never received. This indicates that there is NO communication happening between the two radio modules. I even tried swapping the MI and MO (input and output) pins on the modules as indicated in the video. Power supply to the module adaptors is coming from the 5V pin on the Arduino to VCC on the adapter which should convert the 5V to 3.3V as I am using the nRF24's plugged into the adapter. I restarted both IDE's after the radiohead library installation. I also used a new set of nRF24 modules with brand new genuine Arduino Uno's and I had the exact same problem. 

image

I have been struggling with this for a long time and I have no clue what the problem is. If anyone has any ideas or tips to try please let me know it would be extremely helpful. 

My main goal right now is to get ANY correspondence between the two modules so if someone has code and a library that they used for the nRF24L01+ modules with Arduino that worked for them. Please share, so I can try that and see if it will work. 

 

   
Quote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6530
 

@kabass Focus on the module giving the 'init failed'.

You may need to go into the library code to add debug, just remember when you are done to delete the library you modified and reload it.

If you are using a breadboard triple check that all connections are good, some boards are better than others.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1547
 

Hi @kabass,

  Please note I haven't used these modules ... my comments, which are mainly generic to most such projects, are just based on experience ... so there is always a chance something unusual will catch me out. If I suggest something you think is 'unwise', please query it, before breaking anything. It is easy for me to have made a mistake when writing a 'What to do recipe' with no hardware to test it on.

----------------

   Ron (@zander) is absolutely right when he says concentrate on the module showing "Init failed". Until you get past that problem, your project is stuck. The fact that the Arduino board is saying something on the Serial monitor means it is extremely unlikely (though not strictly impossible) that the Arduino board itself is faulty, and the problem is probably with the attached interboard wiring or the nRF module.

And I also agree with Ron's comment that wiring is number one suspect, but of course, the most likely suspect is not always the guilty party.

--------------------------

I think it is unlikely to be a problem in your case, but Bill in his video, at a time of about 9:50 in a tips section, mentions some nRF modules have input and output markings reversed ... have a look at the video and then do a double check.

----------------------------

Again, unlikely to show anything, but a very easy test ... move the USB connector of the failing Arduino/nRF to the other computer, and temporarily upload the 'receive' end software, thus temporarily making it the 'receiving' end.

If it is a hardware problem, I would expect it to still fail with the "Init failed", as that first few lines of code appears to be common to both receive and transmit software start up options.

Should it pass that point, and start reporting no message received, it is time to rethink the strategy. Maybe post again and hope for a response as where to go.

-------------------------

If swapping the USB connections and making the 'dodgy' hardware a receive end also showed "Init failed", then swap them back, upload the "transmit code", and double check it is still failing in the transmit role.

-----------------------

Assuming you have some spare ribbon cables, try replacing the interboard ribbon cables, and test again, in case one is playing tricks on you.

If you don't have any spare cables, double check connections with a meter (I know you said you have done this, but sometimes connections are intermittent.), being sure to check to the base of the pins on the underside of the Arduino to the base of he pins on the underside of the nRF module.

---------------------------------------------

At this point, if you are still not getting past "Init failed", then I would suggest the nRF module itself is the most likely suspect.

If you have a spare nRF module, 'on the shelf', then try swapping it in.

If you don't have one 'on the shelf', you might consider swapping the two you have over (Put a mark on the likely faulty one, so you can keep track which is which!), and if the fault stays with same module, then maybe order a new module.

-------------------

Best wishes and good luck,

Dave


   
Ron reacted
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6530
 

@kabass @davee I agree 100% with Dave re 

I think it is unlikely to be a problem in your case, but Bill in his video, at a time of about 9:50 in a tips section, mentions some nRF modules have input and output markings reversed ... have a look at the video and then do a double check.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6530
 

@kabass @davee Again I agree with Dave but will elaborate a bit

. move the USB connector of the failing Arduino/nRF to the other computer, and temporarily upload the 'receive' end software, thus temporarily making it the 'receiving' end.

If the 'init failed' message stays with the same NRF board, then it is very likely either the wiring or the board is bad. 

If the 'init failed' moves to the other board, then somehow that sketch has a bug.

 

 

 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@kabass)
Member
Joined: 6 months ago
Posts: 2
Topic starter  

@davee 

Thank you for your feedback. 

With regard to the tip section from Bill's video I swapped the input and output pins on both modules and received the same error. 

I also used two new nRF24 modules (different from the original two used the first time) and new ribbon wires that I confirmed to be functional using a volt-meter. 

I also ran the test you suggested (swapping the USB connections from each computer) the "Init Failed" message occurred every time I ran the (nrf24_client.pde) example code [As attached in the original message] swapping the board and module did not affect the error. Therefore, concluding that regardless of the computer, arduino board or nRF24 module used, the Server code always prompts "Init Failed" on the serial monitor. To me this means that the code or library is the issue, correct me if I am thinking about this the wrong way. 

 

I will say I did notice something that struck me as odd when swapping the USB and modules. The both serial monitors (Server and Client) remain unchanged when the module is disconnected. Even the client keeps running the following prompt with no nRF24 module connected.

image

 


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6530
 

@kabass This last para is interesting

I will say I did notice something that struck me as odd when swapping the USB and modules. The both serial monitors (Server and Client) remain unchanged when the module is disconnected. Even the client keeps running the following prompt with no nRF24 module connected.

It's a little confusing, you say BOTH Server and Client keep running when the 'module' is disconnected. What do you mean by 'module'

Depending on the amount of time involved, you could just be seeing buffering. The easy way to test for that is to do the same thing again but delay reconnecting for a much longer time to see if it ever ends. I think 5 minutes should be enough.

If what you mean is the 'init failed' message continued on, then you have the answer to your puzzle. The failure is due to the NRF24 module NOT being connected (wired) to the processor. If you are using a breadboard or Dupont wires, change them and or quadruple-check ALL the connections. Breadboards have been the cause of hundreds of these kinds of errors.

Either obtain another breadboard, ideally from a different manufacturer or shift the entire circuit by 4 or 6 pin locations.

 

 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1547
 

Hi @kabass,

  It looks like you have made some real progress, though sadly not a solution yet. Regretably, problem solving can be like this .. eliminating possible problems, without discovering the real problem is frustrating but necessary.

  And yes, from your description, it looks like the software may at least partly to blame.

  I am somewhat concerned that I think you are suggesting the receive software, which appeared to be attempting to work, is unable to detect whether the nRF module is connected, even though it claims to have initialised it!

Unfortunately, I haven't actually got any of the nRF modules, so I can't reproduce your problem.

It is much too late in the day for me think of what to do next now, but I'll post again, when & if, I come up with any ideas. In the meantime, I wonder if any others can offer some enlightenment?

Best wishes, Dave


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6530
 

@davee The below is incorrect Dave, it did NOT initialise it. The fact the same error is generated when disconnected isn't too surprising, I imagine their is a bunch of reasons init can fail.

 I am somewhat concerned that I think you are suggesting the receive software, which appeared to be attempting to work, is unable to detect whether the nRF module is connected, even though it claims to have initialised it!

 

 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1547
 

Hi Ron @zander and  @kabass,

   Sorry, it is very difficult to see all that is happening, just based on a couple of screen shots, etc., + it was stupidly late for me, when I last replied, so it might be a moment to reflect on what is known and what is not.

Looking at the code listed and the accompanying pair of photos in the first mail, both server and client start with same code:

CLIENT:

void setup()
{
  Serial.begin(9600);
  while (!Serial)
    ; // wait for serial port to connect. Needed for Leonardo only
  if (!nrf24.init())
    Serial.println("init failed");

I confess to not having looked into it further, having seen the screen shots that follow, for which the

Client shows:

image

and Server shows:

image

which I (naively/hopefully) thought meant that the Client had successfully 'passed' the init code I excerpted above, whilst the Server had 'failed', and declined to move further.

Clearly, the processor should not leave the setup() function, without successfully passing the init stage, plus all of any other code in the setup() function, including setting up the channel and RF power levels, but the client print out is showing the result of print statements in the loop () function, suggesting the client has successfully negotiated its way through setup().

Unfortunately, this conclusion is now being doubted.....

----------------

Ron has just said: "The below is incorrect Dave, it did NOT initialise it." and quoted part of my previous message, which says " I am somewhat concerned that I think you are suggesting the receive software, which appeared to be attempting to work, is unable to detect whether the nRF module is connected, even though it claims to have initialised it!"

The Client photo in the first message does NOT show Init Failed , but it is plausible, that has scrolled out of view, so at this point I am unclear if the Client has reported Init Failed, as Ron is suggesting.

Time to move to the more recent message with photos, using replacement hardware, etc.

--------------------------------------------------------------------

Starting at the latter part of this message, whilst discussing what happens when the nRF modules are disconnected, it is stated "Even the client keeps running the following prompt with no nRF24 module connected." and shows a photo of the Client end, once again in the 'loop()' function, reporting no messages from the server .. and no sign of "Init failed", though once again, that might be scrolled out of view.

I presume, the Server machine hung at "Init Failed", with no nRF module connected, though I don't  think that point is actually confirmed. (Please confirm or deny.)

------

So far, it seems like the software 'error checking' is suspect, in that in at least some cases, it may 'carry on' to the next stage, regardless of whether any hardware is present and responding correctly. Of course, this may not be a problem if the hardware is 'playing nicely', but it can be very confusing if the hardware is faulty, etc. This aspect certainly needs looking into.

One thing I have already noted is that the init() function is effectively a conditional loop, but the 'while' part of the loop is using the return value from the Serial.begin(9600) method. This is only the print back to PC functionality, and has nothing to do with the nRF module functions .... which looks suspicious to me....

------------------------------------------

The first part of the message discussed various checks, including swopping the nRF modules .. and it was found that the Server machine always reported 'Init failed', suggesting the problem was either in the Server software or something very weird to do with the PC running the Server nRF module, which seems implausible at the moment.

However, the finding that the software doesn't notice that the Client nRF module is disconnected, also leaves the possibility that neither none of the nRF modules have worked.

----------------------------------------------------------

All of the above, is simply me going through the evidence and recording my thoughts. Please check through, and see if I have made any mistakes ...for me, it is very easy to have made a 'simple' slip or oversight, which could totally change the conclusions. Unfortunately, as I wrote it, it is also the hardest for me to check.

----------------------------------------------------------------

I think the next points are:

1/ Try to make the software error checking better .. at present it seems to be causing more confusion than aid, and may well be sending us down the garden path.

2/ Unfortunately, I don't have the nRF modules, so I can't check the hardware physically. I have started to look for circuits, etc. on the web. I presently have some concerns, but I need to look further. I have found some circuits for both an nRF24L01 module and its adapter, but I don't know if they match the ones you have. Could you please post any further information, and also maybe a close up photo of the module and adapter boards, so I might get a better idea of the circuit, by trying to identify components, etc.?

----------

Sorry, lots of waffle, not much visible progress, but I am not giving up yet! Best wishes,Dave

 


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6530
 

@davee TLDR. My reverse sermon is.

1. Client is in the loop sending messages and getting no reply. It passed init a while ago.

At this point I read the server code before creating this reply and just now noticed something that makes no sense. After the init fail the code goes on to setChannel and setRF without error.

I am suggesting to @kabass that he add some code after the init failed to do a retry of the init. maybe try it 3 or 4 times with a small delay in between.

If I am understanding @kabass correctly, he said when swapping USBs that the error followed the USB/software cable. That is 100% proof the error is in the software not the hardware. 

I don;t know if the OP has tried this idea yet, but do whatever needs to be done to start the server first and make sure it is actively polling for input as seen in the serial monitor screen prints. Only then start the client and if it fails the same way add the retry logic. Beyond that I am stumped.

When I can find my modules I will give it a go when I have time.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1547
 

Hi Ron @zander and  @kabass,

   I don't know if you are still listening kabass, but I thought I would mention that I haven't forgotten you, albeit, I don't have neat answers either.

I have actually bought a small pack of the 'minimal' nRF24L01 modules with the antenna on the PCB, which should generally work the same as the ones with external antennas and amps, albeit with reduced range. I have also made a couple of 5V to 3.3V adapter modules .. they basically only change the power voltage.

Unfortunately, I only have one 'Arduino', a 2560 clone, and I have been trying to use an ESP32 to drive the second nRF module ... something that is proving more tricky than it should. To be fair, the software does not claim to be supported by the ESP32, although there are comments on the web, some, but not all, suggesting, it is possible.

------

And I have started to look at the software, which is the most concerning bit.

From your video pictures, it looked like one machine was stopping at a failed 'init' function, whilst the other one had continued past that, suggesting it was working, but didn't have a partner to converse with.

However, as Ron points out, they both failed at the 'init' ... but the software in one case has ignored a test that was intended to check that a module was attached!!!! I haven't yet got to the bottom of this, but unfortunately there is very little diagnostics built into the library code, and it is designed to cover a wide range of hardware, so it is confusing at first.

----------

I have just managed to get it to run a version of the Hello World and reply code you were using, albeit presently only with the Mega 2560 as the client and the ESP32 as server.

When I first got it to work, only about 20% of the 'Hello World' messages were being shown and replied to. By chance, I added a small delay (presently 10mS, but this was only my first value, so maybe it can be shortened), in the server code, just after the lines:

      Serial.print("got request: ");
      Serial.println((char*)buf);

and it appears to be seeing all of the messages.

This might be a consequence of using an ESP32 to run this code, as it is a much faster processor than a Mega 2560.

------

Presently, I am adding extra dignostic messages, mainly  to the RH_nRF24.cpp/.h, (which are library files called up by the 'Hello World' example) as well as the top level Hello wWorld calling .ino files. Whether they will be enough to diagnose your system I am not sure.

Sorry, it is not a simple answer.

Best wishes, Dave


   
ReplyQuote