我购买了这个GPS模块
http://item.taobao.com/item.htm?spm=a1z0k.7385961.1997985097.d4918997.XjdXA1&id=13198221647&_u=8p7dcnj6ecc
没用示例中的GSM模块,想直接把GPS数据从串口监视器上显示出来,根据他示例的代码改了一下。。但是没反应。。求教。。
Q526970969
#include <SoftwareSerial.h>
//#include "inetGSM.h"
#include <string.h>
#include <TinyGPS.h>
/* This sample code demonstrates the normal use of a TinyGPS object.
It requires the use of SoftwareSerial, and assumes that you have a
4800-baud serial GPS device hooked up on pins 3(rx) and 4(tx).
*/
TinyGPS gps;
#define ledpin 13
#define pwrkey 27
int error;
boolean started=false;
bool newData = false;
char gps_year[8];
char gps_mon[3];
char gps_day[3];
char gps_hour[3];
char gps_min[3];
char gps_sec[3];
char gps_lon[20];
char gps_lat[20];
char gps_sms[100];
void setup()
{
//software power sim900 up
Serial.begin(115200);
Serial2.begin(9600);
delay(10000);
}
void loop()
{
check_gps();
}
char check_gps()
{
newData=false;
unsigned long chars;
unsigned short sentences, failed;
// For one second we parse GPS data and report some key values
for (unsigned long start = millis(); millis() - start < 1000;)
{
while (Serial2.available())
{
char c = Serial2.read();
Serial.write(c); // uncomment this line if you want to see the GPS data flowing
if (gps.encode(c)) // Did a new valid sentence come in?
newData = true;
Serial.println("GPS READY!");
}
}
if (newData)
{
float flat, flon;
unsigned long age;
int _year;
byte _month, _day,_hour,_minute,_second,_hundredths;
gps.f_get_position(&flat, &flon, &age);
gps.crack_datetime(&_year,&_month,&_day,&_hour,&_minute,&_second,&_hundredths,&age);
flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6;
flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6;
dtostrf(flat, 11, 6, gps_lat);
dtostrf(flon, 10, 6, gps_lon);
Serial.println("lat:"); //latitude
Serial.println(gps_lat);
Serial.println("lon:");
Serial.println(gps_lon);//longitude
}
} |