banner



Arduino How To Install A Library

Contributors: Nate, .Brent.

Favorited Favorite 22

What's a Library?

Arduino libraries take a complex job and boil it down to simple to use functions. Arduino users have written lots of exciting add-ons for Arduino. For example, capacitive sensing takes difficult timing and pulsing of digital pins. We tin can write the code from scratch, or we can stand up on the shoulders of nifty people who are smarter than we are.

Capacitive bear upon sensing is a very pop interface. The CapacitiveSensor library takes care of everything so that we don't have to write code like this:

            language:c *sOut &= ~sBit;        // set Send Pivot Annals low *rReg &= ~rBit;        // fix receivePin to input *rOut &= ~rBit;        // set receivePin Register low to brand sure pullups are off *rReg |= rBit;         // ready pin to OUTPUT - pin is now Depression AND OUTPUT *rReg &= ~rBit;        // set pin to INPUT  *sOut |= sBit;         // set send Pin Loftier interrupts();         // enable interrupts  while ( !(*rIn & rBit)  && (full < CS_Timeout_Millis) ) {     total++; }  if (total > CS_Timeout_Millis)      return -two;         //  total variable over timeout  // set receive pivot Loftier briefly to charge upwards fully noInterrupts();         // disable interrupts *rOut  |= rBit;        // gear up receive pivot High - turns on pullup  *rReg |= rBit;         // set pin to OUTPUT - pin is now High AND OUTPUT *rReg &= ~rBit;        // set pivot to INPUT  *rOut  &= ~rBit;       // turn off pullup *sOut &= ~sBit;        // set send Pin Low interrupts();         // re-enable interrupts  while ( (*rIn & rBit) && (total < CS_Timeout_Millis) ) {      total++; }  if (total >= CS_Timeout_Millis)     render -2;     // total variable over timeout else     return 1;                      

All that code tin can be replaced with a much easier to use and understand statement such every bit:

            language:c senseReading = myCapPad.capacitiveSensor(xxx);                      

The myCapPad.capacitiveSensor() takes care of all the heavy lifting and the senseReading variable contains the value sensed from our capacitive pad. Libraries make circuitous tasks easier so that nosotros tin can focus on larger projects.

There are thousands of libraries out there! And luckily information technology's pretty easy to install them. This tutorial will show you how to install a library in Arduino v1.0.5 but should apply for many past, present, and hereafter versions of Arduino.

Suggested Reading

Brand sure you have a good agreement of the following concepts before getting any farther into this tutorial.

What is an Arduino?

What is this 'Arduino' affair anyhow? This tutorials dives into what an Arduino is and forth with Arduino projects and widgets.

Installing Arduino IDE

A stride-by-step guide to installing and testing the Arduino software on Windows, Mac, and Linux.

The Arduino website also has great instructions on installing libraries if you need more than information for using the Arduino IDE'south library managing director, importing a *.zip library, and transmission installation.

Using the Arduino Library Manager

The library director was added starting with Arduino IDE versions 1.5 and greater (1.6.x). It is found in the 'Sketch' card nether 'Include Library', 'Manage Libraries...'

Manage libraries menu option

Arduino 1.5+ Library Manager Card Option

When you open up the Library Manager you lot will detect a large list of libraries set for one-click install. To find a library for your product, search for the product name or a keyword such every bit 'k type' or 'digitizer', and the library you want should testify upwards. Click on the desired library, and the 'Install' push button will appear. Click that push, and the library should install automatically. When installation finishes, close the Library Manager.

Example library in library manager

Library in the Library Manager, Ready to be Installed

Alternatively, if you have a library of your own y'all would like to add or a library that hasn't been added to the Library Manger yet, you can click the 'Add .Null Library' selection, which will so allow you to cull a folder or *.naught file containing the library of your choice.

