首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Arduino-GPS没有给出经度和纬度值。

Arduino-GPS没有给出经度和纬度值。
EN

Stack Overflow用户
提问于 2015-12-05 05:15:33
回答 1查看 3.7K关注 0票数 2

我正在试图跟踪GPS,但我无法接收到我的经度和纬度数据。我正在使用"Adafruit终极GPS突破V3“GPS模块和"Arduino UNO R3”。

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

*第一部法典::

代码语言:javascript
复制
#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);
    }
  }
}

*第二部法典::

代码语言:javascript
复制
#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());
  }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-12-05 15:51:32

你用的是哪个引脚?第一个代码显示2和3,第二个代码显示3和4。请记住,GPS引脚会转到Arduino RX引脚。同样,全球定位系统RX引脚到Arduino TX引脚。对于第一个代码,GPS TX引脚应该连接到Arduino pin 2。

你在里面吗?你可能必须在外面,或者至少在一些窗户附近,全球定位系统设备才能从卫星接收到。第一次修复可能需要15分钟。

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

代码语言:javascript
复制
#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高效可靠得多。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34101562

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档