Help with Arduino Software serial Serial communication

srnet:
Yes, your first post should have decribed your project, it saves everyones time.

If you had, I would have said you can probably do all you want with a few lines of code and the TinyGPSplus library.

WOW... Tons of information to think about !!!
Thanks :slight_smile:

So far after 5 days of reading and searching i have failed to find a way to do work with the serial input from my gps...

Tinygps++ is an excellent library but from what i understand i can use it to collect the nmea information from the gps to the arduino and display them on a pc via the arduino ide serial terminal ...

What i hope to do is use the arduino as a standalone device that will control a relay according to the state of the incomeing NMEA from each gps receiver. the relay in turn will feed that nmea directly fron the receivers to the computer. The arduino is actually used to "tap" in the serial outputs of each gps receiver and decide which one to connect with the pc. That is why i also need a timeout when a gps is not turned on or not transmitting the GSA, because i will then need to turn the relay and connect the pc with the other one that works.

PLEASE dont get me wrong, i do not asking you people to write the code for me.
I am only seeking advice and maybe if possible some help with coding. If possible.

THANK YOU !

You sent me a PM asking me to look at this Thread. I'm not sure how I can help. I have no experience of using TinyGPS.

Maybe the best thing is to post the latest version of your program taking account of what you have learned and tell us exactly what it does and what you want it to do that is different.

...R

rossi123:
yes it's true i think the best thing to do is maybe to publish the latest version of your program with some reservations of course on the version

When I used the word "your" I meant the program written by @rossi123 :slight_smile:

...R

Robin2:
You sent me a PM asking me to look at this Thread. I'm not sure how I can help. I have no experience of using TinyGPS.
Maybe the best thing is to post the latest version of your program taking account of what you have learned and tell us exactly what it does and what you want it to do that is different.
...R

Will do sir !

P.S. Would it help if i post the code i use on the picaxe ? Just a thought.

Robin2:
When I used the word "your" I meant the program written by @rossi123 :slight_smile:
...R

I am not sure who @rossi123 is :frowning: . Are you talking about the tinygps++ code ?
I will.

HellasT:
I am not sure who @rossi123 is

Just ignore that. I believe there was a Reply from @rossi123 which now seems to have been deleted and I mistakenly thought s/he was the OP. Apologies for the confusion.

If the picaxe code is short then let's have it. Otherwise let's wait and see, it may not be needed.

...R

Please there is nothing for you to apologies for.

I have to apologize because the fact that i do not know how to proceed with my project is ourely because i have no idea about C and C++ and i understand almost nothing from the example codes and the libraries..

I made the code short :slight_smile:

I have removed all the parts that i know how to do. Meaning how to check if a variable == an other variable or how to turn on a led according to a variable's value.

Please excuse my hand writing but i know of no other way show you what it all are about.

PICAXE CODE.pdf (1.04 MB)

I think that first i need to find a way to (timeout) tell the arduino to move to an other part of the code if ("GSA") does not arrive at a pre defined time frame.

Then i need to find a way to tell the arduino to look only for the GSA sentence and then store its content into variables or into an array.
Here i have to say that a line feed could probably be used to tell the arduino to stop saving characters since the sentence is complete. Each NMEA sentence starts with $GP... and ends with carriage return and line feed. Or a pre defined array length could be used.

Then i will have to come up with a way to read the values that are of interest into the array or read the variables that hold the values of interest so that by using operators (== , >= , etc) the arduino will later know what to do with the relay.

Let's try to make things simple.

As far as I can see a GPS message starts with '$' and ends with '\n' so try Example3 from my tutorial with those characters as the start- and end-markers and let me know if it receives the messages correctly. Never mind for the moment that it gets all the messages.

Post a sample of the output from the program.

...R

I see your problem as quite simple, your probably trying to replicate the PICAXE code, rather than writing a solution to the problem.

The GPGSA sentence will be there, but empty, if the GPS RF side has stopped working, it cannot be used as an indication of the GPS working.

The TinyGPS++ library will tell you;

If the location has updated since the last check, if it has not updated, then the GPS is de-facto not working.
Tell you the latest HDOP value and whether its stopped updating, i.e. GPS is not working.
Tell you how many characters have been processed from the GPS.
Tell you how many valid sentences have been processed.
Tell you in mS how long its been since a parameter was updated, lat, lon, time, HDOP etc.

There must be a gazillion different ways\combinations there of telling whether a GPS is still 'working'

Robin2:
Let's try to make things simple.
As far as I can see a GPS message starts with '$' and ends with '\n' so try Example3 from my tutorial with those characters as the start- and end-markers and let me know if it receives the messages correctly. Never mind for the moment that it gets all the messages.
Post a sample of the output from the program.
...R

