GPS模块 NEO-6M 7N程序
时间: 2023-08-06 07:08:33 浏览: 279
以下是基于Arduino平台的NEO-6M 7N GPS模块程序,你可以根据自己的需求进行修改:
```C++
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
static const int RXPin = 4, TXPin = 3;
static const uint32_t GPSBaud = 9600;
SoftwareSerial ss(RXPin, TXPin);
TinyGPSPlus gps;
void setup()
{
Serial.begin(115200);
ss.begin(GPSBaud);
Serial.println("NEO-6M GPS Module Example");
}
void loop()
{
while (ss.available() > 0)
if (gps.encode(ss.read()))
displayInfo();
if (millis() > 5000 && gps.charsProcessed() < 10)
{
Serial.println("No GPS data received: check wiring");
while (true);
}
}
void displayInfo()
{
Serial.print("Location: ");
if (gps.location.isValid())
{
Serial.print(gps.location.lat(), 6);
Serial.print(F(","));
Serial.print(gps.location.lng(), 6);
}
else
{
Serial.print(F("INVALID"));
}
Serial.print(" Date/Time: ");
if (gps.date.isValid())
{
Serial.print(gps.date.month());
Serial.print("/");
Serial.print(gps.date.day());
Serial.print("/");
Serial.print(gps.date.year());
}
else
{
Serial.print(F("INVALID"));
}
Serial.print(" ");
if (gps.time.isValid())
{
if (gps.time.hour() < 10) Serial.print(F("0"));
Serial.print(gps.time.hour());
Serial.print(":");
if (gps.time.minute() < 10) Serial.print(F("0"));
Serial.print(gps.time.minute());
Serial.print(":");
if (gps.time.second() < 10) Serial.print(F("0"));
Serial.print(gps.time.second());
Serial.print(".");
if (gps.time.centisecond() < 10) Serial.print(F("0"));
Serial.print(gps.time.centisecond());
}
else
{
Serial.print(F("INVALID"));
}
Serial.println();
}
```
这个程序使用了TinyGPS++库来解析GPS数据,同时使用了SoftwareSerial库来与GPS模块进行通信。你需要将RXPin和TXPin分别连接到GPS模块的TXD和RXD引脚,然后将GPS模块的VCC和GND引脚连接到Arduino的5V和GND引脚。
阅读全文