Heads upwards! In previous version of the Arduino IDE, all libraries were stored together deep within the contents binder of the Arduino awarding. Still, in newer versions of the IDE, libraries added through the Library Manger tin can exist found in a binder named 'libraries' found in your Arduino Sketchbook folder.
For more than information on the Library manger, including deleting and updating info, visit the GitHub: Arduino - Library Manager FAQ.

GitHub: Arduino - Library Managing director FAQ

Now that the library is installed, an case sketch tin be found in the 'Examples' submenu.

Example sketch

Example Sketch

Since this is a relatively new feature of the Arduino IDE at the time of this writing not all SparkFun products will have libraries in the library manager. We are adding new products and working our way through older products over time. If yous don't find the library you demand in the manager or for some reason cannot install one of the mod IDE releases, follow the instructions in the following sections.

Manually Installing a Library - Windows

This section covers manually installing a library under the Windows environs and utilizes quite a few screen shots. If you're more than of a text learner so cheque out the Arduino tutorial on installing libraries.

Nosotros are going to use the Capacitive Sense library for this example. Navigate to the library's page and download the nada file.

Example of Installed Capacitive Touch Arduino Library on Windows

The contents of the Capacitive Sense naught file

Discover the zip file on your local figurer (wherever downloaded files terminate upwards). Under Windows, yous should exist able to double click on the file to open up it upwards.

This particular library contains libraries for both the bones Arduino and the more advanced Arduino Due. You tin utilize both if you lot'd like, merely, for this case, we volition be copying and installing merely the CapacitiveSensor folder.

Zipped Arduino Library

Libraries will usually contain a *.cpp file and .h file. About volition also contain an examples folder.

Arduino Libraries Path

Under Windows, Arduino stores all the add-on libraries within the My Documents folder. Here we see the location of the Arduino libraries binder.

Open an explorer window and navigate to the libraries binder nether My Documents. At present copy the new CapacitiveSensor folder to the libraries folder.

Capacitive Sensor Library in Arduino Libaries Folder

Success!

To verify the library has been installed correctly, open upwards the Examples folder nether the Arduino IDE. Wait. Where's the CapacitiveSensor example? Did you have Arduino open up when you copied and pasted the directory? Arduino checks the library directory at startup so if yous already accept Arduino open, you will need to restart Arduino whatsoever time you add to the libraries directory.

Missing Arduino Capacitive Sensor Library

If you don't see the CapacitiveSensor case endeavor closing and re-opening Arduino IDE.

Verify Arduino Capacitive Sensor Library

There it is! Permit's open the example provided with our new library.

Example Capacitive Touch Library

Examples are the greatest thing about libraries! Expert libraries will accept well written examples showing how to apply the library. These sketches are wonderful resource for example code and learning how to write adept code under Arduino.

You now have the Capacitive Sensor library installed! Experience costless to commencement from the example sketch, or brainstorm writing your own lawmaking using the functions provided by the library. A library usually has documentation either on its site or written into readme files and instance code. In full general, to speedily learn how to apply a library check out the case lawmaking.

Manually Installing a Library - Mac

This section covers manually installing a library under the Mac Os Ten environs. If you're more of a text learner then check out the Arduino tutorial on installing libraries.

We are going to use the Capacitive Sense library for this example. Navigate to the library'due south page and download the zip file.

Find the zip file on your local reckoner (wherever downloaded files finish up). Unzip it, and await at the folder contents.

Example of Installed Capacitive Touch Arduino Library on Mac OS X

The contents of the Capacitive Sense zip file. Libraries will usually contain a *.cpp* file and *.h* file. Most will also contain an *examples* binder.

This item library contains libraries for both the basic Arduino and the more advanced Arduino Due. Yous can use both if you'd similar, simply, for this example, we will be copying and installing only the CapacitiveSensor binder.

Now we need to add this folder to the Libraries folder for Arduino. This folder is somewhat subconscious in Bone X. To get there you can exercise one of ii things. Choice one, right-click on the Arduino icon located in your Dock. Go upward to 'Options', then click 'Prove in Finder'.

