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:
- Install the Arduino IDE. I'm using version 0017.
- 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.
- 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.
- 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:
- Create a folder c:\dev\eclipse to hold your workspace projects.
- Create a folder c:\dev\eclipse\arduino
- Create a folder c:\dev\eclipse\arduino\core and copy all the files from
the Arduino IDE install \hardware\cores\arduino folder to it.
- Create a folder c:\dev\eclipse\arduino\avr and copy all the file from the
Arduino IDE install \hardware\tools\avr folder to it.
- Create a folder c:\dev\eclipse\arduino\libraries.
- Create a folder c:\dev\eclipse\arduino\libraries\utility.
Get a few more files
- Open the Blink example sketch and compile (verify) it. Upload it to your
Arduino to make sure it all works.
- 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
- Also copy over all .o files from there to c:\dev\eclipse\arduino\core
- 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.
- 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.
- 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.
- Tired yet? Oh there's lots more to go.
Rename files
- 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.
- Go to c:\dev\eclipse\arduino\libraries and do the same renaming trick.
- Go to c:\dev\eclipse\arduino\libraries\utility and do the same renaming
trick.
Make an Eclipse Template Project
- Run Eclipse. File/New/C++ Project. Selected Empty Project under AVR
Cross Target Application
- Name the project MyCPPTemplate. You'll see that Eclipse has created a new
folder in the c:\dev\eclipse folder.
- Click Next and select ATmega328. Set frequency to 16000000. If you need to
change this later you can under Project / Properties / AVR / Target Hardware
- Click Finished.
- In the Eclipse project explorer pane select the project you created.
- Open a file explorer window to the side of the Eclipse window. Navigate to
c:\dev\eclipse\arduino.
- 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.
- Select the folder icon for c:\dev\eclipse\arduino\core and drag-drop it on
MyCPPTemplate.
- Select the folder icon for c:\dev\eclipse\arduino\libraries and drag-drop
it on MYCPPTemplate.
Edit the Properties of your Template Project
- In the Eclipse project explorer pane, select your MyCPPTemplate project.
Navigate to Project / Properties.
- Make sure the top drop down box is on All Configurations.
- Select C/C++ build / Settings and do the long list of the following
- Additional Tools in Toolchain: Check Generate Hex for Flash Memory, and
Print Size. Uncheck the other options.
- AVR Assembler / Debugging: Set No Debugging Info
- AVR Compiler: I didn't do anything here. Maybe I'll have to come back to
this later
- AVR C++ Compiler: Change the Command to avr-g++.
- 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.
- AVR C++ Compiler / Debugging: Set No Debugging Info
- AVR C++ Compiler / Optimization: Set Size Optimization.
- 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}
- 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.
- 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.
- Click Apply and OK.
- Almost done, hang in there.
Go to Window / Preferences
- AVR / AVRDude: Check Use Custom Config File for AVRDude. Browse to
c:\dev\exlipse\arduino\avr\etc\avrdude.conf.
- 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.
- 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.
- Click Apply and OK.
One more Template Update
- Go to your project / properties.
- Navigate to AVR / AVRDude. In the Programmer Configuration, select the
configuration you just created.
- Go to the Advanced tab and select Disable Device Signature Check
- Click Apply and OK.
Compile, Link, and GO!
- Right click on MyCPPTemplate. Add a New C file. Name the file main.cpp.
- Double click on the file main.cpp in the project explorer and the file
editor should appear.
- 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.
- Back in Eclipse, paste this text into your main.cpp file.
- At the top of your main.cpp file add the following:
#include
"WProgram.h"
extern "C" void __cxa_pure_virtual() {
cli();
for (;;);
};
- At the bottom of your main.cpp file add the following:
int
main(void) {
init();
setup();
for (;;) loop();
return 0;
}
- Click the Hammer icon and watch your code compile, then link. Any errors?
Oh, more on that later.
- On the top menu select AVR and Upload Project To Target Device. Did it
work?
- YAHOOOOOOOOOO. Discovering all that took me a month of Sundays (and
Saturdays too).
Your Second Project
- You want to avoid doing all that crap again, right? Ok, here's what I got
from Robert Carlsen's page.
- Select MyCPPTemplate project. Right click on it. Select Copy.
- Right click on the Project Explorer window and select paste.
- Eclipse will ask you for a new project name.
- 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)