I am new in GPS modules and I need to get the NMEA data from my GPS module but when I execute my code all the NMEA sentences are Invalid.
I am using the same example from instructables Tiny GPS Tracker https://www.instructables.com/Tiny-GPS-Tracker/ and it does not work. So I found other code examples and changed them a little bit.
My code is below. I have the GPS_RX wired with Arduino TX and the same logic for GPS_TX-Arduino RX and Baud is 9600, all these details are inside GPS.h.
If I change the wiring between TX and RX or gps baud the system does not work at all, so I strongly believe that these values are correct.
#include "GPS.h"
#include <SD.h>
#if defined (ARDUINO_ARCH_AVR)
#define SerialMonitorInterface Serial
#include <SoftwareSerial.h>
#elif defined(ARDUINO_ARCH_SAMD)
#define SerialMonitorInterface SerialUSB
#include "SoftwareSerialZero.h"
#endif
const int chipSelect = 10;
int cardPresent;
// The GPS connection is attached with a software serial port
SoftwareSerial softSerial(GPS_RXPin, GPS_TXPin);
#define Gps_serial softSerial
void setup()
{
Gps_serial.begin(GPSBaud);
SerialMonitorInterface.begin(115200);
while (!SerialMonitorInterface && millis() < 5000); //On TinyScreen+, this will wait until the Serial Monitor is opened or until 5 seconds has passed
gpsInitPins();
delay(100);
SerialMonitorInterface.print("Attempting to wake GPS module.. ");
gpsOn();
SerialMonitorInterface.println("done.");
delay(200);
//Enable and set interval or disable, per NMEA sentence type
Gps_serial.print(gpsConfig(NMEA_GGA_SENTENCE, 0));
Gps_serial.print(gpsConfig(NMEA_GLL_SENTENCE, 0));
Gps_serial.print(gpsConfig(NMEA_GSA_SENTENCE, 0));
Gps_serial.print(gpsConfig(NMEA_GSV_SENTENCE, 0));
Gps_serial.print(gpsConfig(NMEA_RMC_SENTENCE, 1));
Gps_serial.print(gpsConfig(NMEA_VTG_SENTENCE, 0));
Gps_serial.print(gpsConfig(NMEA_GNS_SENTENCE, 0));
SerialMonitorInterface.print("Initializing SD card...");
// see if the card is present and can be initialized:
if (SD.begin(chipSelect)) {
SerialMonitorInterface.println("card initialized.");
cardPresent = true;
} else {
SerialMonitorInterface.println("Card failed, or not present- continuing with serial output");
cardPresent = false;
}
}
void loop() {
handleGPS();
}
char waitForCharacter() {
while (!Gps_serial.available());
return Gps_serial.read();
}
void handleGPS() {
while (Gps_serial.read() != '$') {
if(!Gps_serial.available()){
return;
}
}
int counter = 1;
char c = 0;
char buffer[100];
buffer[0] = '$';
c = waitForCharacter();
while (c != '*') {
buffer[counter++] = c;
if(c=='$'){//new start
counter=1;
}
c = waitForCharacter();
}
buffer[counter++] = c;
buffer[counter++] = waitForCharacter();
buffer[counter++] = waitForCharacter();
buffer[counter++] = '\r';
buffer[counter++] = '\n';
buffer[counter] = '\0';
buffer[1] = 'G';
buffer[2] = 'P';
gpsDoChecksum(buffer);
if (cardPresent) {
File dataFile = SD.open("gps.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
dataFile.write(buffer, counter);
dataFile.close();
} else {
SerialMonitorInterface.println("error opening gps.txt");
cardPresent = false;
}
} else {
SerialMonitorInterface.print((char *)buffer);
}
}
After I wait aprox. 30 seconds which is the cold start of the gps I still receive invalid NMEA sentences. (I tested it outdoors and indoors)
$GPRMC,181341.901,V,,,,,,,211020,,,N4B $GPRMC,181342.901,V,,,,,,,211020,,,N48 $GPRMC,181343.901,V,,,,,,,211020,,,N49 $GPRMC,181344.901,V,,,,,,,211020,,,N4E $GPRMC,181345.901,V,,,,,,,211020,,,N*4F
Can someone explain to me what is going on?