网页资讯视频图片知道文库贴吧地图采购
进入贴吧全吧搜索

 
 
 
日一二三四五六
       
       
       
       
       
       

签到排名:今日本吧第个签到,

本吧因你更精彩,明天继续来努力!

本吧签到人数:0

一键签到
成为超级会员,使用一键签到
一键签到
本月漏签0次!
0
成为超级会员,赠送8张补签卡
如何使用?
点击日历上漏签日期,即可进行补签。
连续签到:天  累计签到:天
0
超级会员单次开通12个月以上,赠送连续签到卡3张
使用连续签到卡
08月31日漏签0天
arduino吧 关注:75,385贴子:230,317
  • 看贴

  • 图片

  • 吧主推荐

  • 视频

  • 游戏

  • 8回复贴,共1页
<<返回arduino吧
>0< 加载中...

【arduino】GPS模块

  • 只看楼主
  • 收藏

  • 回复
  • 面包zdk
  • 富有名气
    8
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
最近楼主在使gps模块,有大神来交流交流么?、
先上一波代码!
char nmeaSentence[68];
String latitude;//纬度
String longitude;//经度
String lndSpeed;//速度
String gpsTime;//UTC时间,本初子午线经度0度的时间,和北京时间差8小时
String beiJingTime;//北京时间
#define GPSSerial Serial
void setup()//初始化内容
{
GPSSerial.begin(9600);//定义波特率9600,和我们店铺的GPS模块输出的波特率一致
GPSSerial.println("GPS test");
GPSSerial.println("Wating...");
}
void loop()//主循环
{
// For one second we parse GPS data and report some key values
for (unsigned long start = millis(); millis() - start < 1000;)//一秒钟内不停扫描GPS信息
{
while (GPSSerial.available())//串口获取到数据开始解析
{
char c = GPSSerial.read();//读取一个字节获取的数据
switch(c)//判断该字节的值
{
case '$'://若是$,则说明是一帧数据的开始
GPSSerial.readBytesUntil('*', nmeaSentence, 67);//读取接下来的数据,存放在nmeaSentence字符数组中,最大存放67个字节
//Serial.println(nmeaSentence);
latitude = parseGprmcLat(nmeaSentence);//获取纬度值
longitude = parseGprmcLon(nmeaSentence);//获取经度值
lndSpeed = parseGprmcSpeed(nmeaSentence);//获取速度值
gpsTime = parseGprmcTime(nmeaSentence);//获取GPS时间
if(latitude > "")//当不是空时候打印输出
{
GPSSerial.println("------------------------------------");
GPSSerial.println("latitude: " + latitude);
}
if(longitude > "")//当不是空时候打印输出
{
GPSSerial.println("longitude: " + longitude);
}
if(lndSpeed > "")//当不是空时候打印输出
{
GPSSerial.println("Speed (knots): " + lndSpeed);
}
if(gpsTime > "")//当不是空时候打印输出
{
GPSSerial.println("gpsTime: " + gpsTime);
beiJingTime = getBeiJingTime(gpsTime);//获取北京时间
GPSSerial.println("beiJingTime: " + beiJingTime);
}
}
}
}
}
String getBeiJingTime(String s)
{
int hour = s.substring(0,2).toInt();
int minute = s.substring(2,4).toInt();
int second = s.substring(4,6).toInt();
hour += 8;
if(hour > 24)
hour -= 24;
s = String(hour) +":"+String(minute) +":"+ String(second);
return s;
}
//Parse GPRMC NMEA sentence data from String
//String must be GPRMC or no data will be parsed
//Return Latitude
String parseGprmcLat(String s)
{
int pLoc = 0; //paramater location pointer
int lEndLoc = 0; //lat parameter end location
int dEndLoc = 0; //direction parameter end location
String lat;
/*make sure that we are parsing the GPRMC string.
Found that setting s.substring(0,5) == "GPRMC" caused a FALSE.
There seemed to be a 0x0D and 0x00 character at the end. */
if(s.substring(0,4) == "GPRM")
{
//Serial.println(s);
for(int i = 0; i < 5; i++)
{
if(i < 3)
{
pLoc = s.indexOf(',', pLoc+1);
/*Serial.print("i < 3, pLoc: ");
Serial.print(pLoc);
Serial.print(", ");
Serial.println(i);*/
}
if(i == 3)
{
lEndLoc = s.indexOf(',', pLoc+1);
lat = s.substring(pLoc+1, lEndLoc);
/*Serial.print("i = 3, pLoc: ");
Serial.println(pLoc);
Serial.print("lEndLoc: ");
Serial.println(lEndLoc);*/
}
else
{
dEndLoc = s.indexOf(',', lEndLoc+1);
lat = lat + " " + s.substring(lEndLoc+1, dEndLoc);
/*Serial.print("i = 4, lEndLoc: ");
Serial.println(lEndLoc);
Serial.print("dEndLoc: ");
Serial.println(dEndLoc);*/
}
}
return lat;
}
//}
//}
}
//Parse GPRMC NMEA sentence data from String
//String must be GPRMC or no data will be parsed
//Return Longitude
String parseGprmcLon(String s)
{
int pLoc = 0; //paramater location pointer
int lEndLoc = 0; //lat parameter end location
int dEndLoc = 0; //direction parameter end location
String lon;
/*make sure that we are parsing the GPRMC string.
Found that setting s.substring(0,5) == "GPRMC" caused a FALSE.
There seemed to be a 0x0D and 0x00 character at the end. */
if(s.substring(0,4) == "GPRM")
{
//Serial.println(s);
for(int i = 0; i < 7; i++)
{
if(i < 5)
{
pLoc = s.indexOf(',', pLoc+1);
/*Serial.print("i < 3, pLoc: ");
Serial.print(pLoc);
Serial.print(", ");
Serial.println(i);*/
}
if(i == 5)
{
lEndLoc = s.indexOf(',', pLoc+1);
lon = s.substring(pLoc+1, lEndLoc);
/*Serial.print("i = 3, pLoc: ");
Serial.println(pLoc);
Serial.print("lEndLoc: ");
Serial.println(lEndLoc);*/
}
else
{
dEndLoc = s.indexOf(',', lEndLoc+1);
lon = lon + " " + s.substring(lEndLoc+1, dEndLoc);
/*Serial.print("i = 4, lEndLoc: ");
Serial.println(lEndLoc);
Serial.print("dEndLoc: ");
Serial.println(dEndLoc);*/
}
}
return lon;
}
}
//Parse GPRMC NMEA sentence data from String
//String must be GPRMC or no data will be parsed
//Return Longitude
String parseGprmcSpeed(String s)
{
int pLoc = 0; //paramater location pointer
int lEndLoc = 0; //lat parameter end location
int dEndLoc = 0; //direction parameter end location
String lndSpeed;
/*make sure that we are parsing the GPRMC string.
Found that setting s.substring(0,5) == "GPRMC" caused a FALSE.
There seemed to be a 0x0D and 0x00 character at the end. */
if(s.substring(0,4) == "GPRM")
{
//Serial.println(s);
for(int i = 0; i < 8; i++)
{
if(i < 7)
{
pLoc = s.indexOf(',', pLoc+1);
/*Serial.print("i < 8, pLoc: ");
Serial.print(pLoc);
Serial.print(", ");
Serial.println(i);*/
}
else
{
lEndLoc = s.indexOf(',', pLoc+1);
lndSpeed = s.substring(pLoc+1, lEndLoc);
/*Serial.print("i = 8, pLoc: ");
Serial.println(pLoc);
Serial.print("lEndLoc: ");
Serial.println(lEndLoc);*/
}
}
return lndSpeed;
}
}
//Parse GPRMC NMEA sentence data from String
//String must be GPRMC or no data will be parsed
//Return Longitude
String parseGprmcTime(String s)
{
int pLoc = 0; //paramater location pointer
int lEndLoc = 0; //lat parameter end location
int dEndLoc = 0; //direction parameter end location
String gpsTime;
/*make sure that we are parsing the GPRMC string.
Found that setting s.substring(0,5) == "GPRMC" caused a FALSE.
There seemed to be a 0x0D and 0x00 character at the end. */
if(s.substring(0,4) == "GPRM")
{
//Serial.println(s);
for(int i = 0; i < 2; i++)
{
if(i < 1)
{
pLoc = s.indexOf(',', pLoc+1);
/*Serial.print("i < 8, pLoc: ");
Serial.print(pLoc);
Serial.print(", ");
Serial.println(i);*/
}
else
{
lEndLoc = s.indexOf(',', pLoc+1);
gpsTime = s.substring(pLoc+1, lEndLoc);
/*Serial.print("i = 8, pLoc: ");
Serial.println(pLoc);
Serial.print("lEndLoc: ");
Serial.println(lEndLoc);*/
}
}
return gpsTime;
}
}
// Turn char[] array into String object
String charToString(char *c)
{
String val = "";
for(int i = 0; i <= sizeof(c); i++)
{
val = val + c[i];
}
return val;
}


  • 大饭团
  • 默默无闻
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
楼主你这个程序接线图发我看下


2025-08-31 04:29:32
广告
不感兴趣
开通SVIP免广告
  • vdbb99
  • 小有名气
    4
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
我想问下你用的是哪个GPS模块


  • 2013RCfamily
  • 默默无闻
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
楼主可否贴一张你的测试结果图


  • pppaul
  • 默默无闻
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
楼主的库文件用的啥?


  • 竹炭L
  • 默默无闻
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
'parseGprmcLat' was not declared in this scope
你好,报这个错是为什么嘞


登录百度账号

扫二维码下载贴吧客户端

下载贴吧APP
看高清直播、视频!
  • 贴吧页面意见反馈
  • 违规贴吧举报反馈通道
  • 贴吧违规信息处理公示
  • 8回复贴,共1页
<<返回arduino吧
分享到:
©2025 Baidu贴吧协议|隐私政策|吧主制度|意见反馈|网络谣言警示