Notifications
Clear all

nrf24 and nano rc car project

Page 2 / 2

Toymaker
(@toymaker)
Active Member
Joined: 5 months ago
Posts: 11
Topic starter  

@frogandtoad thanks for all the help. Here's the less complex sketch

Sketch for the server: 

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

RH_NRF24 nrf24;

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())
  {
    uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];   // Should be a message for us now
    uint8_t len = sizeof(buf);
    if(nrf24.recv(buf, &len))
    {
      Serial.print("got request: ");
      Serial.println((char*)buf);
    }
    else
    {
      Serial.println("recv failed");
    }
  }
}

Sketch for the Client:

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

RH_NRF24 nrf24;

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();
  delay(1000);
}

    Results on Joy, COM7, server,

serial monitor: Nothing blank

LEDs: no flashing LEDs, red and center green stay lit.

    Results on Nojoy, COM3, client

serial monitor:

init failed

Sending to nrf24_server

Sending to nrf24_server

Sending to nrf24_server

Sending to nrf24_server

LEDs: outer red and green flash, center green stays lit.  

 

I swapped the ports using the tool menu. The problem followed the sketch again like the other sketch. init failed staying with COM3

@Ron

                   I physically swapped the ports at the laptop end of the cable. init failed is now on COM7

     Nojoy, plugged into COM7, client sketch

serial monitor says:

init failed

Sending to nrf24_server

Sending to nrf24_server

Sending to nrf24_server

LEDs flashing

 

      Joy, plugged in to COM3, server sketch

serial monitor says: nothing/blank

LEDs, no flashy

                       Then I swapped the ports using tools again

    Nojoy, COM7, server sketch

serial monitor: Init failed

LEDs flashing

     Joy, COM3, client sketch uploaded

serial monitor:

Sending to nrf24_server

Sending to nrf24_server

Sending to nrf24_server

LEDs: Flashing

 

What do you folks think?

 Maybe the cable?

I have to get away from this computer for awhile, rest my eyes

I'll get the picture posted next time.


ReplyQuote
Ron
 Ron
(@zander)
Famed Member
Joined: 2 years ago
Posts: 2755
 

@toymaker Do you perhaps have a power only USB cable? A simple continuity check if it's an A cable on 4 leads. The two inner are data, the two outer are G and 5V.

It is considered poor judgement to traverse a chasm in 2 leaps.


ReplyQuote
Toymaker
(@toymaker)
Active Member
Joined: 5 months ago
Posts: 11
Topic starter  

@Ron

I'm thinking that because the LEDs change when I load a sketch, it downloads the sketches.

So I'm thinking it pushes data.

 I did start with one that was just a USB power cable and the nano came with the blink program in it.

It didn't change when I uploaded the sketch.

And the lights didn't blink showing when it was uploading.

 Both the nanos act like they are uploading, the right lights are blinking during the process.

 I'll try another cable or I think I'm going to have to try hooking one up to the other laptop.

 Maybe the common ground is messing with it.

 I also read that wifi might interfere with the signal and I should use channel 70 or higher. Just not sure how to do that.

This post was modified 5 months ago by Toymaker

ReplyQuote
Ron
 Ron
(@zander)
Famed Member
Joined: 2 years ago
Posts: 2755
 

@toymaker Of course if the sketch loads then the cable is ok. If it was WiFi interference it would probably be consistent and it's not. Is it possible to test only the client and server by themselves so you can prove or disprove each part. The reason I say that is at the moment you have 2 pieces of code intimately connected so it is difficult to determine where any fault may be. I am knees deep in my own project right now but if you don't solve this soon, I have a couple of the boards and can try it myself where I might notice something when I can get some free time.

It is considered poor judgement to traverse a chasm in 2 leaps.


ReplyQuote
Ron
 Ron
(@zander)
Famed Member
Joined: 2 years ago
Posts: 2755
 

@toymaker Just a sanity check, you do have 2 instances of the arduino IDE open at once correct?

It is considered poor judgement to traverse a chasm in 2 leaps.


ReplyQuote
Toymaker
(@toymaker)
Active Member
Joined: 5 months ago
Posts: 11
Topic starter  

 

 

@Ron 

   I understand having many projects going and

thank you so much for the time you've already spent helping me

and the patience you've shown me.

   I've been picking away at problems with these for months so no big hurry.

Get your stuff taken care of first.

   From my searching for answers I'm not the only one having problems with these:

The bottom of the tutorial page is full of others.

nRF24L01 Wireless Joystick for Arduino Robot Car | DroneBot Workshop

     Since I hope others might read this and find it helpful: 

     My first problem was a bad nano, the chip on the bottom was getting hot.

The other one wasn't getting hot. Logic?>> They aren't supposed to get hot.

Luckily I bought 3 of each, nano, nerf, adapter and antenna. The other one didn't get hot either and works better.

      Another problem was trying to upload a sketch to these nano boards without using the "old bootloader".

Which is found in tools> processor.

It wouldn't load. Bunch of orange text at the bottom.

 

  Yes I believe I do have 2 instances open.

 If I don't click on the arduino icon and bring 2 windows up that way,

then whenever I try to change to a different port on one window, 

 the port changes in the other arduino sketch too.

Me>, " Wait I just changed the client sketch window to COM3

how come it changed to COM7 when I set the server sketch to COM7.

DOH, oh I see I only opened one instance,... again"? <<

You are not the only one who checks my sanity, ha.

 

Let's see if I can attach a picture of my friends Joy and Nojoy:

nanonerfs

 The third one is just to show the breakout board. I did buy another nano. An every this time.

     

This post was modified 4 months ago by Toymaker

ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 3 years ago
Posts: 1156
 

@toymaker 

I also have been unable to upload to any of the Nanos I own without using the "old bootloader."  Not sure what the secret behind that is, but I've now resigned myself to always use the 'old bootloader" when working with my Nanos.

Although it has been awhile I remember I was successful in getting my nrf24 and joysticks working together.

SteveG


ReplyQuote
Ron
 Ron
(@zander)
Famed Member
Joined: 2 years ago
Posts: 2755
 

@toymaker 'Old bootloader'? They have USB ports. I will see if I have a NANO or two laying around and try a blink sketch using the USB port but I was just woke up by a tree crashing on the roof of my RV. Everyone is OK, the RV appears to still be watertight but the repairs will be in 5 figures.

It is considered poor judgement to traverse a chasm in 2 leaps.


ReplyQuote
Will
 Will
(@will)
Noble Member
Joined: 1 year ago
Posts: 1929
 

@codecage @zander @toymaker

Julian Ilett has made a video on how to load the Uno boot loader on to the NANO. This has the extra benefit of expanding usable storage by another 1/2 K. It also means that you don't have to worry about using the new or old bootloader.

The downside is that you have to mark the NANOs because they will be seen by th IDE as an Uno from that point on, despite being the NANO form factor.

I was kidnapped by mimes.
They did unspeakable things to me.


ReplyQuote
Page 2 / 2