Read NMEA strings over serial port with MT3329 and Arduino Mega 2560

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!

I would suggest you use the TinyGPS12 library by Mikal Hart... It's a whole lot easier than parsing GPS data on your own. It works well for me..
I would also suggest that you find out what the EN pin is too It just might be important

Does the TinyGPS library return the raw NMEA strings? I need the raw data for my research.

NMEA 0183 is the raw data stream. it is the native output of a component GPS receiver at a baud rate determined by the receiver mfr.
TinyGPS12 is a library to show position, heading, speed, altitude and course from the prime meridian in London England.. As I remember

Doc

Is the GPS outside? Most GPS units struggle to find a good "fix" in-doors.