Parallax GPS sensor questions
I am having some trouble with understanding how this GPS sensor is sending data.
What I am trying to accomplish here is to to be able to take the RAW data coming from the GPS sensor and parse the information and output it how I want it to.
For example this is how I am trying to get an array of a NMEA string:
if(condition == true)
{
printOutGpsInfo()
}
printOutGpsInfo()
{
gpsData = -1
while(GpsData != 13)· //carriage return; so this will run until a carriage return is seen
gpsData = Serial.read();·· //this gets a character from the GPS sensor
if(gpsData = empty){
wait(100ms)
}
else{
array[noparse][[/noparse]i++]=gpsData;· //store that character
}
}
Granted this is not actual code just my logic. So what I am expecting is·my array·to contain is·information such as
[noparse][[/noparse]code] $GPRMC,225446,A,4916.45,N,12311.12,W,000.5,054.7,191194,020.3,E*68
[noparse][[/noparse]/code]
but sometimes it is and sometimes it isn't. Sometimes two strings will be run together sometimes it will just cut off in the middle of the string. If I change the while(GpsData != 13) to while(1) and just watch the data on my serial output everything looks fine.
This is an example of while(GpsData != 13)
[noparse][[/noparse]code] ,N,00440.5161,W,0,00,,-00044.7,M,051.6,M,,*6B $GPGSA,A,1,,,,,,,,,,,,,,,*1E $GPGSV,3,1,10,02$G154655,4328.1874,N,00340.5185,W,1,03,08.5,-0$GPGSA,A,2,13,23,25,,,,,,,,,,08.5,08.5,00.9*0E $GPGSV,3,1,10,02,50,290,26,04,60,210,26,08,33,173,29,10,21,296,00*7E $GPGSV,3,2,10,13,58,044,34,16,03,035,00,20,02,109,00,23,26,057,34*7B $GPGSV,3,3,10,,,,,,,,,*7D $GPRMC,154655,A,4428.,,,,,,,,,,,W,000.7,000.0,050407,,,A*6C [noparse][[/noparse]/code]it is totally random as well I can't figure out what its actually doing when this is happening. If I run while(1) and watch the data it is correct 100% of the time.But the problem is I can't do anything with this. I cant stay in this loop forever
Overall in words this is what I am wanting...
When I call printOutGpsInfo() I want my array to have each character in an element in the array.
[noparse][[/noparse]code]$GPRMC,225446,A,4916.45,N,12311.12,W,000.5,054.7,191194,020.3,E*68[noparse][[/noparse]/code]
I am really close to figuring this out and just need a little push in the right direction on what this actual GPS sensor is doing.
Edit: I know the GPS sensor works as I found some example code that works correctly but the GPS sensor has to constantly execute that code. You can look at it here.
http://www.arduino.cc/playground/Tutorials/GPS
GPS module: http://www.parallax.com/Store/Microcontrollers/BASICStampModules/tabid/134/txtSearch/GPS/List/1/ProductID/396/Default.aspx?SortField=ProductName%2cProductName
·
What I am trying to accomplish here is to to be able to take the RAW data coming from the GPS sensor and parse the information and output it how I want it to.
For example this is how I am trying to get an array of a NMEA string:
if(condition == true)
{
printOutGpsInfo()
}
printOutGpsInfo()
{
gpsData = -1
while(GpsData != 13)· //carriage return; so this will run until a carriage return is seen
gpsData = Serial.read();·· //this gets a character from the GPS sensor
if(gpsData = empty){
wait(100ms)
}
else{
array[noparse][[/noparse]i++]=gpsData;· //store that character
}
}
Granted this is not actual code just my logic. So what I am expecting is·my array·to contain is·information such as
[noparse][[/noparse]code] $GPRMC,225446,A,4916.45,N,12311.12,W,000.5,054.7,191194,020.3,E*68
[noparse][[/noparse]/code]
but sometimes it is and sometimes it isn't. Sometimes two strings will be run together sometimes it will just cut off in the middle of the string. If I change the while(GpsData != 13) to while(1) and just watch the data on my serial output everything looks fine.
This is an example of while(GpsData != 13)
[noparse][[/noparse]code] ,N,00440.5161,W,0,00,,-00044.7,M,051.6,M,,*6B $GPGSA,A,1,,,,,,,,,,,,,,,*1E $GPGSV,3,1,10,02$G154655,4328.1874,N,00340.5185,W,1,03,08.5,-0$GPGSA,A,2,13,23,25,,,,,,,,,,08.5,08.5,00.9*0E $GPGSV,3,1,10,02,50,290,26,04,60,210,26,08,33,173,29,10,21,296,00*7E $GPGSV,3,2,10,13,58,044,34,16,03,035,00,20,02,109,00,23,26,057,34*7B $GPGSV,3,3,10,,,,,,,,,*7D $GPRMC,154655,A,4428.,,,,,,,,,,,W,000.7,000.0,050407,,,A*6C [noparse][[/noparse]/code]it is totally random as well I can't figure out what its actually doing when this is happening. If I run while(1) and watch the data it is correct 100% of the time.But the problem is I can't do anything with this. I cant stay in this loop forever
Overall in words this is what I am wanting...
When I call printOutGpsInfo() I want my array to have each character in an element in the array.
[noparse][[/noparse]code]$GPRMC,225446,A,4916.45,N,12311.12,W,000.5,054.7,191194,020.3,E*68[noparse][[/noparse]/code]
I am really close to figuring this out and just need a little push in the right direction on what this actual GPS sensor is doing.
Edit: I know the GPS sensor works as I found some example code that works correctly but the GPS sensor has to constantly execute that code. You can look at it here.
http://www.arduino.cc/playground/Tutorials/GPS
GPS module: http://www.parallax.com/Store/Microcontrollers/BASICStampModules/tabid/134/txtSearch/GPS/List/1/ProductID/396/Default.aspx?SortField=ProductName%2cProductName
·
Comments
Here is the code if anyone wants it.
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <SoftwareSerial.h>
#define btrxPin 2
#define bttxPin 3
·int RFID = 0;
·int RFIDPin = 14;
·int rxPin = 0;··················· // RX PIN
·int txPin = 1;··················· // TX TX
·int temp = 0;
·int byteGPS=-1;
·char linea[noparse][[/noparse]300] = "";
·char readLine[noparse][[/noparse]200] = "";
·char comandoGPR[noparse][[/noparse]7] = "$GPRMC";
·int cont=0;
·int bien=0;
·int conta=0;
·int indices[noparse][[/noparse]13];
SoftwareSerial BTSerial = SoftwareSerial(btrxPin, bttxPin);
·void setup() {
·· pinMode(btrxPin, INPUT);
·· pinMode(bttxPin, OUTPUT);
·· pinMode(RFIDPin, INPUT);
·· Serial.begin(4800);
·· BTSerial.begin(9600);
·· for (int i=0;i<300;i++){······ // Initialize a buffer for received data
···· linea[noparse][[/noparse]i]=' ';
·· }
· for(int i = 0; i<200; i++)
· {
····· readLine[noparse][[/noparse]i]=' ';
· }
·}
void loop()
·{
·· RFID = digitalRead(RFIDPin);
··
·· if(RFID == HIGH)
·· {
···· BTSerial.println("Check the below location:");
···· BTSerial.println("");
···· //Serial.println("Check the below location:");
···· getGPRMC();
·· }
·}
void getGPRMC()
{
· temp = 0;
· int byteGPS;
· byteGPS = -1;
· int indices[noparse][[/noparse]13];
· int commaPlace[noparse][[/noparse]13];
· int count = 0;
· int cout = 0;
· int flag = 0;
·
· for(int i = 0; i < 13; i++)
· {
···· commaPlace[noparse][[/noparse]i] = ' ';
· }
·· Serial.flush();
·· while(byteGPS != 13 || readLine[noparse][[/noparse]0] != '$' || readLine[noparse][[/noparse]1] != 'G' || readLine[noparse][[/noparse]2] != 'P' || readLine[noparse][[/noparse]3] != 'R' || readLine[noparse][[/noparse]4] != 'M' || readLine[noparse][[/noparse]5] != 'C')
·· {
····· byteGPS = Serial.read();
····· if(byteGPS == -1)
····· {
········ delay(100);
····· }
····· else
····· {
······· //printByte(byteGPS);
······· if(byteGPS == '$')
······· {
········· temp = 0;
········· readLine[noparse][[/noparse]temp++] = byteGPS;·······
······· }
······· else
······· {
········· readLine[noparse][[/noparse]temp++] = byteGPS;
······· }
····· }
·· }
··
··· Serial.println("");
···
··· for(int i = 0; i<temp; i++)
··· {
····· Serial.print(readLine[noparse][[/noparse]i]);
··· }
··· Serial.println("");
··· /*
··· for(int i = 0; i<temp; i++)
··· {
······ if(readLine[noparse][[/noparse]i] == ',')
······ {
········ commaPlace[noparse][[/noparse]count++] = i;
······ }
······ else if(readLine[noparse][[/noparse]i] == '*')
······ {
········ commaPlace[noparse][[/noparse]12] = i;
······ }
··· }
···
··· for(int i = 0; i< 13; i++)
··· {
····· Serial.println(commaPlace[noparse][[/noparse]i]);
··· }
···
· */·
··· for(int i = 0; i < temp; i++)
··· {
····· if(readLine[noparse][[/noparse]i] == ',')
····· {
······ flag++;
····· }
····· if(flag == 1)
····· {
······· Serial.print("Time in UTC (HhMmSs): ");
······· BTSerial.print("Time in UTC (HhMmSs): ");
······· flag++;
····· }
····· else if(flag == 2)
····· {
········ Serial.print(readLine[noparse][[/noparse]i]);
········ BTSerial.print(readLine[noparse][[/noparse]i]);·
····· }
····· if(flag == 3)
····· {
······· Serial.println("");
······· Serial.print("Status (A=OK, V=KO): ");
······· BTSerial.println("");
······· BTSerial.print("Status (A=OK, V=KO): ");
······· flag++;
····· }
···· else if(flag == 4)
····· {
······· Serial.print(readLine[noparse][[/noparse]i]);
······· BTSerial.print(readLine[noparse][[/noparse]i]);
····· }
····· if(flag == 5)
····· {
······· Serial.println("");
······· Serial.print("Latitude: ");
······· BTSerial.println("");
······· BTSerial.print("Latitude: ");
······· flag++;
····· }
···· else if(flag == 6)
····· {
······· Serial.print(readLine[noparse][[/noparse]i]);
······· BTSerial.print(readLine[noparse][[/noparse]i]);
····· }
···· if(flag == 7)
····· {
······· Serial.println("");
······· Serial.print("Direction (N/S): ");
······· BTSerial.println("");
······· BTSerial.print("Direction (N/S): ");
······· flag++;
····· }
···· else if(flag == 8)
····· {
······· Serial.print(readLine[noparse][[/noparse]i]);
······· BTSerial.print(readLine[noparse][[/noparse]i]);
····· }
···· if(flag == 9)
····· {
······· Serial.println("");
······· Serial.print("Logitude: ");
······· BTSerial.println("");
······· BTSerial.print("Logitude: ");
······· flag++;
····· }
···· else if(flag == 10)
····· {
······· Serial.print(readLine[noparse][[/noparse]i]);
······· BTSerial.print(readLine[noparse][[/noparse]i]);
····· }
···· if(flag == 11)
····· {
······· Serial.println("");
······· Serial.print("Direction (E/W): ");
······· BTSerial.println("");
······· BTSerial.print("Direction (E/W): ");
······· flag++;
····· }
···· else if(flag == 12)
····· {
······· Serial.print(readLine[noparse][[/noparse]i]);
······· BTSerial.print(readLine[noparse][[/noparse]i]);
····· }
···· if(flag == 13)
····· {
······· Serial.println("");
······· Serial.print("Velocity in knots: ");
······· BTSerial.println("");
······· BTSerial.print("Velocity in knots: ");
······· flag++;
····· }
···· else if(flag == 14)
····· {
······· Serial.print(readLine[noparse][[/noparse]i]);
······· BTSerial.print(readLine[noparse][[/noparse]i]);·
····· }
···· if(flag == 15)
····· {
······· Serial.println("");
······· Serial.print("Heading in degrees: ");
······· BTSerial.println("");
······· BTSerial.print("Heading in degrees: ");
······· flag++;
····· }
···· else if(flag == 16)
····· {
······· Serial.print(readLine[noparse][[/noparse]i]);
······· BTSerial.print(readLine[noparse][[/noparse]i]);·
····· }
···· if(flag == 17)
····· {
······· Serial.println("");
······· Serial.print("Date UTC (DdMmYy): ");
······· BTSerial.println("");
······· BTSerial.print("Date UTC (DdMmYy): ");
······· flag++;
····· }
···· else if(flag == 18)
····· {
······· Serial.print(readLine[noparse][[/noparse]i]);
······· BTSerial.print(readLine[noparse][[/noparse]i]);········
····· }
····· /*
···· if(flag == 19)
····· {
······· Serial.println("");
······· Serial.print("Magnetic degrees: ");
······· flag++;
····· }
···· else if(flag == 20)
····· {
······· Serial.print(readLine[noparse][[/noparse]i]);
····· }
···· if(flag == 21)
····· {
······· Serial.println("");
······· Serial.print("(E/W) ");
······· flag++;
····· }
···· else if(flag == 22)
····· {
······· Serial.print(readLine[noparse][[/noparse]i]);
····· }
···· if(flag == 23)
····· {
······· Serial.println("");
······· Serial.print("Mode: ");
······· flag++;
····· }
···· else if(flag == 24)
····· {
······· Serial.print(readLine[noparse][[/noparse]i]);
····· }
*/·····
··· }
/*·· for (int i=0;i<temp+1;i++){
···· if (readLine[noparse][[/noparse]i]==','){··· // check for the position of the· "," separator
······ indices[noparse][[/noparse]cont]=i;
······ cont++;
···· }
···· if (readLine[noparse][[/noparse]i]=='*'){··· // ... and the "*"
······ indices[noparse][[/noparse]12]=i;
······ cont++;
···· }
·· }
········ Serial.println("");····· // ... and write to the serial port
········ Serial.println("");
········ Serial.println("
");
········ for (int i=0;i<12;i++){
·········· switch(i){
············ case 0 :Serial.print("Time in UTC (HhMmSs): ");break;
············ case 1 :Serial.print("Status (A=OK,V=KO): ");break;
············ case 2 :Serial.print("Latitude: ");break;
············ case 3 :Serial.print("Direction (N/S): ");break;
············ case 4 :Serial.print("Longitude: ");break;
············ case 5 :Serial.print("Direction (E/W): ");break;
············ case 6 :Serial.print("Velocity in knots: ");break;
············ case 7 :Serial.print("Heading in degrees: ");break;
············ case 8 :Serial.print("Date UTC (DdMmAa): ");break;
············ case 9 :Serial.print("Magnetic degrees: ");break;
············ case 10 :Serial.print("(E/W): ");break;
············ case 11 :Serial.print("Mode: ");break;
············ case 12 :Serial.print("Checksum: ");break;
·········· }
·········· for (int j=indices[noparse][[/noparse]i];j<(indices[noparse][[/noparse]i+1]-1);j++){
············ Serial.print(readLine[noparse][[/noparse]j+1]);
·········· }
········ }
· */
·· //while to the end...(byte13)
·· // Serial.println("");
··· for(int i = 0; i<200; i++)
··· {
····· readLine[noparse][[/noparse]i] = ' ';
··· }·
· delay(1500);
}
·
·
/*
void GPS()
{
··
·· byteGPS=Serial.read();········ // Read a byte of the serial port
·· if (byteGPS == -1) {·········· // See if the port is empty yet
···· delay(100);
·· } else {
···· linea[noparse][[/noparse]conta]=byteGPS;······· // If there is serial port data, it is put in the buffer
···· conta++;·····················
···· printByte(byteGPS);
···· if (byteGPS==13){··········· // If the received byte is = to 13, end of transmission
······ cont=0;
······ bien=0;
······ for (int i=1;i<7;i++){···· // Verifies if the received command starts with $GPR
········ if (linea[noparse][[/noparse]i]==comandoGPR[noparse][[/noparse]i-1]){
·········· bien++;
········ }
······ }
······ if(bien==6){·············· // If yes, continue and process the data
········ for (int i=0;i<300;i++){
·········· if (linea[noparse][[/noparse]i]==','){··· // check for the position of the· "," separator
············ indices[noparse][[/noparse]cont]=i;
············ cont++;
·········· }
·········· if (linea[noparse][[/noparse]i]=='*'){··· // ... and the "*"
············ indices[noparse][[/noparse]12]=i;
············ cont++;
·········· }
········ }
········ BTSerial.println("");····· // ... and write to the serial port
········ BTSerial.println("");
········ BTSerial.println("
");
········ for (int i=0;i<12;i++){
·········· switch(i){
············ case 0 :BTSerial.print("Time in UTC (HhMmSs): ");break;
············ case 1 :BTSerial.print("Status (A=OK,V=KO): ");break;
············ case 2 :BTSerial.print("Latitude: ");break;
············ case 3 :BTSerial.print("Direction (N/S): ");break;
············ case 4 :BTSerial.print("Longitude: ");break;
············ case 5 :BTSerial.print("Direction (E/W): ");break;
············ case 6 :BTSerial.print("Velocity in knots: ");break;
············ case 7 :BTSerial.print("Heading in degrees: ");break;
············ case 8 :BTSerial.print("Date UTC (DdMmAa): ");break;
············ case 9 :BTSerial.print("Magnetic degrees: ");break;
············ case 10 :BTSerial.print("(E/W): ");break;
············ case 11 :BTSerial.print("Mode: ");break;
············ case 12 :BTSerial.print("Checksum: ");break;
·········· }
·········· for (int j=indices[noparse][[/noparse]i];j<(indices[noparse][[/noparse]i+1]-1);j++){
············ BTSerial.print(linea[noparse][[/noparse]j+1]);
·········· }
·········· BTSerial.println("");
········ }
········ BTSerial.println("
");
······ }
······ conta=0;··················· // Reset the buffer
······ for (int i=0;i<300;i++){··· //·
········ linea[noparse][[/noparse]i]=' ';············
······ }················
···· }
·· }·
}
*/