Getting to the Arduino Libraries 1

Selection 2, find the Arduino app located in your applications folder within Finder. Now, right-click on the Arduino app, and select 'Show Package Contents'. Either pick should get you to this point.

Getting to the Arduino Libraries 2

Navigate through the following folders, 'Contents -> Resource -> Java', until y'all reach the 'libraries' folder.

Arduino Libraries Path

Within the libraries folder is where you desire to copy/movement the library binder you just downloaded and unzipped. You'll as well notice this is where all the default libraries live as well as whatever other libraries yous may have installed in the past.

Capacitive Sensor Library in Arduino Libraries Folder

Side by side, brand sure that restart the Arduino IDE if it was open when you installed the library. This is a very important, often overlooked step. If yous don't restart, the library you simply installed will not yet be bachelor to the IDE.

To verify the library has been installed correctly, open upwardly the 'File > Examples' folder under the Arduino IDE.

Capacitive Sense Library Installed

There information technology is! Let'south open up the example provided with our new library.

Example Capacitive Sensor Code

Examples are the greatest thing about libraries! Proficient libraries volition have well written examples showing how to use the library. These sketches are wonderful resource for example lawmaking and learning how to write proficient code under Arduino.

You now have the Capacitive Sensor library installed! Feel complimentary to get-go from the example sketch, or begin writing your ain code using the functions provided by the library. A library commonly has documentation either on its site or written into readme files and example lawmaking. In general, to chop-chop learn how to use a library check out the example code.

Resources and Going Farther

If you lot're looking for some great libraries to get started with, here are some of our favorites:

  • TinyGPS is the golden standard for interfacing to GPS modules.
  • SevSeg is a library we wrote to brand controlling 7-segment displays easier.
  • Sdfat is a very good library that allows you lot to read and write files to SD cards. Great for datalogging! Be sure to checkout all the examples included with the library.
  • MP3Shield is a swell example of a customer of SparkFun taking circuitous case code and creating a very adept library to make the device easier to use.
  • EEPROM is a built-in library that allows users to read and store settings within the non-volatile retentivity of the ATmega328. Very useful!
  • Capacitive Sensor is the library we covered in this tutorial. It's swell for non-contact capacitive switches and field sensing.
  • Infrared Remote is a great library for reading signals from IR remotes and controlling IR remote based things like TVs and sound systems.

Built-In Libraries

You may not realize information technology, but you lot're probably already using libraries! If you've used:

            Series.print("How-do-you-do world!");                      

And so you're using the Serial() library built in to Arduino. Arduino has quite a few built-in libraries. Hither's the list of the standard libraries that yous can start using immediately!

Write your Ain Arduino Library

Once yous've used a handle of unlike libraries, consider writing your own! Hither'south a skilful tutorial showing how to write your own library so that you can help the globe by making circuitous tasks a piddling easier.

Including Your Library in the Library Manager

If you would like to have it included in the Arduino IDE Library Director, make sure that your library fits the standards.

And so submit an effect request for you 3rd political party library in the GitHub repo for the Arduino IDE linked below. For an example of submitting a request, cheque out SparkFun'south fingerprint scanner TTL library request.

Looking for the right Arduino?

Check out our Arduino Comparing Guide! We've compiled every Arduino development board we conduct, so you can quickly compare them to observe the perfect i for your needs.

Take me at that place!

More Arduino

If you're looking for more Arduino tutorials, accept a wait at these:

Installing an Arduino Bootloader

This tutorial will teach yous what a bootloader is and why you would need to install or reinstall information technology. We will also go over the process of called-for a bootloader by flashing a hex file to an Arduino microcontroller.

Data Types in Arduino

Acquire about the mutual data types and what they signify in the Arduino programming environment.

Or bank check out this blog mail for more ideas.

Source: https://learn.sparkfun.com/tutorials/installing-an-arduino-library/all

Posted by: horowitzwiffew.blogspot.com

0 Response to "Arduino How To Install A Library"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel