macOS版的VS Code Arduino編輯環境設置步驟,和Windows版一樣,僅程式庫路徑不同。以編輯Arduino Uno控制板程式來說,開啟空白的專案資料夾(此例為“blink”),按F1功能鍵執行“Arduino: Initialize”命令,VS Code將產生如下的c_cpp_propertise.json內容(註:從arduino.cc官網下載Arduino開發軟體之後,請把Arduino軟體從「下載(Downloads)」文件夾拖入「應用程式(Applications)」文件夾):
{ "configurations": [ { "name": "Mac", "includePath": [ "/Applications/Arduino.app/Contents/Java/tools/**", "/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/**" ], "forcedInclude": [ "/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Arduino.h" ], "macFrameworkPath": [ "/System/Library/Frameworks", "/Library/Frameworks" ], "intelliSenseMode": "clang-x64", "compilerPath": "/usr/bin/clang", "cStandard": "c11", "cppStandard": "c++17" } ], "version": 4 }
Mac版的Arduino的內建程式庫,封裝在應用程式檔(*.app)內部的“Contents”路徑底下,若有興趣查看,請在應用程式圖示上面按滑鼠右鍵,選擇「顯示套件內容」:
Arduino預設安裝在應用程式(Applications)路徑,所以Arduino內建程式庫的路徑是:
/Applications/Arduino.app/Contents/Resources/Java/libraries/
使用者(就是我們自己)額外新增的程式庫,則存放在使用者「家目錄」底下的「文件(Documents)」路徑當中的“Arduino”文件夾:
~/Documents/Arduino/libraries/
因此,編寫Arduino Uno控制板所需的c_cpp_propertise.json檔的內容如下:
{ "configurations": [ { "name": "Arduino Uno", "includePath": [ "${workspaceFolder}/**", "/Applications/Arduino.app/Contents/Java/tools/**", "/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/**", "/Applications/Arduino.app/Contents/Java/hardware/tools/avr/avr/include/**", "~/Documents/Arduino/libraries/**" ], "forcedInclude": [ "/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Arduino.h" ], "defines": [ "USBCON", "ARDUINO=10809" ], "intelliSenseMode": "clang-x64", "cStandard": "c11", "cppStandard": "c++17" } ], "version": 4 }
編寫ESP8266與ESP32控制板程式的設置
同樣地,編寫非Arduino原廠控制板的程式之前,請先在Arduino IDE的控制板管理員,下載、安裝指定控制板的編譯環境。以ESP8266控制板為例,請在Arduino IDE的主功能表,選擇”Arduino→Preferences“命令,在「偏好設定」面板的「開發板管理網址」欄位輸入ESP8266控制板管理員的網址: https://arduino.esp8266.com/stable/package_esp8266com_index.json
然後選擇「工具→開發板→開發板管理員」,在「控制板管理員」面板中搜尋並安裝“ESP8266”:
底下是包含Arduino Uno, ESP8266和ESP32三種控制板的c_cpp_propertise.json設置檔原始碼,ESP8266和ESP32控制板管理員的版本分別是2.5.2和1.0.2,請自行修改成你安裝的版本:
{ "configurations": [ { "name": "Arduino Uno", "includePath": [ "${workspaceFolder}/**", "/Applications/Arduino.app/Contents/Java/tools/**", "/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/**", "/Applications/Arduino.app/Contents/Java/hardware/tools/avr/avr/include/**", "~/Documents/Arduino/libraries/**" ], "forcedInclude": [ "/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Arduino.h" ], "defines": [ "USBCON", "ARDUINO=10809" ], "intelliSenseMode": "clang-x64", "cStandard": "c11", "cppStandard": "c++17" }, { "name": "Wemos D1 mini", "includePath": [ "~/Library/Arduino15/packages/esp8266/tools/**", "~/Library/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/**", "~/Documents/Arduino/libraries/**" ], "forcedInclude": [ "~/Library/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/cores/esp8266/Arduino.h", "~/Library/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/variants/d1_mini/pins_arduino.h" ], "defines": [ "USBCON", "ARDUINO=10809" ] }, { "name": "ESP32", "includePath": [ "${workspaceFolder}/**", "~/Library/Arduino15/packages/esp32/hardware/esp32/1.0.2/cores/esp32/**", "~/Library/Arduino15/packages/esp32/hardware/esp32/1.0.2/libraries/**", "~/Documents/Arduino/libraries/**" ], "defines": [ "USBCON", "ARDUINO=10809" ], "forcedInclude": [ "~/Library/Arduino15/packages/esp32/hardware/esp32/1.0.2/variants/d32/" ], "intelliSenseMode": "clang-x64", "cStandard": "c11", "cppStandard": "c++17" } ], "version": 4 }
最後,在“.vscode”文件夾裡的arduino.json檔,加入暫存編譯檔的“build_temp”路徑: