NEO6M GPS Module not returning any data

I am using NEO6M GPS Module which I had bought from Buy Ublox Neo 6M GPS Module at Low Price In India | Robu.in . The library that I’m using is TinyGPS++ and the code is:

#include <SoftwareSerial.h>
#include <TinyGPS++.h>
SoftwareSerial gpsSerial(1, 0); //(tx, rx)
TinyGPSPlus gps;
double latitude,longitude;

void setup() {

gpsSerial.begin(9600);
Serial.begin(9600);

}

long data;

void loop()
{
while (gpsSerial.available())
{
data = gpsSerial.read();
if (gps.encode(data)>0)
{
latitude = (gps.location.lat());
longitude = (gps.location.lng());
Serial.print ("latitude: ");
Serial.println (latitude);
Serial.print ("longitude: ");
Serial.println (longitude);
Serial.print("Speed in km/h = ");
Serial.println(gps.speed.kmph());
}
}
}

I’ve connected the VCC of the module to 5V instead of 3.3V of Arduino Mega 2560, ground to ground, and RX to digital pin 0 and tx to digital pin 1 directly.

The only output I get is NMEA Sentences only when I press the reset button on the Mega. Otherwise the loop doesn’t run. Also, through Serial monitor i got to know that gpsSerial.read() is returning value -1.
The NMEA Sentences are giving the right data so I suppose my module is working fine. Is there a problem with my Mega, connections or is there any problem with the library code. Kindly help.

Since you see the NMEA sentences on the monitor with the reset button down, you know two things:

. the GPS module is working; even w/o a fix, it will still output legible sentences (lots of empty fields if no fix)
. your connections are correct (does the RX LED light up?)

I think it is not normal to use software serial on pins 0 & 1. It is usually applied to other digital pins. Try 2 & 3.

John.

Hello John!
Yes, the Module is working as it gave correct information (Time, Location coordinates, sea level height, etc.) in the NMEA sentences that came up. But the RX LED doesn't light up. Also, it may sound strange but when I use any other pins except 1 and 0 for Tx and Rx respectively, I don't get any data even on pressing the reset button.

I think that the code is only running through the void setup() function but the gpsSerial.read() command is returning -1. I am unable to understand where did the data get lost.

Manas

Hi Manas.

Pins 0 & 1 form the Arduino's hardware serial port. Connecting your serial device (the GPS) to these pins allows the IDE monitor to communicate directly with the device. So the data emitted by the GPS appears in the monitor.

BUT! You must not have a sketch running that uses the hardware serial port (yours is). The GPS and the sketch conflict over the port. By pressing RESET (or connecting RESET pin to GND) you kill the sketch and avoid the conflict. Pins 2&3 do not form a h/w serial port so the data received will not automatically go to the monitor -- you use software serial to achieve that.

With your sketch, did you follow an example? Mikal's TinyGPS++ library comes with an example that I had no trouble using.

Thanks a lot for that explanation!

I tried the example sketches provided with the library, and connected the gps to pin 3 and 4 as mentioned in the example codes too. But, the examples return output that no gps is detected, check wiring (I checked it). Also, at the same time the LED of the GPS module indicates that it is fixed and is working fine. The Rx LED on Mega is also blinking now.

Post the example code you used. Also details of how you wired things up.

Example code:

#include <TinyGPS++.h>
#include <SoftwareSerial.h>
/*
This sample sketch demonstrates the normal use of a TinyGPS++ (TinyGPSPlus) object.
It requires the use of SoftwareSerial, and assumes that you have a
4800-baud serial GPS device hooked up on pins 4(rx) and 3(tx).
*/
static const int RXPin = 4, TXPin = 3;
static const uint32_t GPSBaud = 9600; //Default baud rate of Neo6M is 9600

// The TinyGPS++ object
TinyGPSPlus gps;

// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);

void setup()
{
Serial.begin(115200);
ss.begin(GPSBaud);

Serial.println(F(“DeviceExample.ino”));
Serial.println(F(“A simple demonstration of TinyGPS++ with an attached GPS module”));
Serial.print(F("Testing TinyGPS++ library v. ")); Serial.println(TinyGPSPlus::libraryVersion());
Serial.println(F(“by Mikal Hart”));
Serial.println();
}

void loop()
{
// This sketch displays information every time a new sentence is correctly encoded.
while (ss.available() > 0)
if (gps.encode(ss.read()))
displayInfo();

if (millis() > 5000 && gps.charsProcessed() < 10)
{
Serial.println(F(“No GPS detected: check wiring.”));
while(true);
}
}

void displayInfo()
{
Serial.print(F(“Location: “));
if (gps.location.isValid())
{
Serial.print(gps.location.lat(), 6);
Serial.print(F(”,”));
Serial.print(gps.location.lng(), 6);
}
else
{
Serial.print(F(“INVALID”));
}

Serial.print(F(" Date/Time: “));
if (gps.date.isValid())
{
Serial.print(gps.date.month());
Serial.print(F(”/"));
Serial.print(gps.date.day());
Serial.print(F("/"));
Serial.print(gps.date.year());
}
else
{
Serial.print(F(“INVALID”));
}

Serial.print(F(" “));
if (gps.time.isValid())
{
if (gps.time.hour() < 10) Serial.print(F(“0”));
Serial.print(gps.time.hour());
Serial.print(F(”:"));
if (gps.time.minute() < 10) Serial.print(F(“0”));
Serial.print(gps.time.minute());
Serial.print(F(":"));
if (gps.time.second() < 10) Serial.print(F(“0”));
Serial.print(gps.time.second());
Serial.print(F("."));
if (gps.time.centisecond() < 10) Serial.print(F(“0”));
Serial.print(gps.time.centisecond());
}
else
{
Serial.print(F(“INVALID”));
}

Serial.println();
}

Connections:

VCC of gps module is connected to 3.3V pin of arduino mega
GND of gps module if connected to GND of Mega
Rx goes to Digital pin 4
and Tx goes to Digital Pin 3

every new guy gets told this, frequently in a less polite fashion:

Read "How To Use This Forum"

This is what happens when you do not

you do not need software serial on a Mega. the mega has 4 Serial ports

just the code you need and nothing else to give you problems:

void setup()
{
Serial.begin(9600);                                    // set serial monitor rate to 9600 bps
Serial3.begin(9600);                                  // GPS    Serial setup
}
void loop()
{
  while (Serial3.available())                           // look for data from GPS module
  {
     char c = Serial3.read();                             // read in all available chars   
     Serial.print(c);                                            // for diagnostics
  }
}

GPS RX from pin 14
you don't need GPS TX, but if you must, pin 15
verified working with a NEO6 on a Mega at the moment

Thank you for the information! It works perfectly now. Thanks a lot! :slight_smile: :slight_smile:

Shishimaru:
Thank you for the information! It works perfectly now. Thanks a lot! :slight_smile: :slight_smile:

If your stuck on an Arduino problem, you can as a last resort read the reference page for the function you are having problems with, a Google search on;

'Arduino softwareserial reference'

Should point to the reference page for SoftWareSerial.

That page will tell you that SoftwareSerial RX is not supported on pins 3 or 4 of a Mega;

Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69).

Okay! :smiley: