简体   繁体   中英

How do I install a library file in Arduino IDE?

I am trying to install a library (pitches.h) in Arduino IDE by selecting "Sketch" > "Include Library" > "Add .ZIPLibrary". Then I got an error message shown below:

/Users/tomo/Desktop/passive_buzzer/passive_buzzer.ino
A library named pitches already exists

But I don't see the library, "pitches", in the drop down menu, which appears by selecting "Include Library". And then when I compile the sketch, I got the following error message:

passive_buzzer:4:10: fatal error: pitches.h: No such file or directory
 #include <pitches.h>
          ^~~~~~~~~~~
compilation terminated.
exit status 1
pitches.h: No such file or directory

So I think the library is not installed correctly. Can anyone help me install it properly please?

The file name of the library is correct as I copied and pasted the file name from the file to the sketch.

I think the folder structure of the library should also be correct. When I unzipped "pitches.zip", I got the "pitches.h" file in a folder named "pitches". I zipped "pitches.h" file only and then I tried to install it by selecting "Sketch" > "Include Library" > "Add .ZIPLibrary". I got the following message:

java.io.IOException: Zip doesn't contain a library
    at processing.app.Base.handleAddLibrary(Base.java:2417)
    at processing.app.Base$6.actionPerformed(Base.java:1124)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.AbstractButton.doClick(AbstractButton.java:376)
    at com.apple.laf.ScreenMenuItem.actionPerformed(ScreenMenuItem.java:125)
    at java.awt.MenuItem.processActionEvent(MenuItem.java:669)
    at java.awt.MenuItem.processEvent(MenuItem.java:628)
    at java.awt.MenuComponent.dispatchEventImpl(MenuComponent.java:357)
    at java.awt.MenuComponent.dispatchEvent(MenuComponent.java:345)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:763)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:84)
    at java.awt.EventQueue$4.run(EventQueue.java:733)
    at java.awt.EventQueue$4.run(EventQueue.java:731)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:730)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Zip doesn't contain a library

Environment Arduino: 1.8.13 (Mac OS X), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)" macOS Mojave ver. 10.14.6

Thank you in advance, Tomo

Thanks to Juraj, I found the way to install and include a library:

  1. Save a sketchbook file and a library file in the "Sketchbook location".
  2. Open the sketchbook file in the "Sketchbook location". (A folder is automatically created and the sketchbook file is moved to the folder, then the sketchbook will open.)
  3. Through the sketchbook opened, install the library file in the "Sketchbook location" and include it.

The "Sketchbook location" can be confirmed/defined by "Arduino" > "Preference" . This way was applicable to the other sketchbook files and their associated library files provided by Arduino.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM