Outils pour utilisateurs

Outils du site


gps_shield_em_411

GPS EM-411 & Arduino

Matétiel

Codes sources

Récupération de la trame simple

Le module GPS discute en liaison série simple.

Alimenté, il envoie des trames sans cesses.

le but est de récupérer cette trame

#include <NewSoftSerial.h>
 
NewSoftSerial GPS =  NewSoftSerial(2, 3);
 
void setup()
{
  GPS.begin(4800);
  Serial.begin(9600);
}
void loop()
{
  char someChar = GPS.read();
 
  Serial.print(someChar,BYTE);
  delay(100);
 
}
  • Résultat sur une serie
$GPGGA,184830.000,4451.8758,N,00033.6537,W,1,07,1.2,22.9,M,49.7,M,,0000*7E
$GPGSA,A,3,30,25,31,14,29,12,02,,,,,,1.8,1.2,1.3*33
$GPGSV,2,1,08,29,85,102,26,25,61,073,34,31,58,297,26,12,19,090,24*73
$GPGSV,2,2,08,14,19,222,17,30,18,289,26,02,18,044,14,21,16,170,*79
$GPRMC,184830.000,A,4451.8758,N,00033.6537,W,0.41,5.71,150512,,,A*7F

Pseudo Parser de cette trame

#include <SoftwareSerial.h>
 
SoftwareSerial GPS = SoftwareSerial(2,3);
 
int byteGPS=-1;
char linea[300] = "";
char comandoGPR[7] = "$GPRMC";
int cont=0;
int bien=0;
int conta=0;
int indices[13];
 
 
void setup(){
  GPS.begin(4800);
  Serial.begin(115200);
}
 
void loop(){
   byteGPS=GPS.read();         // Read a byte of the serial port
   if (byteGPS == -1) {           // See if the port is empty yet
     delay(100); 
   } else {
     linea[conta]=byteGPS;        // If there is serial port data, it is put in the buffer
     conta++;                      
     Serial.print(byteGPS, BYTE); 
     if (byteGPS==13){            // If the received byte is = to 13, end of transmission
//       digitalWrite(ledPin, LOW); 
       cont=0;
       bien=0;
       for (int i=1;i<7;i++){     // Verifies if the received command starts with $GPR
         if (linea[i]==comandoGPR[i-1]){
           bien++;
         }
       }
       if(bien==6){               // If yes, continue and process the data
         for (int i=0;i<300;i++){
           if (linea[i]==','){    // check for the position of the  "," separator
             indices[cont]=i;
             cont++;
           }
           if (linea[i]=='*'){    // ... and the "*"
             indices[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[i];j<(indices[i+1]-1);j++){
             Serial.print(linea[j+1]); 
           }
           Serial.println("");
         }
         Serial.println("---------------");
       }
       conta=0;                    // Reset the buffer
       for (int i=0;i<300;i++){    //  
         linea[i]=' ';             
       }                 
     }
   }
}
  • Exemple sur une série
---------------
Time in UTC (HhMmSs): 184830.000
Status (A=OK,V=KO): A
Latitude: 4451.8758
Direction (N/S): N
Longitude: 00033.6537
Direction (E/W): W
Velocity in knots: 0.41
Heading in degrees: 5.71
Date UTC (DdMmAa): 150512
Magnetic degrees: 
(E/W): 
Mode: A
gps_shield_em_411.txt · Dernière modification: 2015/01/28 03:09 (modification externe)