• Build logs, Tutorials and Hacks

    Saturday, February 4, 2012

    Using Eclipse with Arduino on Windows: Method 1

    Arduino IDE project used library

    There is a segment at http://arduino.cc/playground/Code/Eclipse about how to use the arduino IDE project library. I am basically rewriting it like I did it.

    Step 1: Verify that you have downloaded the Arduino-0023

    In the Last tutorial we had bade sure that our downloaded core and files were in place and that eclipse IDE was configured and ready. I saved it at G:\arduino-0023 and will refer to that. This is the preferred method.

    Run the Arduino IDE and select File > Example > Basic > Blink as shown below.

    image

    This will bring up a window with a sample project ready. press the play button and it will compile. Now we find the core.a file. In windows explorer, navigate to C:\Users\Inderpreets\Appdata\Local\Temp where you replace Inderpreets with your windows username and search for core.a Copy this file to your Desktop and we will come back to it in a few minutes.

    Step 2: New Project in Eclipse

    Start Eclipse and select File > New > C++ Project Fill in the blanks as

    image

    In the next page, Deselect Debug and Press next. For arduino UNO select atmega328p as the processor and frequency of 16000000Hz.( 16 000 000 no spaces) SmileClick Finish.

    Now right click the Blinky01 project and select new source file. I usually use main.cpp as the file name. A new source file will pop up with a few lines of comment. Now for your program.

    First we include the WProgram.h file because that adds all necessary headers automatically. Copy the code below.

    /*
    * main.cpp
    *
    *  Created on: Jan 31, 2012
    *      Author: Inderpreets

    */

    #include <Wprogram.h>

    // This method is used for init of vars and stuff- run once
    void setup(){

        pinMode(13, OUTPUT);
    }

    //This run over and over again
    void loop(){

        digitalWrite(13, HIGH);   // set the LED on
          delay(500);              // wait for a second
          digitalWrite(13, LOW);    // set the LED off
          delay(100);              // wait for a second

    }

    int main(){

        // init must be called
        init();
        setup();

        for(;;){
            loop();
        } //end for
    }// end main

    Save.

    Step 3: Project Properties

    At this point the IDE will point out that a lot of file and references are missing… So we help it find them. Go to your desktop and copy the core.a file. In eclipse right click the blinky01 project and select paste.

    image

    Next, right click the blinky01 project and select properties.

    Go to C/C++ build > settings as shown

    image

    Go to AVR Compiler > Directories and click the add button. A pop up will ask for the directory paste this: "G:\arduino-0023\hardware\arduino\cores\arduino" with the quotes but replace path where applicable. Do the same with AVR C++ Compiler> Directories. image

    Now Select AVR C++ Linker and select Objects.

    image

    Add the object from the workspace as shown above.

    At this point you can pretty much click ok  ok and build and will be ok. However there are a few extras you should do for other projects like compiler flag settings etc which I will discuss in a different article…

    Right now the build should be ok by rightclicking the project and build project and should be error free… How to upload the code to the UNO is a simple matter and is again covered in a separate article.

    Cheers

    No comments:

    Post a Comment