Hi! Can you please help me with my code? I am trying to track the GPS but i am not able to receive my longitude and latitude data.
I am using "Adafruit Ultimate GPS Breakout V3" GPS module and "Arduino UNO R3"
Here is my code. I have tried both
:::First Code:::
#include <SoftwareSerial.h>
#include <TinyGPS.h>
long flat, flon;
SoftwareSerial gpsSerial(2, 3); // Create GPS pin connection
TinyGPS gps;
void setup(){
Serial.begin(9600); // connection serial
gpsSerial.begin(9600); // gps burd rate
}
void loop(){
while(gpsSerial.available()){ // check for gps data
if(gps.encode(gpsSerial.read())){ // encode gps data
gps.get_position(&flat, &flon); // get lattitude and longitude
// display position
Serial.print("Position: ");
Serial.print("lat: ");Serial.println(flat);
Serial.print("lon: ");Serial.println(flon);
}
}
}
:::Second Code:::
#include <SoftwareSerial.h>
#include <TinyGPS++.h>
#define RXPin 3
#define TXPin 4
#define GPSBaud 9600
#define ConsoleBaud 115200
// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);
// The TinyGPS++ object
TinyGPSPlus gps;
void setup()
{
Serial.begin(ConsoleBaud);
ss.begin(GPSBaud);
Serial.println("GPS Example 2");
Serial.println("A simple tracker using TinyGPS++.");
Serial.println();
}
void loop()
{
// If any characters have arrived from the GPS,
// send them to the TinyGPS++ object
while (ss.available() > 0)
gps.encode(ss.read());
// Let's display the new location and altitude
// whenever either of them have been updated.
if (gps.location.isUpdated() || gps.altitude.isUpdated())
{
Serial.print("Location: ");
Serial.print(gps.location.lat(), 6);
Serial.print(",");
Serial.print(gps.location.lng(), 6);
Serial.print(" Altitude: ");
Serial.println(gps.altitude.meters());
}
}
Read the "How to use this forum" and pay attention to the section on code tags.
Do you know if there is any output from the GPS? Do you know the baud rate? I mean, have you actually tested it instead of just reading the specification?
I thought I replied to this but I must have hit the wrong button. Here goes again.
First, be sure you can see the data on a computer. Be sure you know the baud rate of the device, hook it up to the USB port of a computer, run a program such as PuTTY and be sure you can see the NMEA data on the computer. You will see $GPGSV, $GPGGA and other statements flying by.
Then be sure the baud rate is right on the GPS and hook it up. You should be able to get Lat/Long and much other data after it has a chance to accumulate it. Should only take a few seconds if the GPS has been on and has a lock.
But take care: With AltSoftSerial you cannot use any pin you want, but the RX/TX pins for AltSoftSerial depend on the Arduino board type you are using.
UKHeliBob:
I don't recall seeing this restriction mentioned before and I have used SS @ 9600 baud and HS at 9600 baud before with no apparent problems.
UKHeliBob:
I don't recall seeing this restriction mentioned before and I have used SS @ 9600 baud and HS at 9600 baud before with no apparent problems.
How good or how bad "SoftwareSerial" works depends on the version of the Arduino-IDE you are using.
Especially between version numbers 1.5.5 and 1.6.5 there had been several Arduino IDE realeases with SoftwareSerial hardly working at all.
And of course, it depends on timing within the actual sketch how good or bad software and hardware serial work together.