當(dāng)你用著Arduino或者內(nèi)建函數(shù)比較舒服的時(shí)候,你可能希望擴(kuò)展你的Arduino 附加庫。
附加庫是一個(gè)代碼的集合,可以讓你方便的連接一臺(tái)傳感器、顯示器、模組等等。比如,內(nèi)建庫LiquidCrystal 庫使得在LCD上顯示字符變得方便。在網(wǎng)絡(luò)上,有成百上千的附加庫可供下載。內(nèi)建庫和一些附加庫在鏈接https://www.arduino.cc/reference/en/libraries/中,這些附加庫只有安裝后才能使用它們。
可以采用庫管理器的方式為Arduino IDE安裝一個(gè)新庫(Arduino IDE v1.6.2以后的版本支持)。打開IDE,點(diǎn)擊"Sketch"(項(xiàng)目)> Include Library(加載庫) > Manage Libraries(管理庫),如下圖所示。
庫一般表現(xiàn)為ZIP文件或文件夾。文件夾的名稱一般為庫名,文件夾內(nèi)部一般包括一個(gè).cpp文件和一個(gè).h文件,通常還會(huì)有一個(gè)關(guān)鍵字.txt文件、示例文件夾,以及該庫的其他依賴文件。從Arduino IDE 1.0.5開始,可以安裝第三方庫。不要解壓zip文件,保持它的原始狀態(tài)。
在Arduino IDE中, Sketch(項(xiàng)目) > Include Library(加載庫) > Add .ZIP Library(添加.ZIP庫)。
準(zhǔn)確的選擇要添加的庫。導(dǎo)航到.zip文件的位置并打開它。
注意:該庫可以用于項(xiàng)目中,但是在舊版本IDE示例中,該庫直到IDE重啟之前,不會(huì)出現(xiàn)在File (文件)> Examples(示例)中
When you want to add a library manually, you need to download it as a ZIP file, expand it and put in the proper directory. The ZIP file contains all you need, including usage examples if the author has provided them. The library manager is designed to install this ZIP file automatically as explained in the former chapter, but there are cases where you may want to perform the installation process manually and put the library in the libraries folder of your sketchbook by yourself.
You can find or change the location of your sketchbook folder at File > Preferences > Sketchbook location.
Go to the directory where you have downloaded the ZIP file of the library
Extract the ZIP file with all its folder structure in a temporary folder, then select the main folder, that should have the library name
Copy it in the “l(fā)ibraries” folder inside your sketchbook.
Start the Arduino Software (IDE), go to Sketch > Include Library. Verify that the library you just added is available in the list.
Please note: Arduino libraries are managed in three different places: inside the IDE installation folder, inside the core folder and in the libraries folder inside your sketchbook. The way libraries are chosen during compilation is designed to allow the update of libraries present in the distribution. This means that placing a library in the “l(fā)ibraries” folder in your sketchbook overrides the other libraries versions.
The same happens for the libraries present in additional cores installations. It is also important to note that the version of the library you put in your sketchbook may be lower than the one in the distribution or core folders, nevertheless it will be the one used during compilation. When you select a specific core for your board, the libraries present in the core’s folder are used instead of the same libraries present in the IDE distribution folder.
Last, but not least important is the way the Arduino Software (IDE) upgrades itself: all the files in Programs/Arduino (or the folder where you installed the IDE) are deleted and a new folder is created with fresh content. This is why we recommend that you only install libraries to the sketchbook folder so they are not deleted during the Arduino IDE update process.
聯(lián)系客服