Part 1 focused on installing and setting up Atmel Studio 6 for Arduino Boards.
Part 2 told you how to integrate and use Arduino code with Atmel Studio 6.

Now Part 3, from a user suggestion, will explain how to include custom Arduino libraries to your project.

Step 1: Having gone through Part 2

The purpose of this tutorial is to make you able to use non-default Arduino libraries. You need to have the Arduino core working first, which is Part 2.

Step 2: Locate the wanted library

I will use the Arduino EEPROM library in this tutorial as an example. It will be similar with any library.
Go to your Arduino libraries folder, locate the EEPROM library, and open the folder.
Select only EEPROM.h and EEPROM.cpp and copy them.

Now that there are variants, choose the one you prefer:

Variant 1: Directly into the Arduino core

In Part 2, I made you create a folder named "ArduinoCore" with all the .h Arduino files.

Paste EEPROM.h and EEPROM.cpp there (not in a subfolder).

This method is really simple, that's all you need for that step, and you can go directly to Step 4.

But I don't really like it, since I like to keep things clean and organized, and I only want the ArduinoCore files in my ArduinoCore folder.
This will surely save me a lot of trouble someday when Arduino releases new cores with a new update, (and that day has already come with 1.0.1 and Leonardo USB!)
 and I just have to replace the core files, instead of having to sort out which ones are core files and which ones are libraries.

Variant 2: In a folder

So in the same place where I have my "ArduinoCore" folder, I create a "Libraries" folder, and I paste EEPROM.h and EEPROM.cpp there.

Where you create that folder is up to you; you can create it inside the ArduinoCore folder, you can create a separate folder for every library, put it in another place on your computer, inside your project folder.... all of those variants are up to you!

Step 3: Include the path in your project

Go to the properties of your project.
I still have the "Arduino Tutorial" from Part 2 open, so right click on that in the Solution Explorer panel and select "Properties".

TOOLCHAIN --> AVR/GNU C Compiler --> Directories
Click the "Add Item" icon, uncheck "relative path", and browse to the folder where the .cpp and .h files are.

Do the exact same thing for the AVR/GNU C++ Compiler --> Directories

Save the parameters, and now go to your code (ArduinoTutorial.cpp).

Step 4: Modify the code

The following code is based on the Arduino EEPROM Read example retro-compatible with the Arduino 1.0 core version. They modified the example for Arduino 1.0.1 and Leonardo.

#define F_CPU 16000000
#define ARDUINO 100
#include "Arduino.h"
#include "EEPROM.cpp"

void setup();
void loop();

// start reading from the first byte (address 0) of the EEPROM
int address = 0;
byte value;

void setup()
{
  // initialize serial and wait for port to open:
  Serial.begin(9600);
  EEPROM.write(5, 120);
 
}

void loop()
{
  // read a byte from the current address of the EEPROM
  value = EEPROM.read(address);
 
  Serial.print(address);
  Serial.print("t");
  Serial.print(value, DEC);
  Serial.println();
 
  // advance to the next address of the EEPROM
  address = address + 1;
 
  // there are only 512 bytes of EEPROM, from 0 to 511, so if we're
  // on address 512, wrap around to address 0
  if (address == 512)
    address = 0;
    
  delay(500);
}

Notice that the include is for the ".cpp".
For any other library, you can figure out which one(s) you have to include by opening the .h and .c/.cpp files.

EEPROM.h:
#include
EEPROM.cpp:
#include
#include "Arduino.h"
#include "EEPROM.h"

So all you need to include for this one, is "EEPROM.cpp", as it will itself include "EEPROM.h".

Important note: This will normally be like that everytime, you'll have to include the cpp as it is how .h and .cpp are organized. But I don't know every custom library in the world, and it might happen that a library only contains a ".h" and you'll have in this case to include the ".h".
Some libraries will be in C and not in C++, and so you'll have to include the library ".c" instead of the ".cpp" With that said, you should be able to figure it out, just by checking your library files!

Build the code, upload it to your board, open and connect the Terminal Window, and that should be it!
Notice that in the "setup()" I set the 5th EEPROM slot value to 120 to check if it was working fine, and it is!

If you have any trouble, don't hesitate to ask questions on our dedicated forum thread!