2014-12-29 24 views
1

我無法使用TinyGPS庫來分析Lat和Lon。這個庫與RFduino兼容嗎?我可以通過加載一個空白的草圖到RFduino然後打開串行監視器來讀取NMEA字符串,所以我知道GPS數據正在通過串行端口,但是當我嘗試將Lat或Lon變成變量時,它用999999999填充變量。我通過BLE將這些數據發送給一個android。如果我不嘗試獲取GPS數據,則可以在經緯度或垂直變量中發送我想要的任何值,並將其顯示在我的自定義Android應用程序中。我在某處讀到softserial庫不適用於rfduino。這是真的?如果沒有,我將能夠通過硬串行端口打印我的數據,從而使故障排除變得更加容易。下面我附上了我在RFduino上使用的代碼。任何意見,將不勝感激。RFduino不從GPS拉NMEA字符串

//  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); 
} 
+0

你是怎麼設法使用rfduino的gps模塊和哪個模塊的? – quape

+0

我使用了這個模塊。 http://www.adafruit.com/products/790 – user1359770

回答

1

我看到的一個問題是:循環()試圖在每次執行循環時讀出GPS座標。這種方法有兩個問題:1)循環不等待,直到串行數據準備好; 2)循環不等待,直到接收到的GPS數據有效。

從閱讀http://arduino.cc/en/Tutorial/ReadASCIIStringhttp://arduiniana.org/libraries/tinygps/我建議重寫循環(),以這樣的:

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接收環路打印座標。

+0

我做了這些改變,它的工作!謝謝。 – user1359770