I am currently trying to read the NMEA strings otput by the MT3329 GPS by Mediatek. With the code that I have written only some of the strings are output and the rest are all only the first character in the string.
Example:
returned GPS dataGPS buffer: GPRMC,001027.035,V,,,,,0.00,0.00,060180,,,N*40
END
Getting GPS data
unlocked
locked
returned GPS dataGPS buffer: G
END
Getting GPS data
unlocked
locked
returned GPS dataGPS buffer: GPGSV,1,1,00*79
There are supposed to be other strings with the titles of GPGGA and GPGSA but the only part of the string that is output is ‘G’.
I am using an Arduino Mega and connecting the GPS to Serial1. I have also left the EN pin on the GPS unconnected since I’m not sure what it does.
Here is my code:
// Arduino Mega 2560 R3
#include <string.h>
#define dbg(str) Serial.print(str)
#define portGPS Serial1
long int timerGPS = 0;
int returnedGPS = 0;
int lockedGPS = 1;
char buffGPS[50];
int iGPS = 0;
void setup(){
Serial.begin(9600); // Arduino to computer
dbg("Debug port 0 initialized\n");
portGPS.begin(38400); // MT3328 to Arduino
dbg("Peripheral port initialized\n");
}
#define TIMEOUT 5000
void loop(){
returnedGPS = 0;
timerGPS = millis();
dbg("Getting GPS data\n");
while((millis() - timerGPS < TIMEOUT) && !returnedGPS){
getGPS();
}
if(!returnedGPS){
dbg("GPS timed out!\n");
}else dbg("returned GPS data");
dbg("GPS buffer: ");
dbg(buffGPS);
dbg("\nEND\n");
}
void getGPS(){
int inByte;
if(portGPS.available()){
inByte = portGPS.read();
}
if(lockedGPS){
if(inByte == 36) {
dbg("unlocked\n");
lockedGPS = 0;
iGPS = 0;
}
}
else{
if(inByte == 10){
dbg("locked\n");
lockedGPS = 1;
returnedGPS = 1;
}
else buffGPS[iGPS] = inByte;
iGPS++;
}
}
I think something is wrong in the code. But maybe it could be the hardware. I’m not sure.
Thanks for your suggestions!