Arduino in Eclipse
This tutorial describes how to set up Eclipse for Arduino (AVR) C/C++ development. Eclipse is a full-featured Integrated Development Environment with modern editor features such as syntax highlighting, code completion and error checking. I became interested in using Eclipse for Arduino development as I’m often simultaneously developing firmware for the chip and visualization software in a Java / Processing applet. Since I’m already using Eclipse for Java / Processing, it’s nice to be able to work in the same environment for both.
The Arduino site has a decent walkthrough, but I found some of the steps to be confusing or outdated. Hopefully, this will get you up and running quickly.
Contents |
Overview
Most of this setup will have to happen once, then starting new projects is typically as easy as duplicating a simple, skeleton project. Getting the paths and configuration options correct for this initial project was the most confusing for me, but I haven’t needed to tinker with them again.
To begin, download Eclipse for C/C++ Developers, or install the C/C++ plugin for your existing Eclipse version (these instructions assume Eclipse 3.5 Galileo). To install an Eclipse plugin:
Select CDT from the drop down menu. If CDT is not present, then click the add button and paste the link to the plugin update site in the Location field: http://download.eclipse.org/tools/cdt/releases/galileo- Select Eclipse C/C++ Development Tools, then click “Next >” and “Finish” on the following screen. This may prompt you to restart Eclipse, however select No so we can install the next plugin.
- Return to the Install New Software dialog. Paste in the location for the AVR Plugin and select it and click Next to install. You may have to agree to license terms. http://avr-eclipse.sourceforge.net/updatesite/
Setup Eclipse
After the plugins have been installed they need to be configured. Specifically, the paths to the AVR Tools need to be verified.
- Open the Eclipse Preferences: Eclipse > Preferences. Twirl down the AVR category and select “Paths”. Verify that the paths have located the correct AVR toolkit (CrossPack-AVE on OS X). You can edit these fields as necessary.
Select the AVRDude category. I’ve found that I need to add a Programmer configuration for each Arduino (or USB to Serial adapter) that I use. Please let me know if you can get a better solution working with wildcards.
- Give this configuration a descriptive name. I’m using “Arduino Diecimila”.
- Select “Arduino” as the Programmer Hardware
- Enter the correct port for your Arduino. You can display this by plugging the Arduino into the computer, opening the Terminal then typing: /dev/tty.usbserial then hitting the Tab key. The remainder of the port name should appear.
- Set the baud rate to 19200
- Click OK. Then close the preferences.
Create an Arduino project
For the first project you’ll need to manually set up the configuration. I’d *highly* recommend making a basic blink sketch, then duplicate it for each new project. This is what the tutorial will set up. Alternatively, you can try importing this basic project, but may have to set up the paths for your system anyway. Eclipse Blink Sketch
- Go to File -> New -> C Project
- Select Empty Project under AVR Cross Target Application and name the project “Hello_Blink”.
- Click Finish.
- Select the “Hello_Blink” project in the Project Explorer panel, then navigate to Project > Properties menu.
- Twirl down the AVR category and select AVRDude.
- Select your Arduino from the Programmer configuration menu
- Select Target Hardware at left.
- Ensure that your Arduino is plugged into your computer via USB (and is powered on).
- Click “Load from MCU”. This should query the Arduino for it’s type and detect it correctly.
- If this doesn’t work, typically the Diecimila is an ATmega168 while the Duemilanove is an ATmega328
Each Ardiuno project needs to include the Ardunio core library. This file is compiled automatically by the Arduino IDE. While you could compile it yourself in Eclipse, the easiest way to get it is to build a simple sketch in the Arduino IDE, then copy the “core.a” file into your Eclipse project.
Start the Arduino IDE- Open the Blink sketch (File > Examples > Digital > Blink)
- Click the “Verify” button to compile the sketch
- Select Sketch > Show Sketch Folder
- Drag core.a into your Eclipse Hello_Blink project to copy it in.
- Right-click on core.a, select Rename and change it to “libcore.a”
Now we set up the correct building settings:
- Twirl down C/C++ Build and select Settings
- Select “Additional Tools in Toolchain”
- Check the following:
- Generate HEX for Flash Memory
- Print Size
- AVRDude
- Uncheck Generate Extended Listing
- Select AVR Compiler
- Change the command from avr-gcc to avr-g++
Select AVR Compiler > Directories
- Add an Include Path to the header files within the Arduino.app bundle (look at the screenshot)
- You can right-click on Arduino.app and select Show Package Contents, then navigate to the Contents/Resources/Java/hardware/cores/arduino folder
- Select AVR Compiler > Debugging
- Set “Generate Debugging info” to “No debugging info”
- Select AVR Compiler
- Set the Optimization level to Size Optimizations
- Select AVR Assembler > Debugging
- Set “Generate Debugging info” to “No debugging info”
Select AVR C Linker > Libraries
- Add a library named “core”
- Add a library path. If libcore.a is in the Hello_Blink project folder, the path will be “${workspace_loc:/Hello_Blink}”
Add a new main.c source file
This file will contain your typical Arduino sketch code. There are additional bits of code that are typically added automatically by the Arduino IDE which need to be explicitly written in Eclipse. Feel free to copy the below code.
- Go to File > New… > C Source File. Name this file main.c
- Paste in the following for a basic blink sketch:
#include "WProgram.h"
// prototypes
void blink(int n, int d);
// variables
int ledPin = 13; // LED connected to digital pin 13
void setup(){
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
pinMode(ledPin, OUTPUT); // sets the digital pin as output
Serial.println("------------------");
Serial.println(" hello world");
Serial.println("------------------");
}
void loop(){
blink(3, 50); // blink led (n times, ms interval)
delay(1000); // wait 1 sec
}
void blink(int n, int d){
for (int i=0; i<n; i++) {
digitalWrite(ledPin, HIGH);
delay(d/2);
digitalWrite(ledPin, LOW);
delay(d/2);
}
}
int main(void)
{
init();
setup();
for (;;)
loop();
return 0;
}
Building
When you’re ready to build and upload to the Arduino, click the Hammer icon. This should compile your program and then run avrdude, which uploads to the Arduino.
New projects
Duplicating a project in Eclipse is as simple as selecting the source project in the Project Explorer panel, copying it (Edit > Copy) then paste. Eclipse will prompt you for a new name , then will create a new, duplicate project in the workspace.
If you keep the blink sketch intact, you should be able to duplicate it each time and avoid the above setup.
Follow up
You should be all set to work on Arduino projects in Eclipse. Note that Eclipse uses various “perspectives” for different modes and programming languages. Typically, you’ll be working in the C/C++ perspective while working on Arduino code. If you’d like to switch back to the Java perspective for working with Processing, select it from the perspectives at the upper right of the main window, or Navigate to Window > Open Perspective > Other…











