Help us understand the problem. What is going on with this article?

Mbed(LPC1768)でGPSのデータを取得する

More than 1 year has passed since last update.

はじめに

LPC1768をつかってGPSを取得するやり方の備忘録。

使うもの

Mbed LPC1768
https://www.switch-science.com/catalog/250/
GPS AE-GPS 
http://akizukidenshi.com/download/ds/akizuki/AE-GPS_manual_a.pdf

手順

➀配線する

mbed_GPS.PNG

今回はp9,p10のピンを使ったけれど、LPC1768はSerialピンを3セット持っているのでp13,p14やp28,p27でもよい。

②コードを書く

GPSscript.cpp
#include "mbed.h"
#include "math.h"

#define TIME_GAP      6.0   

Serial           gps(p9,p10);   //ピンを指定

Timer  timer_open;
Timer  timer_log;
Ticker tic_open;
Ticker tic_log;

float   _DMS2DEG(float raw_data);
int     _input(char cha);

float Time;
char  gps_data[256];
int   cnt_gps;
int   Cnt_GPS=0;

int main(){
    while(1){     
        if(gps.readable()){
            gps_data[cnt_gps] = gps.getc();
            if(gps_data[cnt_gps] == '$' || cnt_gps ==256){
                cnt_gps = 0;
                memset(gps_data,'\0',256);
            }else if(gps_data[cnt_gps] == '\r'){
                float world_time, lon_east, lat_north;
                int rlock, sat_num;
                char lat,lon;
                if(sscanf(gps_data,"GPGGA,%f,%f,%c,%f,%c,%d,%d",&world_time,&lat_north,&lat,&lon_east,&lon,&rlock,&sat_num)>=1){
                    if(rlock==1){
                        lat_north = _DMS2DEG(lat_north);
                        lon_east = _DMS2DEG(lon_east);
                        printf("%s\r\n",gps_data);
                        printf("Lat:%f,Lon:%f\r\ntime:%f,sat_num:%d\r\n",lat_north,lon_east,world_time,sat_num);
                    }else{
                        printf("%s\r\n",gps_data);
                    }
                }
            }else{
                cnt_gps++;
            }

        }
        if(timer_log.read()>=30.0*60.0) timer_log.reset();
    }
}

float _DMS2DEG(float raw_data){
    int d=(int)(raw_data/100);
    float m=(raw_data-(float)d*100);
    return (float)d+m/60;
}

参考 http://www.hiramine.com/physicalcomputing/general/gps_nmeaformat.html?iframe=true&width=1040&height=620

③Tera Termで表示

GPS_result.PNG

電波がんばれ...。

onenechan
女子大生の備忘録
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした