Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
RFduino未从GPS中提取NMEA字符串_Gps_Arduino_Nmea_Rfduino - Fatal编程技术网

RFduino未从GPS中提取NMEA字符串

RFduino未从GPS中提取NMEA字符串,gps,arduino,nmea,rfduino,Gps,Arduino,Nmea,Rfduino,我在使用TinyGPS库解析Lat和Lon时遇到问题。这个库与RFduino兼容吗?我可以通过将空白草图加载到RFduino,然后打开串行监视器来读取NMEA字符串,因此我知道GPS数据正在通过串行端口传输,但当我尝试将Lat或Lon输入变量时,它会用9999999填充变量。我正在通过BLE将这些数据发送到android。如果我不尝试获取GPS数据,我可以在lat或lon变量中发送任何我想要的值,并显示在我的自定义Android应用程序中。我在某个地方读到softserial库在rfduino上

我在使用TinyGPS库解析Lat和Lon时遇到问题。这个库与RFduino兼容吗?我可以通过将空白草图加载到RFduino,然后打开串行监视器来读取NMEA字符串,因此我知道GPS数据正在通过串行端口传输,但当我尝试将Lat或Lon输入变量时,它会用9999999填充变量。我正在通过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);
}
//代码//
#包括
#包括
TinyGPS;
长lat=5//用垃圾值加载lat/lon进行测试
长lon=6;
char-latBuf[20];
char lonBuf[20];
无效设置(){
//这是我们希望在广告中出现的数据
//(如果deviceName和advertisementData太长,无法固定到31字节
//如果是ble广告数据包,则首先将advertisementData截断为
//一个字节,然后它将截断deviceName)
RFduinoBLE.advertisementData=“ledbtn”;
//启动可扩展堆栈
RFduinoBLE.begin();
Serial.begin(9600);//用于GPS通信
}
void循环(){
char c=字节(Serial.read());
编码(c);
gps.get_position(&lat,&lon);//获取纬度和经度
//以字符[]形式发送位置
字符串latString=字符串(lat);
字符串lonString=字符串(lon);
latString.toCharArray(latBuf,20);
toCharArray(lonBuf,20);
RFduinoBLE.send(lonBuf,20);
}
void RFduinoBLE_onDisconnect()
{
}
void RFduinoBLE_onReceive(字符*数据,整数长度)
{
RFduinoBLE.send(lonBuf,20);
}

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

通过阅读,我建议将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.
    }

  }
}

有关于以前的固定时间的代码,因此只有当从GPS接收到新的固定时间时,循环才会打印坐标。

您是如何将GPS模块与rfduino一起使用的?哪一个?我使用了此模块。