【问题标题】:Compilation error in connecting Arduino Uno with SKYNAV skm53 GPS module将 Arduino Uno 与 SKYNAV skm53 GPS 模块连接时出现编译错误
【发布时间】:2012-03-11 15:17:59
【问题描述】:

我正在尝试将Arduino Uno 与 skm53 GPS 模块连接,但是在使用 Arduino 软件上传草图之前,我对其进行了验证并发现了以下错误。

错误:#error NewSoftSerial 自 1.0 版起已移入 Arduino 核心。请改用 SoftwareSerial。

我在Arduino工具的libraries目录下包含了TinyGPS和NewSoftSerial这两个库,我搜了一下发现几乎所有的代码都和我的一样。

#include <TinyGPS.h>
#include <NewSoftSerial.h>

unsigned long fix_age;
NewSoftSerial GPS(2,3);
TinyGPS gps;
void gpsdump(TinyGPS &gps);
bool feedgps();
void getGPS();
long lat, lon;
float LAT, LON;

void setup(){
    GPS.begin(9600);
    //Serial.begin(115200);
}

void loop(){
    long lat, lon;
    unsigned long fix_age, time, date, speed, course;
    unsigned long chars;
    unsigned short sentences, failed_checksum;

    // Retrieves +/- latitude/longitude in 100000ths of a degree.
    gps.get_position(&lat, &lon, &fix_age);

    getGPS();
    Serial.print("Latitude : ");
    Serial.print(LAT/100000,7);
    Serial.print(" :: Longitude : ");
    Serial.println(LON/100000,7);
}

void getGPS(){
    bool newdata = false;
    unsigned long start = millis();
    // Every 1 seconds we print an update.
    while (millis() - start < 1000)
    {
        if (feedgps ()){
            newdata = true;
        }
    }
    if (newdata)
    {
        gpsdump(gps);
    }
}

bool feedgps(){
    while (GPS.available())
    {
        if (gps.encode(GPS.read()))
            return true;
    }
    return 0;
}

void gpsdump(TinyGPS &gps)
{
    //byte month, day, hour, minute, second, hundredths;
    gps.get_position(&lat, &lon);
    LAT = lat;
    LON = lon;
    {
        feedgps(); // If we don't feed the GPS during this long
                   //routine, we may drop characters and get 
                   //checksum errors.
    }
}

【问题讨论】:

    标签: gps arduino


    【解决方案1】:

    您可能正在查看较旧的示例(Arduino 1.0 之前和软件序列的预包含)。 这些示例适用于 Arduino .23 及更早版本。 只需像这样更改前四行代码,它就会编译成功:

    #include <TinyGPS.h>
    #include <SoftwareSerial.h>
    
    unsigned long fix_age;
    SoftwareSerial GPS(2,3);
    

    然后您可以删除 NewSoftLibrary 以避免将来出现问题。

    还有一个建议:将两个变量命名相同但大小写不同,这非常令人困惑。 最好使用更具描述性和区别性的名称来快速识别它们。可能更好的选择可能是串行软件连接接口的 ssGPS 和微型 GPS 库的 tlibGPS。

    【讨论】:

      猜你喜欢
      • 2023-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多