CARVIEW |
The playground is a publicly-editable wiki about Arduino.
Related Hardware and Initiatives
- create an account
- suggestions
- formatting suggestions
- all recent changes
- PmWiki
- WikiSandBox training
- Basic Editing
- Cookbook (addons)
- Documentation Index)
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.
Installation
Install the software
Eclipse and additionnal plugins
- Eclipse IDE for C/C++ Developers: https://www.eclipse.org/downloads You can also just add the C Developpement Toolkit to an existing installation. This tutorial have been tested successfully with Europa 3.3.2 Winter
- AVR Plugins for Eclipse. Except if you encounter problems with it, go for 2.2 beta 1, not 2.1.
- Target Management Project This is optionnal, it is used to monitor the serial board directly within Eclipse for debugging purposes.
GNU AVR-GCC toolchain
- Mac OS X with Fink
fink install avr-libc avr-gcc avr-binutils avrdude
- Mac OS X with MacPorts
- Building from source on Mac OS X: installing dev tools on os X
- Easy installer with CrossPack for AVR Development
- For Debian/Ubuntu, install:
apt-get install avrdude binutils-avr gcc-avr avr-libc gdb-avr
- For Windows, follow the instructions for WinAVR: Programming AVR with Eclipse and WinAVR
Install the Part Description Files
- Get the folder Partdescriptionfiles from Atmel AVR Studio
Configure Eclipse and the AVR Plugin
- Open the Eclipse preferences
- Find "AVR" and open those preferences
- Fill in the things that were not automatically found
- Point it to the Partdescriptionfiles you copied previously
- On Mac OS X/Fink, you will need to point to locations in /sw
- On Mac OS X/MacPorts, you will need to point to locations in /opt
- On common *n*x, everything should be under /usr/local/. bin/ for binaries, etc/ for avrdude.conf
Creating an "Arduino Library" project
Note you can harmlessly skip this step, as long as you have all the files somewhere in your hard drive. I've chosen to do it this way because I often "carry my Eclipse around", so I found it a good way to be sure all these files are always under my hand
Create a new C/C++ project and copy the following files into it :
From your Arduino installation, the following files located on /hardware/cores/arduino :
* HardwareSerial.h * WProgram.h * wiring.h * WConstants.h * binary.h * pins_arduino.h * wiring_private.h
From any Arduino project, get the core.a file in the applet subdir and add it, too. I personnaly renamed it to decimilia_core.a to prevent mistaking and allow handling of multiple Arduino boards. Note you can also build this everytime, but this may be a bit longer and is mostly useless, except if you're planning to hack into it, which is outside the scope of this document ^_^
You're not going to even have to build this project, it's just the library for your future Arduino projects. And about this, let's go for :
Your first Arduino project
- Go to File -> New -> Project...
- Open the C++ folder, and select C++ Project...'
- click Next
- select AVR Cross Target Application
Go to your project's preference and set them as the following :
AVR/Target Hardware : For Decimila, Atmel168 with a MCU Clock frequency of 16000000
C++ Build/Settings/Additionnal tools in toolchain : Check Generate hex for flash memory, Print Size and AVRDude.
C++ Build/Settings/AVR C++ Compiler/Optimization : Optimize for size (-Os) (same for the assembler)
C++ Build/Settings/AVR C++ Compiler/Directories : Add the folder of the previously created ARduino Library to the list of include dirs
On Assembler and Compiler, you might also want to disable debugging symbols
AVR C++ Linker, change the command line pattern to :
${COMMAND} --cref -s -Os ${OUTPUT_FLAG}${OUTPUT_PREFIX}${OUTPUT} ${INPUTS} -lm ${FLAGS}
And the "Command" to avr-gcc instead of avr-g++ (may be already be the default if you're making a C project instead of a C++ one)
(Yes, this is a lousy hack, but it will make much small executables. But it will work with default settings as well if you don't want to change this.)
AVR C++ Linker/Objects : Add the core.a file you've imported and maybe renamed from the Arduino library.
A couple more things to do...
[Added by Andrew Davison - still in progress...]
Before this is all going to work as you'd like it to, you will need another little tool.
The arduino environment issues a reset command prior to uploading, which is really convenient (my arduino is locked into a case, to it's even more convenient then!). Unfortunately avrdude doesn't do the same (although it would have to be pretty easy to make it do that... hint hint anyone listenning? :) )
Anyway, to overcome this I've written a small app that toggles the DTR line on the virtual serial port. That will reset the board prior to uploading the new sketch.
Here is the app:
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
You should now find that your application will upload without you needing to hit the reset button.
Writing code
You must #include "WProgram.h"
No loop() and setup() here, only int main(void);
You must NEVER return from main(). I mean, you-MUST-NEVER-return-from-main. In human language, this could be translated by "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 always add a call to init(); as your first instructions. Not doing this will prevent any time-related functions to work.
So, your basic code will usually look like :
int main(void) {
init();
/* Add setup code here */
for (;;) {
/* write main loop here */
}
}
Note : You can also link against main.cxx which can be found in /hardware/cores/arduino as well. Using this you can go for the usual setup() and loop(). If you want to do it this way, just copy the file to your project or (untested) #include it.
Uploading to the Arduino
Configuring AVRDude (Only once)
Go back to your project settings, and go the AVR/AVRDude page. Create a new programmer setup.
For Decimia, 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 something like /dev/cu.usbserial*. Refer to the Arduino environnement.
Once you've configured the programmer, save it, then go to the "Advanced" tab and check "Disable device signature check"
Uploading
If you've checked "AVR DUde" in the Additionnal tool in toolchain panel of the C++ Build Settings, your program will get upload at each build. Else, you can just rightclick your project in the Explorer and choose "AVR/Upload Project to Device".
Serial port monitor
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/
TO-DO list
- Create an Arduino project template to avoid doing a complete config of each project.
- Find a workaround for the C++ Linker problem.
- Make this easier to read ^_^
- Add Windows-specific stuff, of which I don't know a thing.