December 11th, 2009 at 4:14
Hi, I’ve tried your tutorial and I must say, very well written. I seem to be getting much further than with the post on arduino.cc, but I still haven’t succeeded so far. It seems that something goes wrong with the stk500 programmer. Whenever I start arduino I can upload sketches without a problem. But when I use eclipse it can’t seem to connect (I get many timeouts). If I then start arduino again it cannot connect to the stk500 either. I have to do a restart to make it work again. Do you have any clues or can you check your settings for points that may be missing in the tutorial? Thanks in advance.
December 14th, 2009 at 22:59
Well, I can only guarantee that the settings described in the tutorial work for my system. Double-check the AVR device settings in eclipse. I’m not using a specific programmer, but either a SparkFun FTDI USB to Serial board or a Diecimila itself. I’ve selected “arduino” as the programmer within eclipse rather than stk500.
January 5th, 2010 at 19:55
Hi Robert,
Thanks for the write-up, which was much more accurate and pleasant to work with than the one found at Arduino.cc.
I’m very new to c & Arduino, so please read my comments under that light. I ran into a compilation error with the above example (with Print.cpp.o and ‘undefined reference to ‘__cxa_pure_virtual’) and found that if I comment out the ‘Serial.’ statements I was able to compile. Obviously, your code example works with the serial calls in Arduino 0017, if I remove the ‘main’ block first
.
I skimmed through again, but I don’t think I overlooked an explanation. I was curious how your Eclipse is set up to handle/views serial output.
January 5th, 2010 at 20:32
I ran into an issue similar to what “SeeYouDouble” had said, after looking at the Eclipse console, AVRDude responds that ‘arduino’ is not a valid programmer; I had forgot that Arduino.cc’s guide asked me to replace ‘avrdude.conf’ with the one supplied from Arduino’s own IDE (Arduino 0017, fyi). After reverting to WinAVR’s default ‘avrdude.conf’ and ‘avrdude.exe’, I was able to upload Arduino code via Eclipse.
January 5th, 2010 at 20:36
@Wes I recall having to make a small change for 0017. I’ll post the change when I get back to my computer next week.
Check my comment at the end: http://robertcarlsen.net/2009/02/28/using-arduino-in-xcode-532
January 6th, 2010 at 17:34
Robert,
Awesome — That works
.
I added ‘extern “C” void __cxa_pure_virtual() { while (1); }’ which skips the earlier compilation “errors”.
After I installed Eclipse plug-ins for Target Management & RXTX, and set the Eclipse view ‘Terminal’ for my serial, I can view the Arudino’s serial output. I just need to disconnect before invoking AVRDude
.
update-sites for TM & RXTX, respectively:
http://download.eclipse.org/dsdp/tm/updates/3.1/
http://rxtx.qbang.org/eclipse
January 6th, 2010 at 17:42
thanks for the mention of the target management plug-in. i’ve been using Cornflake as my serial terminal, or just running the serial port through screen. i’ll check out the plug-in, however.
January 24th, 2010 at 14:47
hi and thanks for this tutorial!!!
I’m on linuxMint and eclipse 3.5.1
so far everything worked as discribed, but I got stuck at the “setup eclipse-step” as I can see in your picture you changed the paths for AVRDude, AVR-GCC and GNU make to “usr/local/CrossPack……..”
I just followed your steps for installing CDT and AVR-plugin. further I’ve installed the mentioned AVR packages with “apt-get”, but can’t find the Crosspack location for configuring the path.
If you could give me a tip it would be great!
regards, jo
January 24th, 2010 at 17:01
CrossPack is for OS X. I haven’t tried to set up AVR+Eclipse on linux.
Where are your avr tools installed? (specifically, look for avrdude – try using “which avrdude” at a command line).
February 15th, 2010 at 22:22
You are a life saver. I’ve been wrestling with Eclipse and the Arduino for a month now. When I found your blog I immediately got your Hello_Blink to compile and link. What a big step forward!
Since then I’ve gotten my bigger project to compile and just today solved my AVRDude issue. When I saw my message “from the eclipse version” in my terminal window I knew the search was over.
I’m running on MSWindows so things were a little different for me, but not much.
Thanks again for an excellent post.
Best of luck to you,
Jim
February 25th, 2010 at 15:32
Excellent walkthrough, was a nearly effortless install of the required tools and the configuration was easy when following the guide. I’m glad I can now use Eclipse for programming the Arduino as I wasn’t too happy with the standard Arduino IDE.
In regards to the Target Management terminal I found that Putty was also very usefull for monitoring the serial output. I still have to try the Terminal in TM as when I installed the site hosting the RXTX install for Eclipse was not functioning.
February 26th, 2010 at 7:29
hi,
How i could use an external library in the main program? I mean, how do i should configure eclipse to use the s65display library?
thanks
February 26th, 2010 at 10:15
Try adding the libraries path to AVR Compiler/Directories and to AVR C Linker/Libraries in the Project Properties.
If you’ve installed the S65Display library with the others, the path is likely (in OS X): /Applications/Arduino.app/Contents/Resources/Java/hardware/libraries
Then include the library in main.c and see what happens! Let us know since I haven’t tried this yet…
March 17th, 2010 at 17:22
Excellent description, you ‘re a hero!
Robert, adding the Arduino Ethernet library does not seem to work the way you describe here, in my case.
Building is fine, but the AVR C Linker complains about about an undefined reference.
Any ideas?
March 29th, 2010 at 11:36
hi,
nice tutorial, compiles fine on ubuntu 9.10, … but I got a major size problem when doing it this way. After compilation my binaries are over 8000 bytes in size, the Arduino IDE results in about 2300.
It might be the problem but as I did not find a .a library in my arduino IDE I compiled it myself. By leaving out the Serial calls and changing global includes in Tone.cpp to local ones I could get the basic size (just one simple blink-delay loop) down to about 1300 bytes, but once the Serial commands were back in the binaries exceeded 8000 bytes in size. I would usually not care about that, but as there are only 14k available on my Diecimila and the almost empty project takes more than half of the memory its a problem. I compiled the same code in the Arduino IDE and it told me the generated file was about 2300 bytes … so whats goin on? Might it be that there is some other serial lib compiled in? Shouldn’t that be the same Wiring code in the core anyway?
cheers rob
April 18th, 2010 at 11:03
Sorry, my English isn´t so good.
This is a very good tutorial. I have a problem with the Arduino lippath. My path looks like so:
C:\arduino\hardware\arduino\cores.
Is this the right path?
Errormessage : G:\UserDaten\Willi\Documents\Programmierung\Arduino\workspace\Hello_Blink\libcore.a(Print.cpp.o):(.rodata._ZTV5Print+0×4): undefined reference to `__cxa_pure_virtual’
make: *** [Hello_Blink.elf] Error 1
Wes says:
I added ‘extern “C” void __cxa_pure_virtual() { while (1); }’ which skips the earlier compilation “errors”.
Where must I added this code?
Best regards from a newbie
April 18th, 2010 at 11:08
You add that somewhere in your main.cpp file. I’d put it near the top, just above the setup() method.
April 18th, 2010 at 11:31
Thank you Robert for the quickly anewer. But the error remains. Here my complete Code.
[/code] /* * main.c * * Created on: 18.04.2010 * Author: Willi */ #include "WProgram.h" // prototypes void blink(int n, int d); // variables int ledPin = 13; // LED connected to digital pin 13 extern "C" void __cxa_pure_virtual() { while(1); } void setup(){ Serial.begin(9600); // opens serial port, sets data rate to 9600 bps pinMode(ledPin, OUTPUT); // sets the digital pin as output Serial.println("------------------"); Serial.println(" hello world"); Serial.println("------------------"); } void loop(){ blink(3, 50); // blink led (n times, ms interval) delay(1000); // wait 1 sec } void blink(int n, int d){ for (int i=0; i<n; i++) { digitalWrite(ledPin, HIGH); delay(d/2); digitalWrite(ledPin, LOW); delay(d/2); } } int main(void) { init(); setup(); for (;;) loop(); return 0; } [code]it´s very fine, if can you hold my hand
Willi
April 30th, 2010 at 18:50
[...] Arduino in Eclipse [...]
May 31st, 2010 at 9:49
[...] set the baud rate to 57600, which seems to be necessary but other tutorials don’t mention. Robert Carleson’s tutorial almost works, but uses a C project. The playground page specifies a code size optimization, I [...]