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());
}
}
Which pins are you using? The first code shows 2&3, but the second shows 3&4. And remember, the GPS TX pin goes to the Arduino RX pin. Likewise, the GPS RX pin goes to the Arduino TX pin. For the first code, the GPS TX pin should be connected to Arduino pin 2.
Are you inside? You probably have to be outside, or at least near some windows for the GPS device to receive from the satellites. It could take 15 minutes for the first fix to happen.
Although you don't show any output, you should try a simple echo program first, to see if the GPS device is sending anything.
#include <NeoSWSerial.h>
NeoSWSerial gpsSerial( 2, 3 );
void setup()
{
Serial.begin( 9600 );
gpsSerial.begin( 9600 );
}
void loop()
{
if (gpsSerial.available())
Serial.write( gpsSerial.read() );
}
I would also recommend getting the NeoSWSerial library. It's my library, and it's much more efficient and reliable than SoftwareSerial
.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다