Eclipse is a free, powerful, and full-featured development environment that can be set up to work with AVR and Arduino. This page is very much a work-in-progress, please free to add to it or improve it.
If the automatic installation doesn't work, manually copy this "plugin" into the the Eclipse installation. Move the folder which begins with the name "de.innot.avreclipse" to the "dropins" folder located within the eclipse folder. Restart Eclipse if you have it already running.
There should now be a new "AVR" toolbar button in your workspace.
There are three ways to get the Arduino core library: getting an existing binary from an Arduino IDE project, compiling the library directly into your project, compiling your own library file.
The library source code is included in the Arduino IDE download, in the hardware/cores/arduino directory. At the very least, you will need the header files from that directory accessible to your Eclipse project:
* HardwareSerial.h * WProgram.h * wiring.h * WConstants.h * binary.h * pins_arduino.h * wiring_private.h
You will also need the .a static library.
This is the preferred method.
From any Arduino IDE project, get the core.a file in the compilation subdirectory. To generate this file you will need to create and verify a project in the Arduino IDE. It can be any program, such as the Blink program. Make sure that the correct target board is selected in the Arduino IDE.
The compilation subdirectory is a temporary folder. For example, in Windows 7, the object files might be stored in the following directory:
C:\Users\<username>\AppData\Local\Temp\buildXXXXXXXXXXXXXXXXXXXXX.tmp The X's in the build...tmp directory are a hash that map to the project whose temporary files are held in the directory. The temporary files are named after the project, so you can verify that you're copying the correct library.
Copy the core.a file into your own project directory, and rename it to libArduinoCore.a. You can call it anything, so long as it starts with "lib" and ends with ".a". It might be a good idea to name the file after its target, e.g. libArduinoMegaCore.a, so that you can always tell what the library's target architecture is.
You can copy the entire contents of the hardware/cores/arduino directory into your Eclipse project so that it is compiled into the application every time. This requires that you use C++ projects, and the projects will take a bit longer to compile. This generally isn't a very good idea unless you're hacking the core code.
You can compile your own static library in Eclipse.
You may need to add the following function when using the C++ headers:
extern "C" void __cxa_pure_virtual()
{
cli();
for (;;);
}
Add this function to your main application file (main.c). It may work in a header file as well.
The contents of the function can be any error handling code; this function will be called whenever a pure virtual function is called.
The Arduino environment issues a reset command prior to uploading. Newer versions of AVRDude (such as the one shipped with CrossPack) will also do this. If you have an older version and are using Windows, you can overcome this problem with this little app. Attach:newavrdude.exe
To use this, you need to:
1) rename the avrdude.exe that is currently being used by eclipse to "realavrdude.exe" 2) Make sure that in the eclipse configuration for avrdude, you specify the port override. This should add something like "-P//./COM7" and it needs to be argument #3 (if this causes a problem for anyone, let me know and I'll build in some configuration stuff). 3) copy newavrdude.exe into the same directory as realavrdude.exe, and rename it to avrdude.exe
When using the Arduino IDE, you just have to define setup() and loop() functions and the IDE already has a main functional defined in the core library that calls setup() and loop() functions.
Eclipse does not define the main() function for you. However, you can use Arduino's default main() function by copying the main.cxx file from the hardware/cores/arduino directory in the Arduino IDE package. You might have to rename this file to main.c for Eclipse to recognize it as a code file. Linking in main.cxx will allow you just to define the setup() and loop() functions like you would in the Arduino IDE.
You must #include "WProgram.h" in your application program to gain access to the Arduino API.
If you choose to define your own main function, you must NEVER return from main(). I mean, you-MUST-NEVER-return-from-main. In human language, this could be translated as "the main() function must contain some kind of endless loop, because if it ends, the Arduino won't stop the program but will just keep reading random data as code". You must also always add a call to init(); as your first instructions. Not doing this will prevent any time-related functions from working.
So, your basic code will usually look like :
int main(void) {
/* Must call init for arduino to work properly */
init();
/****************************/
/* Add your setup code here */
/****************************/
for (;;) {
/****************************/
/*** write main loop here ***/
/****************************/
} // end for
} // end main
Go back to your project settings, and go the AVR/AVRDude page. Create a new programmer configuration. You only need to do this once; for other Arduino projects, you can reuse this configuration.
For Diecimila, the programmer model is "ATMEL STK500 version 1.X firmware". Probably the same for other Arduino boards.
Enter the name of your serial port in the "Override default port" field. Usually this is something like "/dev/cu.usbserial*" in *NIX and something like "//./COM*" in Windows. Override the default baud rate to 19200 for Arduinos based on the ATmega168, or 57600 for Arduinos based on the ATmega328p.
On Windows, the FTDI virtual COM port driver doesn't register its COM port until the Arduino board is plugged in. With the board plugged into USB, check a terminal program or device manager to find out what COM port the FTDI driver is using for the Arduino. This COM port will usually be the same on a machine even if you reboot or unplug the Arduino, but might differ on different machines.
Once you've configured the programmer, save it, then go to the "Advanced" tab and check "Disable device signature check".
If you are using WinAVR-20090313 or earlier on Windows, then you will need to replace the default avrdude.exe and avrdude.conf in the WinAVR directory with the ones from the following directories in the Arduino IDE folder:
hardware\tools\avr\bin\avrdude.exe hardware\tools\avr\etc\avrdude.conf
If you've checked "AVR Dude" in the Additional tool in toolchain panel of the C/C++ Build Settings, your program will get upload at each build. Else, you can just right click your project in the Explorer and choose "AVR/Upload Project to Device" or click the AVR upload button.
If you have Target Management Project installed, just go to the Window menu / Show View / Other.. And choose Terminal/Terminal. Open it with a serial link and choose the serial port your Arduino is connected to. Notice you'll probably have to disconnect the terminal while uploading.
As the RXTX library is a troublemaker for many people, there is a workaround : Just start a SSH or Telnet (please be aware this may be a potential security leak) server on your computer and open it in the Eclipse terminal. Then, on any unix, just type :
cat /dev/your_serial_port/