GPS: Read GPGGA Only

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Skarate
 
Posts: 10
Joined: Fri Jan 06, 2023 10:02 am

GPS: Read GPGGA Only

Post by Skarate »

I am trying to read only GPGGA data from the GPS on an Arduino Uno. I looked at this post first:
viewtopic.php?p=735631&hilit=gps+command#p735631

Unfortunately, it seems the link to the github example there no longer works. I wrote this small script that simply sends the command to the GPS:

Code: Select all

void setup() {
  delay(3000);
  const char* cmd = "PMTK314,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29";
  Serial.begin(9600);
  Serial.write(cmd);
  Serial.end();
}

void loop() {
}
The GPS itself is wired with it's Tx connected to the Uno's Tx, and the GPS' Rx to the Uno's Rx. In this configuration, the Uno automatically prints the NMEA sentences received from the GPS to the serial console. When it's run, the command gets printed to the serial console, but otherwise there are no changes to the GPS' output:
serial_output.png
serial_output.png (205.35 KiB) Viewed 102 times
I've tried:
-adding and removing "\r\n" at the end of the command string
-different checksums: the forum post linked says 29, I calculated 41. No observed change using either, though
-swapping Tx and Rx on the Uno side
-using Serial.write and Serial.print

Not sure what else to try- any suggestions are welcome. Thank you!

User avatar
Franklin97355
 
Posts: 23912
Joined: Mon Apr 21, 2008 2:33 pm

Re: GPS: Read GPGGA Only

Post by Franklin97355 »

Have you looked at https://github.com/adafruit/Adafruit_GPS ?
Also, I calculated 29 so try that too.

User avatar
Skarate
 
Posts: 10
Joined: Fri Jan 06, 2023 10:02 am

Re: GPS: Read GPGGA Only

Post by Skarate »

Thanks for your suggestions. I downloaded the library and tried adapting some of the hardware serial examples. They seem to rely on both Serial and Serial1, and the Arduino Uno I have only has Serial. I tried sending the command via the sendCommand member function, however this didn't seem to change anything:

Code: Select all

#include <Adafruit_GPS.h>

Adafruit_GPS gps(&Serial);

void setup()
{
  gps.sendCommand(PMTK_SET_NMEA_OUTPUT_GGAONLY);
}

void loop()
{
  if(gps.newNMEAreceived())
  {
    Serial.begin(9600);
    Serial.print(gps.lastNMEA());
    Serial.end();
  }
}
adapted_code.png
adapted_code.png (101.7 KiB) Viewed 90 times
I then tried running the software serial echo example (https://tinyurl.com/2fej2546), slightly modifed to send GGAONLY. This simply resulted in '?' getting printed:
mystery.png
mystery.png (52.52 KiB) Viewed 90 times
Interestingly, *something* about the way it sends the command seems to work. I re-uploaded the first code, and the serial monitor showed the correct output:
correct.png
correct.png (134.23 KiB) Viewed 90 times
I don't know what caused the change though- my guess is using the digital pins to send it? If you have any insight into this I'd really appreciate it.

User avatar
Skarate
 
Posts: 10
Joined: Fri Jan 06, 2023 10:02 am

Re: GPS: Read GPGGA Only

Post by Skarate »

Update: it seems the Uno uses Tx for both transmission and reception. I figured this out by:

1) connecting the Uno's Tx pin to the GPS Rx pin
2) waiting a few seconds for the command to send
3) Switching it from the GPS Rx pin to the GPS Tx pin, keeping it connected to the Uno's Tx pin.

After doing that I am seeing the expected output.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”