###### tags: `產品開發` `FlagsBlock`,`esp8266` 製作可攜式的 Win32/64 通用 ESP8266 Arduino IDE 環境 ==== 1. 安裝 [git 工具](https://www.git-scm.com), 如果是在 Windows XP 上, 必須使用 [2.10.0 版](https://github.com/git-for-windows/git/releases/tag/v2.10.0.windows.1), 較新的版本並不支援 Windows XP。 3. 安裝 Python, 3.x 或是 2.7 都可以。 5. 下載 zip 格式的 Arduino IDE, 由於 1.6.10 版在 Windows XP 上執行有問題, 會出現以下錯誤訊息: ```sh panic: Failed to find GetFileInformationByHandleEx procedure in kernel32.dll: The specified procedure could not be found. ``` 建議使用 [1.8.9 版的 Arduino IDE](https://www.arduino.cc/download_handler.php?f=/arduino-1.8.9-windows.zip)。 1. 下載解開之後, 請在 Arduino\hardware 下, 建立 esp8266com 資料夾。 2. 開啟命令提示字元視窗, 使用 git 工具下載 ESP8266 Arduino Core 套件: ```sh cd arduino\hardware\esp8266com git --branch 2.5.0 https://github.com/esp8266/Arduino.git esp8266 1. 更新套件中的程式庫: ```sh cd esp8266com git submodule update --init ``` 這個步驟一定要做, 否則像是 SoftwareSerial 程式庫的內容預設是空的, 編譯到相關程式時就會失敗。 1. 下載 esp8266 的編譯工具鏈: ```sh cd tools python get.py ``` :::info :bomb: 請特別留意, 工具鏈有區分 Win32 和 Win64 版本, 如果要能夠跨 Win32/64 執行, 就必須下載 Win32 的版本, get.py 預設會自行判斷平台, 如下所示 (以 2.5.0 版的 ESP8266 Arduino Core 為例): ```py=96 def identify_platform(): arduino_platform_names = {'Darwin' : {32 : 'i386-apple-darwin', 64 : 'x86_64-apple-darwin'}, 'Linux' : {32 : 'i686-pc-linux-gnu', 64 : 'x86_64-pc-linux-gnu'}, 'LinuxARM': {32 : 'arm-linux-gnueabihf', 64 : 'aarch64-linux-gnu'}, 'Windows' : {32 : 'i686-mingw32', 64 : 'x86_64-mingw32'}} bits = 32 if sys.maxsize > 2**32: bits = 64 sys_name = platform.system() if 'Linux' in sys_name and (platform.platform().find('arm') > 0 or platform.platform().find('aarch64') > 0): sys_name = 'LinuxARM' if 'CYGWIN_NT' in sys_name: sys_name = 'Windows' return arduino_platform_names[sys_name][bits] ``` 如果要強制下載 Win32 版本的工具鏈, 可以把其中的 `identify_platform()` 函式修改如下: ```py=96 def identify_platform(): arduino_platform_names = {'Darwin' : {32 : 'i386-apple-darwin', 64 : 'x86_64-apple-darwin'}, 'Linux' : {32 : 'i686-pc-linux-gnu', 64 : 'x86_64-pc-linux-gnu'}, 'LinuxARM': {32 : 'arm-linux-gnueabihf', 64 : 'aarch64-linux-gnu'}, 'Windows' : {32 : 'i686-mingw32', 64 : 'x86_64-mingw32'}} return arduino_platform_names['Windows'][32] ``` :::