gps & nrf24l01+ 2

Hi all.

Having failed with my previous post, I have decided to start a fresh from the beginning, as with the amount of replies Info sketches and ebook's I was reading, I was only getting more and more confused. Thank you for all of your Input.

With starting again I first tested the radios with a test sketch, TMRh20's random numbers to check they both work.
All works fine.

I have a few questions I would like to ask before I go any further with the code, but will ask one at a time.

static const int RXPin =10, TXPin =11; //gps channels
const uint64_t pipe = 0xF0F0F0F0E1LL; //radio channel
static const uint32_t GPSBaud = 9600; //gps baud rate/quote]
Can I do this? A static const + a const and a static const int? I also thought that the int should be a char and only for the RXPin =10?
Please, don't forget I'm a newbie and trying to learn, mostly from mistakes.

Dizzwold

TX

#include <SPI.h>
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include "nRF24L01.h"
#include "RF24.h"

static const int RXPin =10, TXPin =11; //gps channels
const uint64_t pipe = 0xF0F0F0F0E1LL; //radio channel
static const uint32_t GPSBaud = 9600; //gps baud rate

TinyGPSPlus gps;
RF24 radio(49,53); //radio pins on mega 2560
SoftwareSerial ss(RXPin, TXPin); //software serial pins a above to 10,11

unsigned long startTime = millis();
unsigned long updateInterval = 5000UL; //send gps coordinates every 5 seconds

void setup(void) {

Serial.begin(115200); //view in serial monitor
  ss.begin(GPSBaud);
  radio.begin();
  //radio.setRetries(15,15);
  radio.openWritingPipe(pipe);
  Serial.println();
  Serial.println("Dizzwold's GPS.");

}

void loop () {

unsigned int random_Number = random(0,255); //ignore the random numbers part of the code for now
  Serial.print("Sending: ");
  Serial.println(random_Number);
  while (ss.available() > 0)
    if (gps.encode(ss.read()))

if (millis() > 5000 && gps.charsProcessed() < 10)
  Serial.println(F("No GPS detected: check wiring."));
  radio.stopListening();

boolean ok = radio.write( &random_Number, sizeof(random_Number) );

if (ok) Serial.println("ok...");
  else Serial.print(F("INVALID"));

delay(1000);

}
/code]

   while (ss.available() > 0)
    if (gps.encode(ss.read()))
      

  if (millis() > 5000 && gps.charsProcessed() < 10)
  Serial.println(F("No GPS detected: check wiring."));
  radio.stopListening();

This is rubbish. You need to learn basic C/C++ formatting. Where to use semicolons. Where to use curly braces.

Your logic for using millis() also makes no sense. If you want to check elapsed time somehow, you have to compare the current time to some previous time.

Hi michinyon.

I still haven't worked you out yet "not that I want to", but I must ask you why;

Your so abusive?
Not willing to help?

Stating comments, such as;
"This is rubbish"
"Your logic for using millis() also makes no sense"
"That's a bad idea. Buy, borrow or steal a proper book".
"why would you use softwareserial on a mega with 4 real serial "?
"This is no good".
"Get a C book and read it instead of writing random nonsense".

You have given some good advise, but why you have to try to humiliate me every time, with the comments, such as above with-out giving some kind of resolve???

I'm a newbie, learning ar** about face, "YES", but if your going to insult me, al-lease gives some kind of pointer, and not just abuse.

I don't want the code written for me.

If you have no good input for this thread, then please leave it alone "michinyon".

Dizzwold.

dizzwold, you have an ambitious project here and it's easy to get confused.

I suggest you back up a little, and get one part working at a time. Maybe just the GPS first, and make sure you understand how to format the received data into the form you will need for the radio transmission. Maybe then just the radios, with "fake" data of the correct format. Divide and conquer. Write small test programs, then combine them (carefully).

You haven't given up yet, so that proves you have persistence.. the most important Engineering quality.

Sorry I can't give much help/examples right now. I will have an example using RAdioHead library (A follow-on to the RF24, I believe.) One of my Grandsons has a working example with one arduino/radio having a joystick and the receiving arduino/radio having two servos in a pan-tilt arrangement, pointing a small laser around in response to the remote joystick. It took him a while to get the data formatting and scaling right. But he had patience, and I only helped when he asked. I'll try to get that up on the Arduino.Info site in a day or two.

Keep on keeping on!

I've been trying to help you for several days, you seem to have a problem with learning anything.

I suggest you back up a little, and get one part working at a time. Maybe just the GPS first, and make sure you understand how to format the received data into the form you will need for the radio transmission. Maybe then just the radios, with "fake" data of the correct format. Divide and conquer. Write small test programs, then combine them (carefully).

I endorse this advice 100%. Particularly as it is the same advice I gave you last week !

If you won't believe me, then listen to the hippie.

The first step, is to make sure your gps is actually connected and working. Try this sketch:

void setup( )
{
    Serial.begin(9600);     // connected to your computer
    ss.begin(GPSBaud);     //  connected to your GPS
}

void loop( )
{
    while ( ss.available( ) )
    {
          char c = ss.read( ) ;
          Serial.print(c) ;
    }
}

You should see a bunch of character messages coming from the GPS device. If you don't, then it is not working.

Be aware that most gps device will not work indoors, you need to be outside or next to a large window.

And the next thing you should do, is have a look at these websites:

http://www.gpsinformation.org/dale/nmea.htm
http://aprs.gids.nl/nmea/

... so that you learn what the GPS device is actually telling you.

The function of the tinygps or tinygps++ objects, is to parse these text messages and separate out all the useful fields of information for you.

To actually LEARN what is wrong with this nonsense, you need to consider what it will actually DO when you execute it:

while (ss.available() > 0)
    if (gps.encode(ss.read()))
      

  if (millis() > 5000 && gps.charsProcessed() < 10)
  Serial.println(F("No GPS detected: check wiring."));

Here's an annoted version of what you wrote, functionally indentical to your code:

while (ss.available() > 0)
{
    if (gps.encode(ss.read()))                                        //  reads the serial character and sticks the character into the gps object
                                                                                               //  gps.encode( )  returns a true/false outcome,   did you look to see
                                                                                               // what this actually does ???
    {    
          if (millis() > 5000 && gps.charsProcessed() < 10)
          {
                   Serial.println(F("No GPS detected: check wiring."));
          }
          else
          {
                 // you didn't specify anything for else
          }
    }
    else
    {
            //  you didn't specify anything for else
    }
}       // end of while

Now the first problem, which is not your fault, it is the author of tinygps++ fault, is that neither the header file nor the cpp file for the tinygps++ class actually says " the encode( c ) function returns true, when the encoded character terminates a complete and checksummed sentence, and false otherwise ". You have to do quite a bit of analysis to figure out that this is what it does.

So in your code, you read a serial character from the gps device, stick it into the tinygps++ object, probably get a false return from encode( ) , and then do nothing after that. If you don't watch out for the true return from encode( ), which means you got a complete sentence, then how will you possibly know to send your radio message ?

And then, if encode( ) returns true, which means the gps device gave you a complete message, then you probably go and print an error message for that. This just doesn't make any sense.

The logic of the program has to follow the actual logic of the process that you are trying to accomplish.

Your code should look more like this:

void loop( )
{
     boolean got_completed_message = false ;
    while (  ss.available() > 0 )
    {
          if ( gps.encode(  ss.read( ) ) )
          {
               got_completed_message = true ;
               break ;    // exit the while loop,  there may be more characters available, but they can be processed next time
          }
          else   // keep doing the while
          {
          }
    }          // end while.     The while loop will repeat until you have read all the available characters from the gps module.

    //       the program reaches here is there are currently no more characters avail,  or we got a complete message and 
    //       jumped out of the loop
    if (  got_completed_message )
    {
         // the stuff to send the radio message goes here,   or in a separate function which gets called here
    }
    else  //  you didn't get a complete message yet,  keep waiting for the gps device to send more characters
    {
             // do nothing here,    loop( )  will start again from the beginning.
    }

    //  Add any irrelevant timeout check logic here.


    // end of loop function
}

Hi michinyon.

Thank you for your guidance and input.
I apologise for my blast with your previous comments, but they were not use-full, as I'm a newbie to code.
FOR THAT, I'M SORRY.

I will play around & research your advise.
As previously stated;
I'm trying to learn & have many books to reference to.
I don't want the code writing for me, ie like the last post you sent to this thread as an example, "so I can look at It a try to work It-out for myself.
But at some point i I get no further, & struggle, I will ask for an example, of how to write or what I'm missing, "newbie".

I think my main problem, Is how to package the information for the radios. "char or float", how to get that info, send It, then how to unpack It at the other end.

From looking through lots of material, I believe 'char or float' would be the best data type to use?

I appreciate that this Is a very ambitious project for a newbie, but I think this Is the best way for me to learn.

Dizzwold

dizzwold:
From looking through lots of material, I believe 'char or float' would be the best data type to use?

I appreciate that this Is a very ambitious project for a newbie, but I think this Is the best way for me to learn.

Dizzwold

I would start simple, and focus on your radio TX/RX.

Start with transmitting a single char from the transmitting radio (entered from the serial monitor) and processing that on the RX side by using Serial.print().

Just radio, just a single char until you get that working...

Dizzwold, I have a preliminary version of the nRF24L01 example I mentioned earlier, here:
http://arduino-info.wikispaces.com/RadioLink-Joystick-To-Servos

This is NOT just what you need, but it is an example of sending real-time data over the radio link.

My Grandson Noah wrote this, and I 'cleaned up' the examples to make it clear what is happening. I HOPE.. Perhaps the organization of the code examples would help you keep the complexity organized. I know I go crazy unless I do this. But that might be that I'm over 40. Also 50, 60, and 70 :slight_smile:

This uses the RadioHead library. Noah found the "ReliableDatagram" capability worked best.

Any comments/critique/suggestions would be appreciated.

If you won't believe me, then listen to the hippie.

I Seriously LOVE IT! :slight_smile: :slight_smile: :slight_smile:

Hi all.

Thank you for your replies and input regarding.

I've been doing more research, "ebooks and example sketches", to get a better idea of char's, & char array's.

@bulldog, yes, a very good idea. I have tested the radios with TMRh20's random number sketch, so will possibly reflect on this to do as you state, and learn something about char' & char array's.

@michinyon, your correct with regards to testing the GPS, as the serial monitor Is printing a different location, to my actual location and what the OLED states on the GPS development board, "using the example you posted". I will have to look into why this Is?
But again @michinyon, with the quote

If you won't believe me, then listen to the hippie./quote]

Why? There Is no need for this!
Because Terry, "I believe thats who you are referencing to", has posted a photo, you are being rude, Insulting and out of character regarding what "open source and forum" mean. In your previous posts to me, your point of attack has been at me! Granted "I'm a complete newbie". But now your attacking others that reply to this thread.
Again "I THANK YOU, MICHINYON FOR YOUR INPUT, BUT I WILL NOT ACCEPT YOUR INSULTS".

@terryking228, I can only apologies for the comments made buy michinyon.
"I'M SORRY FOR THIS".
I hope this won't deter you from posting again.
I've not looked at the link yet, that you've sent, but the idea of a dog withe a servo controlled laser could be fun, although I think I will get lots of complaints in the UK, let alone from other dog walkers.

Will have a look.

Thank you again for all you help and advise.

Dizzwold.