调试SIM808 GPS功能遇到问题求助
大家好,我在调试SIM808 的GPS 功能时,遇到问题,如下:1. 在loop函数中加入 Serial.println("111"); 这一段之后,在调试的时候一直输出 111,我的期望是输出 111 之后能继续输出 GPS 坐标信息
2. 在loop函数中加入 delay(1000); 这一段之后,在调试的时候什么都不输出了,我的期望是间隔1秒请求一次 GPS 数据
3. 在loop函数中加入 Serial.println(result); 这一段之后,在调试的时候一直输出 0,我的期望是能正常输出 GPS 坐标信息
4. 以上三段代码都注释掉的情况下能正确输出 GPS 坐标信息
我用的是 Arduino UNO R3 + DF SIM808板
以下是我的代码:
#include <DFRobot_sim808.h>
#include <SoftwareSerial.h>
DFRobot_SIM808 sim808(&Serial);
void setup() {
//mySerial.begin(9600);
Serial.begin(9600);
//******** Initialize sim808 module *************
while(!sim808.init()) {
delay(1000);
Serial.print("Sim808 init error\r\n");
}
//************* Turn on the GPS power************
if( sim808.attachGPS())
Serial.println("Open the GPS power success");
else
Serial.println("Open the GPS power failure");
}
void loop() {
//加上这段就一直输出 111
//Serial.println("111");
//加上这段什么也不输出了
//delay(1000);
int result = sim808.getGPS();
//************** Get GPS data *******************
if (result) {
Serial.println(result); // 这里输出 1
Serial.print("latitude :");
Serial.println(sim808.GPSdata.lat,6);
Serial.print("longitude :");
Serial.println(sim808.GPSdata.lon,6);
//************* Turn off the GPS power ************
sim808.detachGPS();
}else{
//加上这段就一直输出 0
//Serial.println(result);
}
}
页:
[1]