I recently set up a GY-NEO6MV2 gps module with an Arduino Uno. I followed the basic scripts out there which used the gps.location.isUpdated() line as an "if" condition. However this never worked for some reason and nothing was printed to my serial. So I added a condition that printed out the raw NMEA sentences my gps spits out to see if my gps was even working. It is as the 3rd field in the $GPRMC line shows "A" which means the gps data is valid, and also I checked the $GPGSA field. However the gps.location.isUpdated() line still doesn't work. I don't know if something is wrong with my condition statements or something's up with my gps module. Also I checked that my TX and RX pins are connected properly to the arduino (TX to RX of arduino and vice versa) so the software serial connection isn't the problem.
#include <Arduino.h>
#include <TinyGPS++.h>
#include <TinyGPS.h>
#include <SoftwareSerial.h>
#define RXpin 11
#define TXpin 10
TinyGPSPlus gps;
SoftwareSerial ss(RXpin,TXpin);
String GPS_nmea;
void setup() {
Serial.begin(9600);
ss.begin(9600);
Serial.println("begin script");
}
void loop()
{
while (ss.available())
{
gps.encode(ss.read());
if (gps.location.isUpdated())
{
Serial.print("Latitude:");
Serial.println((gps.location.lat()));
Serial.print("Longitude:");
Serial.println((gps.location.lng()));
}
else
{
GPS_nmea = ss.readStringUntil(13);
if(GPS_nmea.startsWith("$GPRMC"))
{
Serial.println(GPS_nmea);
}
}
}
}