【发布时间】:2014-12-29 21:38:00
【问题描述】:
我在使用 TinyGPS 库解析纬度和经度时遇到问题。这个库与 RFduino 兼容吗?我可以通过将空白草图加载到 RFduino 然后打开串行监视器来读取 NMEA 字符串,所以我知道 GPS 数据正在通过串行端口,但是当我尝试将纬度或经度放入变量时,它用 999999999 填充变量。我通过 BLE 将此数据发送到 android。如果我不尝试获取 GPS 数据,我可以在 lat 或 lon 变量中发送我想要的任何值,它会出现在我的自定义 Android 应用程序中。我在某处读到 softserial 库在 rfduino 上不起作用。这是真的?如果没有,我将能够通过硬串行端口打印我的数据,从而使故障排除更加容易。下面我附上了我在我的 RFduino 上使用的代码。任何建议将不胜感激。
// CODE //
#include <RFduinoBLE.h>
#include <TinyGPS.h>
TinyGPS gps;
long lat = 5; //Load lat/lon with junk value for testing
long lon = 6;
char latBuf[20];
char lonBuf[20];
void setup() {
// this is the data we want to appear in the advertisement
// (if the deviceName and advertisementData are too long to fix into the 31 byte
// ble advertisement packet, then the advertisementData is truncated first down to
// a single byte, then it will truncate the deviceName)
RFduinoBLE.advertisementData = "ledbtn";
// start the BLE stack
RFduinoBLE.begin();
Serial.begin(9600);//For GPS Communication
}
void loop(){
char c = byte(Serial.read());
gps.encode(c);
gps.get_position(&lat,&lon); // get latitude and longitude
// send position as char[]
String latString = String(lat);
String lonString = String(lon);
latString.toCharArray(latBuf, 20);
lonString.toCharArray(lonBuf, 20);
RFduinoBLE.send(lonBuf, 20);
}
void RFduinoBLE_onDisconnect()
{
}
void RFduinoBLE_onReceive(char *data, int len)
{
RFduinoBLE.send(lonBuf, 20);
}
【问题讨论】:
-
你是如何设法将 gps 模块与 rfduino 一起使用的?
-
我使用了这个模块。 adafruit.com/products/790