【问题标题】:Arduino-GPS is not giving longitude and latitude valuesArduino-GPS 没有给出经度和纬度值
【发布时间】:2015-12-05 23:51:32
【问题描述】:

我正在尝试跟踪 GPS,但我无法接收我的经度和纬度数据。 我正在使用“Adafruit Ultimate GPS Breakout V3”GPS 模块和“Arduino UNO R3”

这是我的代码。我都试过了

:::第一个代码:::

#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);
    }
  }
}

:::第二代码:::

#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());
  }
}

【问题讨论】:

    标签: gps arduino


    【解决方案1】:

    您使用的是哪些引脚?第一个代码显示 2&3,但第二个代码显示 3&4。请记住,GPS TX 引脚连接到 Arduino RX 引脚。同样,GPS RX 引脚连接到 Arduino TX 引脚。对于第一个代码,GPS TX 引脚应连接到 Arduino 引脚 2。

    你在里面吗?您可能必须在室外,或者至少靠近一些窗户,以便 GPS 设备接收来自卫星的信息。第一次修复可能需要 15 分钟。

    虽然您没有显示任何输出,但您应该先尝试一个简单的回显程序,看看 GPS 设备是否正在发送任何东西

    #include <NeoSWSerial.h>
    NeoSWSerial gpsSerial( 2, 3 );
    
    void setup()
    {
      Serial.begin( 9600 );
      gpsSerial.begin( 9600 );
    }
    
    void loop()
    {
      if (gpsSerial.available())
        Serial.write( gpsSerial.read() );
    }
    

    我还建议获取NeoSWSerial 库。这是我的库,它比SoftwareSerial 更高效可靠。

    【讨论】:

      猜你喜欢
      • 2017-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-14
      • 1970-01-01
      相关资源
      最近更新 更多