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.
There are four ways to get the Arduino core library: using a precompiled binary, getting an existing library 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.
Click here for a link to a precompiled core library (including header files). If this doesn't work, you will have to use one of the methods outlined below.
From any Arduino IDE project, get the core.a file in the applet subdir and add it, too. I personally renamed it to diecimilia_core.a to prevent mistaking it for a library for another Arduino core. To generate this file you will need to create and compile a project in the Arduino IDE.
Note: You must use the upload feature to get the applet directory (in which core.a is located) into your sketch folder. Clicking on 'verify' in the IDE will compile and remove the files in a temporary location.
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. But 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 (this author found this method more straightforward than using the Arduino IDE to generate the core library).
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) {
init();
/* Add setup code here */
for (;;) {
/* write main loop here */
}
}
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/