Arduino——野火GPS模块

GPS模块


前言

手上还有一个GPS,用arduino做模块很方便,打算和短信模块结合,短信模块上次已经使用完成了,这次学习一下GPS模块
在这里插入图片描述
看模块很容易知道,这个模块用的是串口通信,只需要注意设置相应的波特率即可,GPS模块的波特率是115200。使用的时候一定要注意,在室内是无法获取经纬度的,一定要去室外测试。下面看一下这个模块如何使用。

一、Arduino代码

你随便写一个串口然后打印内容,就能看到GPS输出的一大片内容,但是我们使用的时候往往只需要经纬度,在arduino中提供了一个TinyGPS++解析库,可以解析出经纬度。库不会安装的可以看之前的博客,这里直接给出代码。

/*
  richowe
*/
#include <TinyGPS++.h>
#include <SoftwareSerial.h>

TinyGPSPlus gps;
SoftwareSerial ss(6, 7);

float latitude;
float longitude;
int incomedate=0;
void setup()
{
    
    
  Serial.begin(9600); //set the baud rate of serial port to 9600;
  ss.begin(115200); //set the GPS baud rate to 9600;
}

void loop()
{
    
    
  while (ss.available() > 0)
  {
    
    
    gps.encode(ss.read()); //The encode() method encodes the string in the encoding format specified by encoding.

    if (gps.location.isUpdated())
    {
    
    
      latitude = gps.location.lat(); //gps.location.lat() can export latitude
      longitude = gps.location.lng();//gps.location.lng() can export latitude
      Serial.print("Latitude=");
      Serial.print(latitude, 6);  //Stable after the fifth position
      Serial.print(" Longitude=");
      Serial.println(longitude, 6);
      delay(500);
      }
  }
}

可以通过串口打印相关的信息。
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_51963216/article/details/128559410