Getting GPS location from A9G board.

Thread Starter

eonshopact

Joined Sep 2, 2023
19
I am trying to get the current location from A9G board connected to Arduino. I am not getting the longitude and latitude. The code i tried. (I was not able to paste the code. So, i have pasted it as image).

gps.jpg
 
Last edited:

Ya’akov

Joined Jan 27, 2019
9,234
I am trying to get the current location from A9G board connected to Arduino. I am not getting the longitude and latitude. The code i tried. (I was not able to paste the code. So, i have pasted it as image).

View attachment 316941
Welcome to AAC.

First, do you have the baud rate of the serial port set to 9600 to be able to decode the NMEA data? According to the documentation the NMEA messages will be at 9600 no matter what the interface to the module itself is.

Second, why are you looking for GPSRD:? The NMEA message itself looks like:

$GNGGA,000840.261,2236.3719,N,11350.4081,E,0,0,,153.2,M,-3.2,M,,*4F

and the $GNGGA at the front is unique and on the same line, guaranteed. But even more problematic is that Serial.read() returns only one byte! You need to use Serial.readString() or possibly Serial.readStringUntil() using * as the terminator. It appears this will work given the message.

So first confirm you are, in fact, getting readable NMEA messages (baud rate). Then use one of the other functions to get the string, then parse it more compactly—and don’t forget to use Serial.flush() to clear the buffer for the next message.
 

Thread Starter

eonshopact

Joined Sep 2, 2023
19
I am using Ai Thinker A9G board. It came with GPS module and it does not have any brand name on it. Can you please suggest a good library to get the gps data and make into google map link?
 

Ya’akov

Joined Jan 27, 2019
9,234
The Adafruit GPS library is very good. But, before you start with that make sure you are getting usable NMEA sentences because the module can’t do anything to help you if you are not.

Remember, the documentation says that the GPS data is 9600 baud no matter what the other interface uses. I can’t confirm that since I don’t have the board and haven‘t used one. But no matter what, please do this step first to make sure you aren’t chasing ghosts.
 

Thread Starter

eonshopact

Joined Sep 2, 2023
19
Tried with simple code,
Code:
#include <SoftwareSerial.h>
// Define software serial communication pins
const int gpsRxPin = 7;
const int gpsTxPin = 8;
// Create software serial object
SoftwareSerial gpsSerial(gpsRxPin, gpsTxPin);
void setup() {
  // Initialize serial communication for debugging (optional)
  Serial.begin(9600);
  // Begin communication with GPS module at 9600 baud
  gpsSerial.begin(9600);
  delay(1000);
}
void loop() {
  // Check for available data from GPS module
  gpsSerial.println("AT");
  delay(1000);
   
  if (gpsSerial.available()) {
    String response = gpsSerial.readStringUntil('\n');
    Serial.println("Response: " + response);
    if (response.indexOf("OK") != -1) {
      Serial.println("AT command successful!");
    } else {
      Serial.println("AT command failed!");
    }
  } else {
    Serial.println("No response from GPS module!");
  } 
  delay(1000);
}
I am getting response as: "No response from GPS module!"

When i tried to connect the module using USB to TTL converter, I am getting OK as response.
 

Ya’akov

Joined Jan 27, 2019
9,234
You need to start up the GPS output with AT+GPSRD=1 and see you if you can read NMEA sentences, like:

$GNGGA,000840.261,2236.3719,N,11350.4081,E,0,0,,153.2,M,-3.2,M,,*4F
The command‘s argument (1) is specifying that you want a message each second. You won’t see the fix as there is in this example unless it has been running for long enough, and has a view of enough birds to get one. But, you will see messages.

Your attempts to parse the messages have issues so don’t try—just use the serial monitor in the Arduino IDE.
 
Top