【问题标题】:RFduino not pulling NMEA strings from GPSRFduino 没有从 GPS 中提取 NMEA 字符串
【发布时间】: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 arduino nmea rfduino


【解决方案1】:

我看到的一个问题:loop() 每次执行循环时都试图读出 GPS 坐标。这种方法有两个问题:1)循环不会等到串行数据准备好,2)循环不会等到接收到的 GPS 数据有效。

从阅读 http://arduino.cc/en/Tutorial/ReadASCIIStringhttp://arduiniana.org/libraries/tinygps/ 开始,我建议将 loop() 重写为如下内容:

loop() {
  char c;
  float fLat, fLon;
  unsigned long fix_age;
  static unsigned long previous_fix_age = 0;

  // If nothing to read; do nothing.
  // Read as many characters as are available.
  while (Serial.available() > 0) {

    // Tell the GPS library about the new character.
    c = Serial.read();
    gps.encode(c);

    gps.f_get_position(&flat, &flon, &fix_age);
    if (fix_age != TinyGPS::GPS_INVALID_AGE && fix_age != previous_fix_age) {
      // new GPS data is valid, new, and ready to be printed

      previous_fix_age = fix_age; // remember that we've reported this data.

      String latString = String(lat);
      ...the rest of the code you already have to print the lat and lon.
    }

  }
}

关于 previous_fix_age 的代码在那里,以便循环仅在从 GPS 接收到新的修复时打印坐标。

【讨论】:

    猜你喜欢
    • 2010-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多