2014/09/28

Arduino小知識:error: 'TKD2' was not declared

當使用Arduino IDE 1.5.7時(應該早自1.5.5 r2便有此錯誤),若想使用紅外線程式庫IRremote,光是底下這短短的草稿碼:

#include <IRremote.h>
void setup() {
}
void loop() {
}

就會出現底下的編譯錯誤訊息(若選擇「Arduino Robot Control」以外的板子):

path-to-arduino\libraries\RobotIRremote\src\IRremoteTools.cpp:5:16: error: 'TKD2' was not declared in this scope
 int RECV_PIN = TKD2; // the pin the IR receiver is connected to
 
原因在於,Arduino IDE 1.5.5 r2開始加入一套縮減版的IRremote程式庫,名為RobotIRremote,更動了不少東西,但有些地方卻沒變(譬如檔名),以至於起衝突。

此錯誤的詳細情況,大致如此:想使用自行安裝的IRremote,但Arduino IDE卻以內建的RobotIRremote為優先;RobotIRremote的檔案IRremoteTools.cpp需要TKD2的腳位定義,而只有「Arduino Robot Control」板子的腳位定義檔裡才有TKD2這玩意兒,如此一來,就會發生上述的錯誤訊息。

解決之法:

  • 若你想使用自己安裝的IRremote,而且不是使用Arduino Robot Control板子,那就乾脆把path-to-arduino-1.5.x\libraries\RobotIRremote整個移除算了。
  • 也可以自行更改RobotIRremote裡的檔名,並連帶修改相關程式碼,解決衝突;較為困難,屬於暫時性解法,照理說應該由Arduino官方開發團隊修改。
  • 若想使用內建的RobotIRremote,目前似乎只有Arduino Robot Control板能用;要不然就要自己修改程式庫。

參考資料:

12 comments:

  1. 好像Arduino的Library都很容易跟Robot相關的部分衝到
    我在使用adafruit的Library時也有衝到的情況

    ReplyDelete
  2. http://qmaw.pixnet.net/blog/post/386285501
    您好,這是我自己在使用adafruit的library時,遇到的狀況,也是需要把Robot的相關函式都刪掉才有辦法編譯成功。

    ReplyDelete
    Replies
    1. 我剛用Arduino IDE 1.5.8試了你網頁裡說的程式庫,並無錯誤耶。
      嗯,奇怪。

      Delete
    2. 剛剛試了一下,1.5真的有解掉這問題,感謝您。

      Delete
    3. 我剛用1.0.6試了,也沒有錯誤耶。

      Delete
    4. 囧~我的剛好是1.0.5r2,國外的論壇是建議沒在用Robot板子的話,就刪掉跟robot有關的資料夾。

      Delete
    5. 我剛用1.0.5 r2試了,也沒有錯誤耶。

      Delete
    6. 剛剛我用1.0.5 r2,又編了一次,有下面這些Error,但是1.0.6 & 1.5都沒這問題,可以直接編過。不過也有可能我的1.0.5裝了其他的lib導致衝突。
      C:\arduino-1.0.5-r2\libraries\Robot_Control\ArduinoRobot.cpp:18: error: 'MUXB' was not declared in this scope
      C:\arduino-1.0.5-r2\libraries\Robot_Control\ArduinoRobot.cpp:18: error: 'MUXC' was not declared in this scope
      C:\arduino-1.0.5-r2\libraries\Robot_Control\ArduinoRobot.cpp:18: error: 'MUXD' was not declared in this scope
      C:\arduino-1.0.5-r2\libraries\Robot_Control\ArduinoRobot.cpp:19: error: 'MUX_IN' was not declared in this scope
      C:\arduino-1.0.5-r2\libraries\Robot_Control\ArduinoRobot.cpp:22: error: 'BUZZ' was not declared in this scope
      C:\arduino-1.0.5-r2\libraries\Robot_Control\ArduinoRobot.cpp:25: error: 'Serial1' was not declared in this scope

      Delete
    7. 嗯,應該是跟Adafruit_GFX起衝突。

      Delete
    8. 不過我並無發生這些錯誤,嗯,真奇怪。

      Delete
  3. Anonymous11/2/15 18:31

    1.6 Got the same issue.

    ReplyDelete