Pages: [1]   Go Down
Author Topic: programmung question  (Read 710 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hello ,

i've extracted an GPs string looks like:

$GPRMC,163931.000,A,5131.2865,N,00727.3957,E,0.37,303.93,240312,,,A*6C

and now i want to grab only the Longitude and latidue
i worked with comma positions but the program only give me the string after first comma up to last comma.... looks like:

$GPRMC
164137.000
A
5131.2847
N
00727.4010
E
0.85
65.61
240312

is there any way to say give me the text between comma 3 and 4 and 5 to 6????

thank a lot for answer smiley


Logged

Austin, TX
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6106
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What code did you use to extract those?
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

#include <string.h>
#include <ctype.h>
 
  int ledpin = 13;     // LED test pin
  char speicher[80];
  int commaPosition;
  int i;
 
  void setup(){
   
    pinMode(ledpin, OUTPUT);
    Serial.begin(4800);
    Serial1.begin(4800);
   
  }
 
   void loop(){
   
    digitalWrite(ledpin,HIGH);
   
     while (Serial1.available())
     {
      speicher = Serial1.read();
     
      if (speicher[i++] == 10) // überprüfung einer neuen Zeile ( == 10 ist wie '\n')
     {
      speicher[i-1] = '\0'; // Ende einer Zeile -> Ende des Strings
      if (speicher[0] == '$' && speicher[1] == 'G' && speicher[2] == 'P' && speicher[3] == 'R' && speicher[4] == 'M' && speicher[5] == 'C')
     {
       if(speicher[18]=='A') // ist der status ok mach weiter (an 18ter Stelle steht ein "A")
       {
       String newStr=speicher;      // char speicher to string new string kopoieren
       Serial.println(newStr);
       do
       {
       commaPosition=newStr.indexOf(',');
       if(commaPosition!=-1)
       {
       Serial.println(newStr.substring(0,commaPosition));
       newStr=newStr.substring(commaPosition+1,newStr.length());
       }}
       while(commaPosition>=0);
       delay(5000);
       
       }
       else
       {
         Serial.println("Wait for Valid signal...");
       }
     }
     i=0; // Den Positionszeiger wieder auf den Anfang des Arrays setzen
    }
  }
}

 
   
 
 

   
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 289
Posts: 25697
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Again, with CODE TAGS please.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

  void loop(){
   
    digitalWrite(ledpin,HIGH);
   
     while (Serial1.available())
     {
      speicher = Serial1.read();
     
      if (speicher[i++] == 10) // überprüfung einer neuen Zeile ( == 10 ist wie '\n')
     {
      speicher[i-1] = '\0'; // Ende einer Zeile -> Ende des Strings
      if (speicher[0] == '$' && speicher[1] == 'G' && speicher[2] == 'P' && speicher[3] == 'R' && speicher[4] == 'M' && speicher[5] == 'C')
     {
       if(speicher[18]=='A') // ist der status ok mach weiter (an 18ter Stelle steht ein "A")
       {
       String newStr=speicher;      // make char to string
       Serial.println(newStr);
       do
       {
       commaPosition=newStr.indexOf(',').
       if(commaPosition!=-1).   // if there is a comma 
       {
       Serial.println(newStr.substring(0,commaPosition)); //write text after first comma in substring and give it to serial port 
       newStr=newStr.substring(commaPosition+1,newStr.length()); // copy after. Comma till end of string in newstr
       }}
       while(commaPosition>=0);
       delay(5000);
       
       }
       else
       {
         Serial.println("Wait for Valid signal...");
       }
     }
     i=0; // Den Positionszeiger wieder auf den Anfang des Arrays setzen
    }
  }
}
In arduino cookbook at chapter 2.5 is a description about comma position if u dont understand my tags smiley)

Thx for interest smiley
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

http://www.poliedit.com/vroc/AC.pdf
Heres a link to cookbook
Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Again, with CODE TAGS please.

AWOL didn't mean adding comments, he meant for you to repost your sketch wrapped in [code]...[/code] tags. Paste the code in, then select it and press the '#' button above the text entry box.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
#include <string.h>
#include <ctype.h>
 
  int ledpin = 13;     // LED test pin
  char speicher[80];
  int commaPosition;
  int i;
 
  void setup(){
   
    pinMode(ledpin, OUTPUT);
    Serial.begin(4800);
    Serial1.begin(4800);
   
  }
 
   void loop(){
   
    digitalWrite(ledpin,HIGH);
   
     while (Serial1.available())
     {
      speicher = Serial1.read();
     
      if (speicher[i++] == 10) // überprüfung einer neuen Zeile ( == 10 ist wie '\n')
     {
      speicher[i-1] = '\0'; // Ende einer Zeile -> Ende des Strings
      if (speicher[0] == '$' && speicher[1] == 'G' && speicher[2] == 'P' && speicher[3] == 'R' && speicher[4] == 'M' && speicher[5] == 'C')
     {
       if(speicher[18]=='A') // ist der status ok mach weiter (an 18ter Stelle steht ein "A")
       {
       String newStr=speicher;      // char speicher to string new string kopoieren
       Serial.println(newStr);
       do
       {
       commaPosition=newStr.indexOf(',');
       if(commaPosition!=-1)
       {
       Serial.println(newStr.substring(0,commaPosition));
       newStr=newStr.substring(commaPosition+1,newStr.length());
       }}
       while(commaPosition>=0);
       delay(5000);
       
       }
       else
       {
         Serial.println("Wait for Valid signal...");
       }
     }
     i=0; // Den Positionszeiger wieder auf den Anfang des Arrays setzen
    }
  }
}

 
   
 
 

   
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thx smiley
Sry im a noob smiley-razz
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There is a TinyGPS library for collecting GPS data with the waste of using Strings, AND it knows how to parse the data. Why are you not using that?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

jeps i know ^^ but i will do it in my own way and now i have the solution smiley-wink

working with pointers
 works really nice 4 me


thx
Logged

Hannover, Germany
Offline Offline
Jr. Member
**
Karma: 0
Posts: 52
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Perhaps you will try the function "strtok".

best regards
Andreas
Logged

http://danimathblog.blogspot.com

#define true '/'/'/'
#define false '-'-'-'

Pages: [1]   Go Up
Jump to: