neo-6m gps not working properly.

Hello guys,

im facing some issues with the gps. The first time i plugged it in it worked perfectly and now it doesnt anymore. I have switched arduino’s, cable’s etc yet nothing solved the problem.

The setup now a is arduino uno with a GY-GPS6MV2 from alieexpress:
https://www.aliexpress.com/item/1550843440.html?spm=a2g0s.9042311.0.0.27424c4dQ1ZB7W

The codes and setups i tried are as followed:
the neo 6m tx to the arduinos tx pin, the neo has its own powerbank for power. I am using the following code:

 /*
 * This is the Arduino code Ublox NEO-6M GPS module
 * this code extracts the GPS latitude and longitude so it can be used for other purposes

 * 
 * Written by Ahmad Nejrabi for Robojax Video
 * Date: Jan. 24, 2017, in Ajax, Ontario, Canada
 * Permission granted to share this code given that this
 * note is kept with the code.
 * Disclaimer: this code is "AS IS" and for educational purpose only.
 * 
 */

// written for RoboJax.com 
String inputString = ""; // a string to hold incoming data
boolean stringComplete = false; // whether the string is complete
String signal = "$GPGLL";
void setup() {
    // initialize serial:
    Serial.begin(9600);
    // reserve 200 bytes for the inputString:
    inputString.reserve(200);
}

void loop() {
    // print the string when a newline arrives:
    if (stringComplete) {
        String BB = inputString.substring(0, 6);
        if (BB == signal) {
            String LAT = inputString.substring(7, 17);
            int LATperiod = LAT.indexOf('.');
            int LATzero = LAT.indexOf('0');
            if (LATzero == 0) {
                LAT = LAT.substring(1);
            }

            String LON = inputString.substring(20, 31);
            int LONperiod = LON.indexOf('.');
            int LONTzero = LON.indexOf('0');
            if (LONTzero == 0) {
                LON = LON.substring(1);
            }

            Serial.println(LAT);
            Serial.println(LON);

        }

        // Serial.println(inputString);
        // clear the string:
        inputString = "";
        stringComplete = false;
    }
}

/*
SerialEvent occurs whenever a new data comes in the
hardware serial RX. This routine is run between each
time loop() runs, so using delay inside loop can delay
response. Multiple bytes of data may be available.
*/
void serialEvent() {
    while (Serial.available()) {
        // get the new byte:
        char inChar = (char) Serial.read();
        // add it to the inputString:
        inputString += inChar;
        // if the incoming character is a newline, set a flag
        // so the main loop can do something about it:
        if (inChar == '\n') {
            stringComplete = true;
        }
    }
}

the output gives me these results (if working randomly) with many strange characters. But stops after a few seconds.

12:37:43.628 -> bn6⸮⸮⸮⒊b⸮⸮b⸮⸮I⸮⸮,1,13,01,3⸮⸮⸮S⸮7,03⸮⸮⸮⸮⸮⸮g11[⸮žKI⸮⸮⸮4⸮⸮H⸮:A1⸮ML&r⸮⸮ʂ⸮br⸮00608.39963,E,1037⸮⸮L⸮A*6B
⸮⸮,A*79
12:37:44.486 -> $GPVTG,,T,,M,0.365,N,0.677,K,A*2⸮>C⸮⸮⸮⸮b⸮⸮⸮⸮rL⸮KLb⸮⸮⸮$GPRMC,104010.00,A⸮?72⸮i⸮⸮⸮⸮b⸮⸮608.40107,E,0⸮⸮⸮
⸮⸮⸮<⸮⸮b⸮⸮⸮⸮08.40117,E,0.039⸮Q⸮⸮⸮⸮⸮⸮⸮/⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮1,2⸮I⸮b⸮⸮⸮b⸮⸮R⸮⸮j
12:40:07.898 -> $GPGLL,51⸮⸮R⸮%⸮
⸮104012.00,A,5120.33678,N,00608.40121,E,0.114,,230820,,,A*7E
12:40:08.489 -> $GPVTG,,T,,M,0.114,N,0.211,K,A*25
12:40:08.524 -> $GPGGA,104012.00,5120.33678,N,00608.40121,E,1,06,2.3?,26.8,M,46.3,M⸮GPGSV,4,1⸮⸮b01,35⸮⸮b⸮⸮b⸮⸮b⸮⸮⸮bb⸮⸮b⸮⸮b⸮⸮,29,10,⸮⸮MNi⸮R⸮⸮⸮⸮b⸮b⸮⸮b⸮⸮b⸮⸮⸮⸮⸮⸮&⸮⸮b⸮Šb⸮⸮R⸮⸮j
12:40:08.802 -> $GPGSV,4,3,1&I⸮b⸮⸮⸮⸮)⸮⸮b⸮⸮b⸮⸮b⸮⸮b⸮⸮⸮⸮32,⸮6,?1>⸮⸮⸮⸮r⸮⸮⸮⸮⸮br⸮p0608⸮⸮012~p
12:40:09.425 -> ⸮⸮⸮⸮4013.00,A,5120.33⸮⸮K⸮ ⸮⸮⸮⸮r⸮⸮⸮⸮⸮b*⸮0.028,,230820,,,A*70
12:40:09.494 -> $GPVTG,,T,,⸮⸮⸮r⸮0.051,K,A*2D

