Is this correct?

Hi all I wish to read:

MSL Altitude from GPGGA

UTC Time, Latitude, Longtitude, Speed over Ground, Date from GPRMC

Pretty noob to Arduino programming, is the code below correct? I dont seem to be getting any output, can anyone advise me?

#include <string.h>
#include <ctype.h>
char data;
int byteGPS=-1;
char linea[300] = "";
int conta=0;
int loopcount = 0;
char comandoGPR[7] = "$GPRMC";
char comandoGPA[7] = "$GPGGA";
int bien=0;
int bien2=0;

void setup()
{
Serial2.begin(57600); // set to the tx and rx as per xbee pin. currently this is TX 0
Serial1.begin(4800); // this is GPS fixes.
for (int i=0;i<300;i++)
{ // Initialize a buffer for received data
linea[i]=' ';
}
}
void loop()
{
//byteGPS=Serial2.read(); // Read a byte of the Serial2 port
byteGPS=Serial1.read();
if (byteGPS == -1)
{ // See if the port is empty yet
delay(100);
}
else
{
linea[conta]=byteGPS; // If there is Serial2 port data, it is put in the buffer
conta++;
//Serial2.println(byteGPS, BYTE);
if (byteGPS==13)
{ // If the received byte is = to 13, end of transmission
//for (i=0,)
bien=0;
bien2=0;
for (int i=1;i<7;i++)
{ // Verifies if the received command starts with $GPR
//Serial2.print(linea[i]);
//Serial2.print(",");
//Serial2.println(comandoGPR[i-1]);
if (linea[i]==comandoGPR[i-1])
{
bien++;
}
if (linea[i]==comandoGPA[i-1])
{
bien2++;
}
}
if (bien == 6)
{
for (int i=0; i<conta;i++)
{
Serial2.print(linea[i]);
}
}

if (bien2 == 6)
{
for (int i=0; i<conta;i++)
{
Serial2.print(linea[i]);
}
//Serial2.println("//////////////////////////////////////");
}
conta=0; // Reset the buffer
for (int i=0;i<300;i++)
{
linea[i]=' ';
}
}
}

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Replies

  • Btw I am using a MediaTek MT3329 GPS 10Hz + Adapter that is connected to an Ardupilot Mega with IMU shield/oil pan

This reply was deleted.

Activity