I cannot read NEO-6M gps serial data

Hie,

Using UNO I just want see all data send by GPS NEO-6M in IDE serial monitor
I see only “waiting data”
what is wrong ?

 #include <string.h>
 #include <ctype.h>

 int ledPin = 13;                  // LED test pin
 int rxPin = 0;                     // RX PIN
 int txPin = 1;                     // TX PIN
 int byteGPS=-1;
 char linea[300] = "";
 int cont=0;
 int bien=0;
 int conta=0;
 int indices[13];

 void setup() {
    pinMode(ledPin, OUTPUT);       // Initialize LED pin
    pinMode(rxPin, INPUT);
    pinMode(txPin, OUTPUT);
    Serial.begin(9600);
    while (!Serial) { ;} // wait for serial port to connect. Needed for native USB port only
    Serial.println("Serial Connected");
    for (int i=0;i<300;i++){       // Initialize a buffer for received data
       linea[i]=' ';
    }   
 }

 void loop() {
    digitalWrite(ledPin, HIGH);
    byteGPS=Serial.read();         // Read a byte of the serial port
    Serial.print(byteGPS); 
    if (byteGPS == -1) {           // See if the port is empty yet
       Serial.println("waiting data");
       digitalWrite(ledPin, LOW);
       delay(200); 
    } else {
       Serial.println("data comming");
    }
 }

wired
tx gps to rx uno and rx gps to tx uno

disconnect pin 1 (arduino TX is not needed) Try different speeds

You should wait until characters are actually received, before using Serial.read()

See Serial Input Basics.

The main problem is that characters arrive very infrequently. At 9600, there is 1ms between each character. That is an eternity to a 16MHz process. In fact, loop will get called ~240 times for each character.

If you want to see the raw NMEA data, just use this simple echo program:

void setup()
{
  Serial.begin( 9600 );
}

void loop()
{
  if (Serial.available())
    Serial.write( Serial.read() );
}

If you are going to parse the received data, you might be interested in my NeoGPS library. It is smaller, faster, more reliable and more accurate than all other libraries. The examples are structured properly, and can usually be modified without breaking them. Be sure to work through the Installation instructions, to make sure you have the correct configuration. The docs also have some good Troubleshooting tips.

Here’s a sketch the echoes the raw data and parses it into a fix structure, toggling the LED during the GPS quiet time:

#include <NMEAGPS.h>

NMEAGPS gps; // parses the characters into...
gps_fix fix; //   ... this structure (a group of all the GPS pieces)

#define gpsPort Serial
  // This is just an "alias" for the GPS port.
  //   Later, if you put the GPS device on a different pin, you just have to
  //   change this definition, not all the places you use it below.

const int ledPin      = 13;      // LED test pin
bool      waitingData = true;

void setup() {
  pinMode(ledPin, OUTPUT);       // Initialize LED pin

  Serial.begin(9600); // this controls pins 0 & 1 for you.
  Serial.println( F("Serial Connected") );

  //gpsPort.begin( 9600 ); // not needed if gpsPort *is* Serial
}

void loop() {

  if (gpsPort.available()) {  // Was a character received yet?
    char c = gpsPort.read();

    // Data is now coming from the GPS device, but print the message only *ONCE*.
    if (waitingData && ((c != '\r') && (c != '\n'))) {
                       // Ignore the last CR/LF chars at first
      waitingData = false;
      digitalWrite(ledPin, HIGH);
      Serial.println( F("data coming") );
    }

    Serial.write( c ); // show the raw NMEA data
    gps.handle( c );   // parse the data (a fix structure *may* become available)

    if (gps.available()) { // finally parsed enough characters
      fix = gps.read();
      printGPSinfo();

      //  Now the GPS will be "quiet" for a while
      //    (Except for the last CR/LF... that's checked for above.)
      waitingData = true;
      digitalWrite(ledPin, LOW);
      Serial.println("waiting data");
    }
  }

} // loop

void printGPSinfo()
{
  // This is taken from the example NMEAsimple.ino

  Serial.print( F("\nLocation: ") );
  if (fix.valid.location) {
    Serial.print( fix.latitude(), 6 );
    Serial.print( ',' );
    Serial.print( fix.longitude(), 6 );
  }

  Serial.print( F(", Altitude: ") );
  if (fix.valid.altitude)
    Serial.print( fix.altitude() );

  Serial.println();
}

If you don’t need to echo the raw data, you could use a much simpler sketch:

#include <NMEAGPS.h>

NMEAGPS gps; // parses the characters into...
gps_fix fix; //   ... this structure (a group of all the GPS pieces)

#define gpsPort Serial

const int ledPin      = 13;      // LED test pin
bool      waitingData = true;

void setup() {
  pinMode(ledPin, OUTPUT);       // Initialize LED pin

  Serial.begin(9600); // this controls pins 0 & 1 for you.
  Serial.println( F("Serial Connected") );

  //gpsPort.begin( 9600 ); // not needed if gpsPort *is* Serial
}

void loop() {

  if (gps.available( gpsPort )) { // finally parsed enough characters?
    fix = gps.read();
    printGPSinfo();

    //  Now the GPS will be "quiet" for a while
    waitingData = true;
    digitalWrite(ledPin, LOW);
  }

  if (waitingData && !gps.is_safe()) {
    // GPS quiet time is over
    waitingData = false;
    digitalWrite(ledPin, HIGH);
  }

} // loop


void printGPSinfo()
{
  Serial.print( F("Location: ") );
  if (fix.valid.location) {
    Serial.print( fix.latitude(), 6 );
    Serial.print( ',' );
    Serial.print( fix.longitude(), 6 );
  }

  Serial.print( F(", Altitude: ") );
  if (fix.valid.altitude)
    Serial.print( fix.altitude() );

  Serial.println();
}

If you want to try it, NeoGPS is available from the Arduino IDE Library Manager, under the menu Sketch → Include Library → Manage Libraries.

Cheers,
/dev