Post continues as it is exceeding the max amount of characters.

Part 2

The second setup is Tx to Pin 4 and Rx to pin 3, again a powerbank for the gps.
Using the following code:

#include <SoftwareSerial.h>

#include <TinyGPS.h>

/* This sample code demonstrates the normal use of a TinyGPS 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).
*/

TinyGPS gps;
SoftwareSerial ss(4, 3);

static void smartdelay(unsigned long ms);
static void print_float(float val, float invalid, int len, int prec);
static void print_int(unsigned long val, unsigned long invalid, int len);
static void print_date(TinyGPS &gps);
static void print_str(const char *str, int len);

void setup()
{
  Serial.begin(9600);
  
  Serial.print("Testing TinyGPS library v. "); Serial.println(TinyGPS::library_version());
  Serial.println("by Mikal Hart");
  Serial.println();
  Serial.println("Sats HDOP Latitude  Longitude  Fix  Date       Time     Date Alt    Course Speed Card  Distance Course Card  Chars Sentences Checksum");
  Serial.println("          (deg)     (deg)      Age                      Age  (m)    --- from GPS ----  ---- to London  ----  RX    RX        Fail");
  Serial.println("-------------------------------------------------------------------------------------------------------------------------------------");

  ss.begin(9600);
}

void loop()
{
  float flat, flon;
  unsigned long age, date, time, chars = 0;
  unsigned short sentences = 0, failed = 0;
  static const double LONDON_LAT = 51.508131, LONDON_LON = -0.128002;
  
  print_int(gps.satellites(), TinyGPS::GPS_INVALID_SATELLITES, 5);
  print_int(gps.hdop(), TinyGPS::GPS_INVALID_HDOP, 5);
  gps.f_get_position(&flat, &flon, &age);
  print_float(flat, TinyGPS::GPS_INVALID_F_ANGLE, 10, 6);
  print_float(flon, TinyGPS::GPS_INVALID_F_ANGLE, 11, 6);
  print_int(age, TinyGPS::GPS_INVALID_AGE, 5);
  print_date(gps);
  print_float(gps.f_altitude(), TinyGPS::GPS_INVALID_F_ALTITUDE, 7, 2);
  print_float(gps.f_course(), TinyGPS::GPS_INVALID_F_ANGLE, 7, 2);
  print_float(gps.f_speed_kmph(), TinyGPS::GPS_INVALID_F_SPEED, 6, 2);
  print_str(gps.f_course() == TinyGPS::GPS_INVALID_F_ANGLE ? "*** " : TinyGPS::cardinal(gps.f_course()), 6);
  print_int(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0xFFFFFFFF : (unsigned long)TinyGPS::distance_between(flat, flon, LONDON_LAT, LONDON_LON) / 1000, 0xFFFFFFFF, 9);
  print_float(flat == TinyGPS::GPS_INVALID_F_ANGLE ? TinyGPS::GPS_INVALID_F_ANGLE : TinyGPS::course_to(flat, flon, LONDON_LAT, LONDON_LON), TinyGPS::GPS_INVALID_F_ANGLE, 7, 2);
  print_str(flat == TinyGPS::GPS_INVALID_F_ANGLE ? "*** " : TinyGPS::cardinal(TinyGPS::course_to(flat, flon, LONDON_LAT, LONDON_LON)), 6);

  gps.stats(&chars, &sentences, &failed);
  print_int(chars, 0xFFFFFFFF, 6);
  print_int(sentences, 0xFFFFFFFF, 10);
  print_int(failed, 0xFFFFFFFF, 9);
  Serial.println();
  
  smartdelay(1000);
}

