Mega 2560 GPS NEO6MV2 check wiring

Hi,

I was using NEO6MV2 with arduino uno without any problem, due to my project i switched to Mega 2560 and connected the same way arduino;

VCC : 3.3V
GND . GND
RX : D4
TX : D3

and uploaded this example :

#include <TinyGPS++.h>
#include <SoftwareSerial.h>
/*
   This sample code 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 = 4800;

// 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("FullExample.ino"));
  Serial.println(F("An extensive example of many interesting TinyGPS++ features"));
  Serial.print(F("Testing TinyGPS++ library v. ")); Serial.println(TinyGPSPlus::libraryVersion());
  Serial.println(F("by Mikal Hart"));
  Serial.println();
  Serial.println(F("Sats HDOP Latitude   Longitude   Fix  Date       Time     Date Alt    Course Speed Card  Distance Course Card  Chars Sentences Checksum"));
  Serial.println(F("          (deg)      (deg)       Age                      Age  (m)    --- from GPS ----  ---- to London  ----  RX    RX        Fail"));
  Serial.println(F("---------------------------------------------------------------------------------------------------------------------------------------"));
}

void loop()
{
  static const double LONDON_LAT = 51.508131, LONDON_LON = -0.128002;
  printInt(gps.satellites.value(), gps.satellites.isValid(), 5);
  printInt(gps.hdop.value(), gps.hdop.isValid(), 5);
  printFloat(gps.location.lat(), gps.location.isValid(), 11, 6);
  printFloat(gps.location.lng(), gps.location.isValid(), 12, 6);
  printInt(gps.location.age(), gps.location.isValid(), 5);
  printDateTime(gps.date, gps.time);
  printFloat(gps.altitude.meters(), gps.altitude.isValid(), 7, 2);
  printFloat(gps.course.deg(), gps.course.isValid(), 7, 2);
  printFloat(gps.speed.kmph(), gps.speed.isValid(), 6, 2);
  printStr(gps.course.isValid() ? TinyGPSPlus::cardinal(gps.course.value()) : "*** ", 6);

  unsigned long distanceKmToLondon =
    (unsigned long)TinyGPSPlus::distanceBetween(
      gps.location.lat(),
      gps.location.lng(),
      LONDON_LAT, 
      LONDON_LON) / 1000;
  printInt(distanceKmToLondon, gps.location.isValid(), 9);

  double courseToLondon =
    TinyGPSPlus::courseTo(
      gps.location.lat(),
      gps.location.lng(),
      LONDON_LAT, 
      LONDON_LON);

  printFloat(courseToLondon, gps.location.isValid(), 7, 2);

  const char *cardinalToLondon = TinyGPSPlus::cardinal(courseToLondon);

  printStr(gps.location.isValid() ? cardinalToLondon : "*** ", 6);

  printInt(gps.charsProcessed(), true, 6);
  printInt(gps.sentencesWithFix(), true, 10);
  printInt(gps.failedChecksum(), true, 9);
  Serial.println();
  
  smartDelay(1000);

  if (millis() > 5000 && gps.charsProcessed() < 10)
    Serial.println(F("No GPS data received: check wiring"));
}

// This custom version of delay() ensures that the gps object
// is being "fed".
static void smartDelay(unsigned long ms)
{
  unsigned long start = millis();
  do 
  {
    while (ss.available())
      gps.encode(ss.read());
  } while (millis() - start < ms);
}

static void printFloat(float val, bool valid, int len, int prec)
{
  if (!valid)
  {
    while (len-- > 1)
      Serial.print('*');
    Serial.print(' ');
  }
  else
  {
    Serial.print(val, prec);
    int vi = abs((int)val);
    int flen = prec + (val < 0.0 ? 2 : 1); // . and -
    flen += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1;
    for (int i=flen; i<len; ++i)
      Serial.print(' ');
  }
  smartDelay(0);
}

static void printInt(unsigned long val, bool valid, int len)
{
  char sz[32] = "*****************";
  if (valid)
    sprintf(sz, "%ld", val);
  sz[len] = 0;
  for (int i=strlen(sz); i<len; ++i)
    sz[i] = ' ';
  if (len > 0) 
    sz[len-1] = ' ';
  Serial.print(sz);
  smartDelay(0);
}

static void printDateTime(TinyGPSDate &d, TinyGPSTime &t)
{
  if (!d.isValid())
  {
    Serial.print(F("********** "));
  }
  else
  {
    char sz[32];
    sprintf(sz, "%02d/%02d/%02d ", d.month(), d.day(), d.year());
    Serial.print(sz);
  }
  
  if (!t.isValid())
  {
    Serial.print(F("******** "));
  }
  else
  {
    char sz[32];
    sprintf(sz, "%02d:%02d:%02d ", t.hour(), t.minute(), t.second());
    Serial.print(sz);
  }

  printInt(d.age(), d.isValid(), 5);
  smartDelay(0);
}

static void printStr(const char *str, int len)
{
  int slen = strlen(str);
  for (int i=0; i<len; ++i)
    Serial.print(i<slen ? str[i] : ' ');
  smartDelay(0);
}

but keep getting;

No GPS data received: check wiring
**** **** ********** *********** **** ********** ******** **** ****** ****** ***** ***   ******** ****** ***   0     0         0

According to my research i need to use RX0&TX0 on arduino mega, so i found this code;

//Connect with pin 18 and 19
#include <TinyGPS.h>
//long   lat,lon; // create variable for latitude and longitude object
float lat,lon;
TinyGPS gps; // create gps object

void setup(){
Serial.begin(57600); // connect serial
Serial.println("The GPS Received Signal:");
Serial1.begin(9600); // connect gps sensor

}
 
void loop(){
    while(Serial1.available()){ // check for gps data
    if(gps.encode(Serial1.read()))// encode gps data
    { 
    gps.f_get_position(&lat,&lon); // get latitude and longitude

    Serial.print("Position: ");
    
    //Latitude
    Serial.print("Latitude: ");
    Serial.print(lat,6);
    
    Serial.print(",");
    
    //Longitude
    Serial.print("Longitude: ");
    Serial.println(lon,6); 
    
   }
  }
}

with this code it works, but i was wondering is it possible to convert official example to work through RX0& TX0 ?

SoftwareSerial will not work on all Mega pins - see SoftwareSerial limitations
any reason not to use the hardware serial on the mega?

horace:
SoftwareSerial will not work on all Mega pins - see SoftwareSerial limitations
any reason not to use the hardware serial on the mega?

i can use with second code through hardware serial, but this example has good options like speed, distance between two locations etc. so that's why i wondered is it possible to convert official example to hardware serial.

try converting to SoftwareSerial to hardware Serial1 (Mega pins 18 and 19) so

//SoftwareSerial ss(RXPin, TXPin);   // COMMENT OUT THIS LINE
#define ss Serial1

// ADD THIS LINE

horace:
try converting to SoftwareSerial to hardware Serial1 (Mega pins 18 and 19) so

//SoftwareSerial ss(RXPin, TXPin);   // COMMENT OUT THIS LINE

#define ss Serial1


// ADD THIS LINE

ok did that, now output is like;

FullExample.ino
An extensive example of many interesting TinyGPS++ features
Testing TinyGPS++ library v. 0.92
by Mikal Hart

Sats HDOP Latitude   Longitude   Fix  Date       Time     Date Alt    Course Speed Card  Distance Course Card  Chars Sentences Checksum
          (deg)      (deg)       Age                      Age  (m)    --- from GPS ----  ---- to London  ----  RX    RX        Fail
---------------------------------------------------------------------------------------------------------------------------------------
**** **** ********** *********** **** ********** ******** **** ****** ****** ***** ***   ******** ****** ***   0     0         0        
**** **** ********** *********** **** ********** ******** **** ****** ****** ***** ***   ******** ****** ***   237   0         3        
**** **** ********** *********** **** ********** ******** **** ****** ****** ***** ***   ******** ****** ***   474   0         6        
**** **** ********** *********** **** ********** ******** **** ****** ****** ***** ***   ******** ****** ***   709   0         9        
**** **** ********** *********** **** ********** ******** **** ****** ****** ***** ***   ******** ****** ***   946   0         12

sheshman:
ok did that, now output is like;

Is the GPS outdoors with a good view of the sky, it needs to be ?

srnet:
Is the GPS outdoors with a good view of the sky, it needs to be ?

yes it is and blue led is blinking,also i'm able to receive coordinates with this code;

//Connect with pin 18 and 19
#include <TinyGPS.h>
//long   lat,lon; // create variable for latitude and longitude object
float lat,lon;
TinyGPS gps; // create gps object

void setup(){
Serial.begin(57600); // connect serial
Serial.println("The GPS Received Signal:");
Serial1.begin(9600); // connect gps sensor

}
 
void loop(){
    while(Serial1.available()){ // check for gps data
    if(gps.encode(Serial1.read()))// encode gps data
    {
    gps.f_get_position(&lat,&lon); // get latitude and longitude

    Serial.print("Position: ");
   
    //Latitude
    Serial.print("Latitude: ");
    Serial.print(lat,6);
   
    Serial.print(",");
   
    //Longitude
    Serial.print("Longitude: ");
    Serial.println(lon,6);
   
   }
  }
}

should

GPSBaud = 4800;

be

GPSBaud = 9600;

horace:
should

GPSBaud = 4800;

be

GPSBaud = 9600;

Thank you, you saved me from re-writing all the codes of the project,i owe you one.

FullExample.ino
An extensive example of many interesting TinyGPS++ features
Testing TinyGPS++ library v. 0.92
by Mikal Hart

Sats HDOP Latitude   Longitude   Fix  Date       Time     Date Alt    Course Speed Card  Distance Course Card  Chars Sentences Checksum
          (deg)      (deg)       Age                      Age  (m)    --- from GPS ----  ---- to London  ----  RX    RX        Fail
---------------------------------------------------------------------------------------------------------------------------------------
**** **** ********** *********** **** ********** ******** **** ****** ****** ***** ***   ******** ****** ***   47    0         0        
5    391  41.060325  28.682949   42   10/04/2020 12:03:07 43   64.60  0.00   2.72  N     2478     307.71 NW    543   2         0