Understood..

srnet:
I see your problem as quite simple, your probably trying to replicate the PICAXE code, rather than writing a solution to the problem.

Yes. That is because i dont know any other way. I think due to my lack of knowledge on C & C++ .

srnet:
The GPGSA sentence will be there, but empty, if the GPS RF side has stopped working, it cannot be used as an indication of the GPS working.

Yes and that is why on the picaxe code u udes the 1,2,3 indicator where 1=no fix, 2=2d fix and 3 =3dfix.
when number was 1 or 2 then the GPS receiver was considerd unreliable begause GPGSA would give empty fields.

srnet:
The TinyGPS++ library will tell you;
If the location has updated since the last check, if it has not updated, then the GPS is de-facto not working.
Tell you the latest HDOP value and whether its stopped updating, i.e. GPS is not working.
Tell you how many characters have been processed from the GPS.
Tell you how many valid sentences have been processed.
Tell you in mS how long its been since a parameter was updated, lat, lon, time, HDOP etc.
There must be a gazillion different ways\combinations there of telling whether a GPS is still 'working'

I think so. If i could understand the language maybe i would be able to figure this out by reading the Tinygps++ library source code that is shown in the below link:

Dont let me be misunderstood. I am not asking you to do that for me. :slight_smile: I know you are all already helping as you can.

Google is your friend;

Try a search on 'TinyGPS++' for a well written, easy to understand, set of instructions.

There is even an explanation on how to set up custom extractions;

"Custom NMEA Sentence Extraction

One of the great new features of TinyGPS++ is the ability to extract arbitrary data from any NMEA or NMEA-like sentence."

So if you want to pull a specific field from the GPGSA, its easy enough.

I have tried that and i can get the fields i wand but then how can i process them ? how can i set timeouts etc ?

Robin2:
Let's try to make things simple.
As far as I can see a GPS message starts with '$' and ends with '\n' so try Example3 from my tutorial with those characters as the start- and end-markers and let me know if it receives the messages correctly. Never mind for the moment that it gets all the messages.
Post a sample of the output from the program.
...R

Okay i used the Only receive version of the software serial library. also i altered the numChars to 50 so it will fit the whole GSA sentence and modified start market to '$' and end marker to "\n".
The serial terminal can not read correctly... See Picture 1.

When i changed the end marker to '*' it looks like it can receive correctly. See picture 2.

HellasT:
I have tried that and i can get the fields i wand but then how can i process them ? how can i set timeouts etc ?

Check the TinyGPSPlus library, there is an example of how to detect if a GPS is not connected ...........

Images from Reply #33 so we don't have to download them. See this Simple Image Guide

...R

Please don't post pictures of text - they are unreadable. Just copy and paste the text.

If you can receive the messages then you can use the strstr() function to test whether a message contains the characters you are interested in.

I have no experience of the TinyGPS library but I suspect it will do the same thing but much easier.

...R

Okay i will be more careful with the pictures.

Here is the example 3 code modified a little bit. It seems to work. Though i could not make it use the \n as end marker... i dont know why. I will read about strstr() function and i will let you know if i make progress. THANK YOU.

#include <ReceiveOnlySoftwareSerial.h>
ReceiveOnlySoftwareSerial gps1serial(4); // RX
const byte numChars = 50;
char receivedChars[numChars];
boolean newData = false;

void setup() 
{
   Serial.begin(9600);
   gps1serial.begin(4800);
   Serial.println("<Arduino is ready>");
}

void loop() 
{
   recvWithStartEndMarkers();
   showNewData();
}

void recvWithStartEndMarkers() 
{
   static boolean recvInProgress = false;
   static byte ndx = 0;
   char startMarker = '

;
  char endMarker = '*';
  char rc;

while (gps1serial.available() > 0 && newData == false)
  {
      rc = gps1serial.read();

if (recvInProgress == true)
      {
          if (rc != endMarker)
          {
              receivedChars[ndx] = rc;
              ndx++;
              if (ndx >= numChars)
              {
                  ndx = numChars - 1;
              }
          }
          else
          {
              receivedChars[ndx] = '\0'; // terminate the string
              recvInProgress = false;
              ndx = 0;
              newData = true;
          }
      }

else if (rc == startMarker)
      {
          recvInProgress = true;
      }
  }
}

void showNewData()
{
  if (newData == true)
  {
      Serial.print("This just in ... ");
      Serial.println(receivedChars);
      newData = false;
  }
}

Robin2:
I have no experience of the TinyGPS library but I suspect it will do the same thing but much easier.
...R

I really do not know.

srnet:
Check the TinyGPSPlus library, there is an example of how to detect if a GPS is not connected

I failed to find about it. I am not sure why...

To make it easy for people to help you please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

...R