static void smartdelay(unsigned long ms)
{
  unsigned long start = millis();
  do 
  {
    while (ss.available())
      gps.encode(ss.read());
  } while (millis() - start < ms);
}

static void print_float(float val, float invalid, int len, int prec)
{
  if (val == invalid)
  {
    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 print_int(unsigned long val, unsigned long invalid, int len)
{
  char sz[32];
  if (val == invalid)
    strcpy(sz, "*******");
  else
    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 print_date(TinyGPS &gps)
{
  int year;
  byte month, day, hour, minute, second, hundredths;
  unsigned long age;
  gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &age);
  if (age == TinyGPS::GPS_INVALID_AGE)
    Serial.print("********** ******** ");
  else
  {
    char sz[32];
    sprintf(sz, "%02d/%02d/%02d %02d:%02d:%02d ",
        month, day, year, hour, minute, second);
    Serial.print(sz);
  }
  print_int(age, TinyGPS::GPS_INVALID_AGE, 5);
  smartdelay(0);
}

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

The results are sometimes :

10:13:01.020 -> Sats HDOP Latitude  Longitude  Fix  Date       Time     Date Alt    Course Speed Card  Distance Course Card  Chars Sentences Checksum
10:13:01.159 ->           (deg)     (deg)      Age                      Age  (m)    --- from GPS ----  ---- to London  ----  RX    RX        Fail
10:13:01.298 -> -------------------------------------------------------------------------------------------------------------------------------------
10:13:01.438 -> **** **** ********* ********** **** ********** ******** **** ****** ****** ***** ***   *******  ****** ***   0     0         0        
10:13:02.516 -> **** **** ********* ********** **** ********** ******** **** ****** ****** ***** ***   *******  ****** ***   63    0         0        
10:13:03.594 -> **** **** ********* ********** **** ********** ******** **** ****** ****** ***** ***   *******  ****** ***   243   0         0        
10:13:04.673 -> **** **** ********* ********** **** ********** ******** **** ****** ****** ***** ***   *******  ****** ***   617   0         0

In both cases, if i restart the arduino or if i unplug it it will give me 0 output in the first code and just a lot of 0’s in the seoncd code

10:13:01.438 -> **** **** ********* ********** **** ********** ******** **** ****** ****** ***** ***   *******  ****** ***   0     0         0

When i turn of my pc completely and try again next day it works again, but only untill i unplug or restart the arduino its no data again.

Any input would be much appreciated.

It's better to debug GPS problems, by looking directly at the NMEA sentences. Just looking at TinyGPS output hides information that might help you.

The first step is to verify GPS communications with a simple echo program, like the one below. If you see nonsense characters, you may have the wrong Baud rate or a power problem.

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); //(RX, TX) check correct pin assignments.

void setup() {
  mySerial.begin(9600);
  Serial.begin(9600);
  Serial.println("GPS start");
}

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

jremington:
The first step is to verify GPS communications with a simple echo program, like the one below. If you see nonsense characters, you may have the wrong Baud rate or a power problem.

Thank you for the reply, i ran the code and it worked, so it has to be something more then this.

21:39:44.788 -> GPS start

ryukenden:
Thank you for the reply, i ran the code and it worked:

21:39:44.788 -> GPS start

Are you sure? I don't see any GPS data coming from the receiver.

it only prints that line: Gps start, nothing else

Then no data are coming from the GPS. Check your wiring.

The "echo" program as posted expects the GPS TX to be connected to Arduino pin 10. Of course, power and ground need also be connected.

The wiring is as followed

Gps Tx -- Arduino pin 10
Gps Rx -- Arduino pin 11

i tried reverse order too, but no data
yes gnd and vcc are also connected.

i tried to run the nmea test again to see for any response and it gave me 2 lines only:

22:06:36.921 -> ⸮⸮⸮⸮⸮,⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮0b⸮⸮r⸮⸮bbbbbbR⸮⸮j
22:06:36.990 -> $GPGSA,A,1,, ⸮⸮⸮⸮⸮⸮⸮)⸮r⸮⸮9r⸮⸮

You probably have a bad connection. Check continuity of connections, while wiggling the wires (power disconnected).

Post a clear, close up, focused photo showing your solder connections.

The wires have not been soldered on yet, i am using the breadboard.
I will solder the wires directly then tomorrow, maybe that will help indeed.

So far thank you for your help :slight_smile:

The module worked perfectly after i soldered on the wires.
So i guess it was indeed a bad connection.

Thank you for your help, much appreciated!