Arduino Notes: Eclipse

 

 

Other Rants and Raves

 

Resources

First, this guy had the keys to the kingdom - Robert Carlsen. His site gave a very clear, step by step process to get a program to compile in the Eclipse workspace for the Arduino. I suggest that you go read his site and follow the directions there. Then you can come back and read more of what I've learned.

Second, the forums were very helpful. It's worth reading the Eclipse thread there. I posted a problem and got some help on my way to a solution.

Third, the Arduino site has a wiki that contains some info, but it's hard to read and not complete. I suggest you help the community by making that page better.

February 2010 -

I'm tired of that little IDE and I'm trying to move to Eclipse. The instructions on the Arduino site didn't work. After a month of wrestling with it - and it was a struggle - I got it to work today. I'm going to document everything here and then go try to edit the Arduino site wiki. My general approach is to install what I need to get it working, then move files around so that all the needed files are in my own directories. This way I can upgrade a component and not worry that a new version will stop me from working. Turns out this is a good idea since the latest version of WinAVR didn't completely work for me and I had to screw around a bit. At the very end I'll add some tips for troubleshooting problems that I found.

I should also add, that I might have taken a torturous route to get something to work. If you know Eclipse or Arduino and can give me a short cut, I'm happy to take the feedback - thanks in advance.

First, get the software installed:

  1. Install the Arduino IDE. I'm using version 0017.
  2. Download Eclipse and install it. I'm using Eclipse 20090920-1017. I installed into c:\eclipse\.  If it asks you for a default workspace reply c:\dev\eclipse.
  3. AVR 2.3.1 : Unzip the download and put it in c:\eclipse\avr.  Now move the three files named de.innot.avr... from c:\eclipse\avr\plugins to c:\eclipse\plugins. Start Eclipse and you'll see an AVR logo on the workspace toolbar.
  4. WinAVR : I installed it and used the defaults. It ended up in c:\winavr-20100110\

Now create your own space to hold all the files you'll need:

  1. Create a folder c:\dev\eclipse to hold your workspace projects.
  2. Create a folder c:\dev\eclipse\arduino
  3. Create a folder c:\dev\eclipse\arduino\core and copy all the files from the Arduino IDE install \hardware\cores\arduino folder to it.
  4. Create a folder c:\dev\eclipse\arduino\avr and copy all the file from the Arduino IDE install \hardware\tools\avr folder to it.
  5. Create a folder c:\dev\eclipse\arduino\libraries.
  6. Create a folder c:\dev\eclipse\arduino\libraries\utility.

Get a few more files

  1. Open the Blink example sketch and compile (verify) it. Upload it to your Arduino to make sure it all works.
  2. Go to the Blink Arduino sketch folder and look for the applet sub-folder. Copy the core.a file from there into c:\dev\eclipse\arduino. Rename it LibDuemilanove_core.a
  3. Also copy over all .o files from there to c:\dev\eclipse\arduino\core
  4. If you want to use other libraries in your projects, like Servo or String, then include them in your blink Arduino sketch and compile it again.
  5. Go to c:\dev\eclipse\arduino\libraries and copy the .h and .c and .cpp and .o files for the libraries you want to use from your Arduino IDE install \hardware\libraries folder. For instance, for the String library you have to copy WString.cpp and WString.h. If there is a WString.o, then copy it too. If any of the library folders have a sub-folder called utility then copy the .h .c .cpp and .o files to the folder c:\dev\eclipse\arduino\libraries\utility.
  6. Go to the Arduino sketch folder for the Blink example you just compiled. In the applet sub-folder you'll see a sub-folder for each of the libraries. Go into each and copy the .o file to c:\dev\eclipse\arduino\libraries. You may find that some of these have another sub-folder in them. For example the EEPROM folder has a sub-folder \applet\EEPROM\utility. If so, then copy any .o files into the folder c:\dev\eclipse\arduino\libraries\utility.
  7. Tired yet? Oh there's lots more to go.

Rename files

  1. Go to c:\dev\eclipse\arduino and rename all the .o files to be of the form Lib<name>.so. For instance, if you have a file there named WString.cpp.o you should rename it LibWString.so.
  2. Go to c:\dev\eclipse\arduino\libraries and do the same renaming trick.
  3. Go to c:\dev\eclipse\arduino\libraries\utility and do the same renaming trick.

Make an Eclipse Template Project

  1. Run Eclipse. File/New/C++ Project.  Selected Empty Project under AVR Cross Target Application
  2. Name the project MyCPPTemplate. You'll see that Eclipse has created a new folder in the c:\dev\eclipse folder.
  3. Click Next and select ATmega328. Set frequency to 16000000. If you need to change this later you can under Project / Properties / AVR / Target Hardware
  4. Click Finished.
  5. In the Eclipse project explorer pane select the project you created.
  6. Open a file explorer window to the side of the Eclipse window. Navigate to c:\dev\eclipse\arduino.
  7. Select c:\dev\eclipse\arduino\LibDuemilanove_core.a and drag-drop it on MyCPPTemplate in Eclipse. You'll see that Eclipse has copied this file into c:\dev\eclipse\MyCPPTemplate for you. Cool. You might be tempted to copy these files via the file system - don't do it! When you drag-drop onto the Eclipse IDE it keeps track of these files.
  8. Select the folder icon for c:\dev\eclipse\arduino\core and drag-drop it on MyCPPTemplate.
  9. Select the folder icon for c:\dev\eclipse\arduino\libraries and drag-drop it on MYCPPTemplate.

Edit the Properties of your Template Project

  1. In the Eclipse project explorer pane, select your MyCPPTemplate project. Navigate to Project / Properties.
  2. Make sure the top drop down box is on All Configurations.
  3. Select C/C++ build / Settings and do the long list of the following
  4. Additional Tools in Toolchain: Check Generate Hex for Flash Memory, and Print Size. Uncheck the other options.
  5. AVR Assembler / Debugging: Set No Debugging Info
  6. AVR Compiler: I didn't do anything here. Maybe I'll have to come back to this later
  7. AVR C++ Compiler: Change the Command to avr-g++.
  8. AVR C++ Compiler / Directories: Click to add an Include path. Select Workspace, then MyCPPTemplate. Click ok. Do the same to add the sub folders of Core and Libraries. When you are done you should have three lines in the Include Paths box.
  9. AVR C++ Compiler / Debugging: Set No Debugging Info
  10. AVR C++ Compiler / Optimization: Set Size Optimization.
  11. AVR Linker: Change the Command to avr-g++. Change the command line pattern to
        ${COMMAND} --cref -s -Os ${OUTPUT_FLAG}${OUTPUT_PREFIX}${OUTPUT} ${INPUTS} -lm ${FLAGS}
  12. AVR Linker / Libraries: In the Libraries Path click to add a path. Select Workspace, then MyCPPTemplate. Click ok. Do the same to add Core and Libraries and Libraries\Utility. When you are done you should have four lines in the Libraries Path box.
  13. AVR Linker / Libraries: In the Libraries box click to add a library. Add Duemilanove_core. Note that even though the file is named LibDuemilanove_core.a, you just add the middle part. If you are using other libraries you must do this for each library. For example, add Servo and EEPROM. Again, note that there is no "Lib" or ".so" on these.
  14. Click Apply and OK.
  15. Almost done, hang in there.

Go to Window / Preferences

  1. AVR / AVRDude: Check Use Custom Config File for AVRDude. Browse to c:\dev\exlipse\arduino\avr\etc\avrdude.conf.
  2. AVR / AVRDude: Programmer Configurations, click to Add. Name it whatever your current hardware is named. Then if you get a different Arduino you can come here and create a new config. Mine is Duemilanove. I selected Atmel STK500 Version 1.x Firmware. Override default port should be \\.\COM4 (Of course if Windows gave your Arduino a different port when you plugged it into the USB then you should put that number in this field.) Override default baud rate to 57600. I left everything else at default.
  3. AVR / Paths: Set as follows -
    AVR-GCC to c:\dev\eclipse\arduino\avr\bin
    GNU Make to c:\dev\eclipse\arduino\avr\utils\bin
    AVR Header Files to c:\dev\eclipse\arduino\avr\avr\include
    AVRDude to c:\dev\eclipse\arduino\avr\bin
    Atmel Part Description Files on my system is blank.
  4. Click Apply and OK.

One more Template Update

  1. Go to your project / properties.
  2. Navigate to AVR / AVRDude. In the Programmer Configuration, select the configuration you just created.
  3. Go to the Advanced tab and select Disable Device Signature Check
  4. Click Apply and OK.

Compile, Link, and GO!

  1. Right click on MyCPPTemplate. Add a New C file. Name the file main.cpp.
  2. Double click on the file main.cpp in the project explorer and the file editor should appear.
  3. In the Windows file explorer, find the source code file of your Blink sketch. It should be a .pde file. Open it in Notepad. Select all the text and copy.
  4. Back in Eclipse, paste this text into your main.cpp file.
  5. At the top of your main.cpp file add the following:
     #include "WProgram.h"
     extern "C" void __cxa_pure_virtual() {
        cli();
        for (;;);
      };
  6. At the bottom of your main.cpp file add the following:
     int main(void) {
        init();
        setup();
        for (;;) loop();
        return 0;
     }
  7. Click the Hammer icon and watch your code compile, then link. Any errors? Oh, more on that later.
  8. On the top menu select AVR and Upload Project To Target Device. Did it work?
  9. YAHOOOOOOOOOO. Discovering all that took me a month of Sundays (and Saturdays too).

Your Second Project

  1. You want to avoid doing all that crap again, right? Ok, here's what I got from Robert Carlsen's page.
  2. Select MyCPPTemplate project. Right click on it. Select Copy.
  3. Right click on the Project Explorer window and select paste.
  4. Eclipse will ask you for a new project name.
  5. Bang, all those config steps are now replicated in the new project. Swell.

 

I've moved the troubleshooting info to another page.


       

 


Jim Schrempp is a sometimes freelance writer (only Vanity Press will publish his work) living in Saratoga, California. His writings have appeared on numerous pages on his own web site. The opinions expressed in this piece are those of the writer and do not necessarily represent those of anyone else (although Jim wishes more people shared his opinions)