Introduction: How to Get Started With Eclipse and AVR

Picture of How to Get Started With Eclipse and AVR

Programming AVRs is fun, but sometimes the manufacturers development environments make code maintenance a chore. If your looking for a free, cross platform, high quality piece of software for programming AVRs Eclipse is a good choice.

Moving to an Integrated Development Environment (IDE), such as Eclipse is a logical step up from learning to program basic functions. By using an IDE you will be able to work easier and work with a range of tools inside the same program. you will be able to easily package and reuse your code and you will have access to advanced functions like refactoring and code analysis. For details on these benefits please have a quick skim over Step 12: Quick Tour of Cool Features.

In this instructable I will show you how to install and configure Eclipse to program AVR micro controllers (aka. Micro Controller Units or MCUs). I will also provide a quick run through uploading to your MCU and I will briefly cover some of the cool feature Eclipse has to offer.

Step 1: Why?

Eclipse is cool. Like, really cool. Compared to something like the Arduino programming software, the Eclipse IDE is the proverbial Swiss army knife.

For example, the Arduino development environment only lets you work in one file at a time. Also if you want to rename a variable you have to do a find/replace. If you want to take some code and wrap it in a method, you have to do it by hand. Eclipse can help with these otherwise tedious tasks and more. More generally speaking, moving to a fully featured IDE like eclipse is a step up from less full featured environments.

Note: Yes, Eclipse can be used to program the Arduino - however the set up for this is slightly more complex and the specifics of using Arduino in Eclipse will not be covered here.

Step 2: Preparation

If you are operating on an office computer (i.e. in your place of work) you need to get permission to install software on your machine. It would also be prudent to check that the corporate firewall does not block and (just type these addresses into the address bar or click the links, if you get a warning from your firewall then you don't have access to these sites).

If you are working from a home computer with an internet connection and your computer has USB ports your good to go.

To program AVR devices you will either need a programmer and your AVR (two separate units) or an AVR with a programmer on board, like the Arduino. If you don't have either yet, I would advise looking into the Arduino or similar to get started. If you are at the beginner stage I would point you towards googling "getting started with Arduino" and taking it from there. Moving on to Eclipse is very much for when you are more sure footed about AVR development.

Brew up a cup (or glass) of your favourite beverage and hopefully we will be done installing before it gets cold, warm or whatever temperature it shouldn't be...well, we should be done at least before it sprouts mould.

Step 3: Download and Install Eclipse

Picture of Download and Install Eclipse

Firstly we will need to download Eclipse itself. I recommend having a separate workspace and Eclipse version because the AVR plug in seems to corrupt both the Eclipse installation and the workspace over time (every now and again the installation inexplicably breaks, taking the workspace with it). So if you have eclipse already I would advise having a second copy on your computer and an 'AVR workspace' for AVR development so that any failures breakages are contained to AVR workspace. More on these issues later.

Go to the eclipse website and find the downloads page (at the time of writing this is here; The list of versions contains an entry titled "Eclipse IDE for C/C++ Developers", next to it there should be a one or more links. Click the "32 bit" option for the platform that you are running (for example click the 32 bit link next to "Windows:" if you are running a Windows machine). This should take you to the download page.

Near the top of the download page should be some text reading "Download eclipse-cpp-helios-linux-gtk.tar.gz from:" followed by a link titled ...Mirror Service...(http) or similar. Click the link and the download should begin.I will refrain from posting a link because Eclipse is updated fairly regularly, so you need to check this page to get the latest version.

Once downloaded, you need to extract the Eclipse program from the compressed file you downloaded. This step differs depending on operating system, but broadly, if you double click on the download an extractor program will open.  Extract the program to an appropriate place, for Windows users the Programs folder is acceptable. Open the eclipse folder that you just extracted and double click the eclipse executable. Eclipse will now start.

Note: It is a good idea to make a desktop short cut that runs the executable, to save time and effort later.

The start up screen will ask you where to find a workspace. If you do not know what this is leave this as it is and press OK. For the more experienced programmers, a word to the wise; Back-up your workspace either with version control or even just a local copy and avoid using an existing work space.

Step 4: Install AVR-GCC and AVR Dude

The AVR GCC toolchain is the compiler that is used to compile data suitable for AVR's. AVR-dude is a tool for putting that information onto your AVR (basically it communicates with the AVR via the physical programmer).

On a Windows machine simply go to the WinAVR site and follow the installation instructions. WinAVR(Help page here and download page here) has both of the above and a few extra bits to make things like debugging easier. Now go to the next step (the stuff below is for Linux users)!

On Linux it is necessary to install the packages required manually, however the effort involved is no that much different. Go to your Package Manager and install the following;

- gcc-avr
- binutils-avr
- gdb-avr
- avr-libc
- avrdude

Step 5: Note About the CDT Plugin

Some instructions you find online indicate that at this point you should install the C\C++ Development Tools (CDT) plug in. This is not necessary in this case because we have downloaded the C\C++ version of Eclipse, which already has it installed. So... no instructions here, go to the next step...Stop hanging round here...we have installing to do!

Step 6: Install AVR Plugin

Picture of Install AVR Plugin

The AVR plug in allows us to easily deal with AVR's from within Eclipse. Once installed it will allow you to build and deploy a C project to an AVR device. There are also neat features such as being able to pull up data on chips without having to refer to the data sheet.

To install the AVR plugin go to top menu in Eclipse, select Help>Install New Software. A new window titled Install will open. Near the top is a drop down box with "work with:" to it's left. Click the box and type then click add. In the pop up box that appears type AVR Eclipse Plugin into the "name" box.

In the box below an entry (CDT Optional Features) should appear after a short while. Select the check box directly to the left of this entry and click Next . The next screen asks if the selected new packages are correct. Press Next. The next page asks you to agree to the terms and conditions. Check the radio button next to 'I agree' and click Finish .

A progress bar will slowly fill up, indicating that eclipse is installing the plug-ins specified. If there are any security warnings just click OK or Continue. The security warnings just relate to the fact that the plugin is not authenticated, it's no big deal.

A pop up informing you that you need to restart eclipse will appear when the installation is complete. Select Restart Now. Eclipse will shut itself down and restart. When eclipse restarts it will ask you to select a workspace (either select your workspace if you want a different one to that suggested or if you don't know what this is just press OK). The AVR Plug in is now installed.

Now Eclipse has what it needs to talk to AVR's. Perhaps it's time for a celebratory post installation biscuit (or snack) to go with that beverage?

Step 7: Make a New Project

Picture of Make a New Project

Now we have Eclipse set up what we still need to do is; create a project to hold our settings and files, Set up the project, create a blinky light application, load to an AVR.

A note on projects for people from an Arduino IDE background (Skip to next paragraph if you know about projects already); Projects separate code out for each piece of work we want to do. For example If I wanted to create a flashy light to adorn my mantle I would make a FlashyLight Project to contain it. Equally if I wanted to make fading lights to spruce up my desk I would make a project called FadingLights. The key difference from single files (like a sketch - i.e. a source file) is that the project can contain a bunch of settings and also any number of source files.Roughly, a project is a special folder and source files are the files put into them. We tell the Project what platform we are targeting (for example the Attiny2313), how we want to program it, what data we want to put in it's EEPROM, what fuse bit's we want to burn, and so on.

To create a new project Click File>New>C Project type a name for your project, such as BlinkyLight. Make sure the Empty Project option under AVR Cross Target Application is selected and click next. Deselect the Debug option (we don't need it at this point) then click Finish. If instead of clicking Finish, you click Next there are a number of settings that you can set, but we will set them manually in a minute (we need to set some other settings too, so we shall do them all at once).

Step 8: Set Build Settings

Picture of Set Build Settings

Now you should have a project called whatever you named it in the Project Explorer tab. Now we want to set the settings for this project, so right click on the project and select Properties (right at the bottom).

Click on the plus [+] sign next to C\C++ Build and click Settings. In the window that appears select the following;
Generate Hex File for Flash Memory
Print Size
AVR Dude

Deselect the other two options (we don't really need them). Click Apply (its near the bottom right, you may have to scroll down).

Now we have told Eclipse that we want it to generate a HEX file (this will be flashed to the device, it is the "compiled" version of our code), we have told it to use AVR Dude to write to our AVR and we have told it to tell us how big the compiled program is (this is sometimes useful if space is an issue).

Step 9: Set AVR Target Settings

Picture of Set AVR Target Settings

Finally in setting up our project we need to tell Eclipse about the AVR we want to program and what we are programming it with. Select the plus [+] sign next to the AVR option to expand it. Select AVRDude. We don't have any configurations at this point so click New. Now select the programmer that you are using, if you are using an Arduino, it is on the list too. At the top of the page give a brief name and description, something such as "Arduino Programmer" "For programming a standard Arduino" would be fine - this is just so you know what it is for if you want to program using different devices from the same computer.

Note: You may need to specify a serial port if the defaut one doesn't work. First try these steps ignoring this note and then if it doesn't work retry and follow this note. The serial port can change (normally it's a fixed name with an incremental number like COM1). If you have multiple arduinos plugged in, or you have unplugged, replugged-in your arduino the number may have incremented. It can get confusing. The easiest method of finding the correct serial port name is to unplug all the arduinos except the one you want to program and then use the serial ports dropdown in the arduino software to find the name of the serial port. Once you have the serial port enter it into the appropriate box.

Click OK. Click Apply.

Now we will see whether our settings have worked - we will attempt to get the MCU to tell us what it is. Click the TargetHardware list item on the left of the screen. Make sure that your programmer is;
A) plugged in to the power(if necessary) and USB (or Serial).
B) turned on.
C) connected to your AVR target device.

Now click LoadFromMCU. If all has worked the device listed in the box should change to the device that is currently in your programmer. If it worked click Apply then click OK. If it didn't work, select the MCU from the list (it may be that your programmer does not support the Load From MCU feature) then click Apply and then click OK.

Your project is now set up and good to go.

Step 10: New Source File

Picture of New Source File
Creating source and header files is very easy. Simply right click on the project or project folder that you want your new file to be created within, and click New>Source File. In the window that appears look for the type of file that you want to create, type in a name for your new file and click Finish.

Please note that you Needa file called main.c somewhere in your project, this is because that is the file that the compiler starts with. The compiler will compile main.c and any source files included within it. For an simple example of what to put in main.c try using the source listing from this page (for attiny2313). I have used this example in the pictures on this step.

Now that you have finished the code we need to build it. What is build you ask? Building a project is the act of compiling all of the source code and creating a "compiled" result. For normal C programmers you would build an executable file (an EXE for windows users). Since we are putting data onto an AVR we are building a Flash image. Before you hit build you will not see any errors in your code. After hitting build you will see that some lines are underlined in red. These are called "Compile Errors" - these are bits of code that are incorrect, because the compiler cannot understand them or has a problem with them.

Note about source files (again for people from an Arduino IDE background): Now that we have moved on from a single source file it's time to get serious about organising our code. Doing so is not hard and it means that when you want to make your project do something else (like adding a button to your blinky light). In C, the language that we are now using, the way to make code is to organise it into groups of "utility" files. Say we want to know if a number is a prime, if a number is a Fibonacci number and if a number is a square. Now imagine that we want to use these new methods in both the Blinky Light project and the completely separate Fading Light project. If you wanted to do this in the Arduino IDE the only realistic way would to be copy and paste your methods (which is kind of hard work). Further more it kinda sucks because if I discover that my method isAFibonacciNumber actually has a bug, I have to copy and paste the fix to both projects. Wouldn't it be easier if you could write a function once and use it many times? Well you can, and it's easy... We use source files and header files. We might make a source file called NumberUtilities.c . Number Utilities would contain all of the number crunching methods we might want to use. Now if I want to use Number Utilities all I need to do is import it once. The great thing is that if I need to make a change, or a fix then I need only do so once. For more help with C and AVR you may want to hit google, an AVR forum or your library. Remember that there is a links section at the end of this instructable!.

Step 11: Build and Upload to AVR

Picture of Build and Upload to AVR

I assume you now have your project set up with at least a main.c file and some content in the main.c file. This step should be performed whenever you wish to build and/or flash your AVR device.

Next we need to build the project. What is this build of which you speak? It is the process of compiling the code. Effectively, turning the "source" code that we can (sort of) understand into binary machine code that the AVR can understand. Once we hit build the compiler will try to perform this task, sometimes however it will encounter problems in the source file. (An illustrative example is in the images attached to this step). In these situations the compiler will report an error (see the next step, "Compilation Errors" for help).

Click Project>Build All to build your project. After fixing any compilation errors click AVR>Upload Project To Target Device. The console tab should now fill up with green text describing the process that is taking place. If the upload process fails check that the device is definitely switched on and plugged in. If you are uploading to an Arduino, press the reset button just before you upload.

Your project should now be uploaded and on you device, plug it into a circuit and off you go! The bulk of the Instructable is now over. The remaining steps are informational (i.e. not instructional) and can be ignored if you are happy with the results you have got thus far.

If you want to make a new project after this point follow steps 6, 8 9 and 10. We can ignore step 7 because eclipse will remember the settings we applied the first time that we set the settings in step 7 and apply them to future projects. Remember when repeating step 8 that since we have already created a Programmer Configuration you can just select it in the Programmer Configuration drop down box instead of creating a new configuration like we did the first time round.

Step 12: Compilation Errors

Picture of Compilation Errors

What are compilation errors?
Compilation errors are errors that the compiler has detected during a build. A build is the process of taking all the written code and transforming (i.e. compiling) it to a single binary file that the AVR can understand. Compilation errors are only refreshed when you click Build and so after fixing a problem it is advisable to save and rebuild the project (If you don't eclipse gets confused).

Why do I get them?
Normally build errors are basic programming errors, for example look at the following code fragment;


Notice how the if has two closing brackets but only one opening bracket? This would result in a compilation error. This is because the syntax is wrong, fixing this example would just require deleting one of the two closing round brackets. Once fixed save and rebuild the project - the underlining should be gone. If this error existed in a program you were trying to build, the first line if(1)) would be underlined in red. This indicates that there is an error on the line indicated. To get more detailed messages look for the Errors tab close to the bottom of the page.

In the errors tab you will see that there are a number of columns telling you information about each error line by line. If you double click an error in this window Eclipse will automatically open the file in question and highlight the problem line.

How do I fix them?
Normally errors that the compiler finds are syntax related - this means that fixing the errors is a relatively easy matter; Simply work out which syntax rule you have transgressed and fix it. If you are unsure of the solution post your problem in a forum, either on instructables or a dedicated C programming forum. Please do not use the comments section of this page to find help for programming problems. 

For helpful sites please see the links section.

Are there other types of error?
Yes...If the program you have coded behaves unexpectedly while it is running then it is suffering from what is known as a "runtime error" - an error that occurs while the program is running. These types of error are often much harder to diagnose, there are advanced tools for resolving this type error, however the use of such tools is beyond the scope of this instructable.

Step 13: Quick Tour of Cool Features

There are a number of cool features that I would like to briefly draw your attention to. These features are In some way directly helpful of useful for every day programming.

Refactor Method, File
Top of the list is Refactor. The idea behind refactoring is simple, if I refactor a method, I change it's name. More specifically, I type in a new name and eclipse updates all the references to that method. So if I wanted to rename the method  oldMethodName() I would select it's declaration, right click, Refactor>Rename thentype a new name (say newMethodName()) and click OK. Then Eclipse goes away replaces every call to oldMethodName() to newMethodName(). This feature is a real time saver. Refactor can also be used to turn a section of code into a method, and a number of variations on that theme.

Custom Perspectives
As you are no doubt aware the eclipse window is full of tabs and panes, and many many buttons. If you are not happy with the way these are laid out then you can simply move tem around with drag and drop. You can close tabs that you don't think you will need, and add ones that you think you will. If you want to make Eclipse a little less complex one of the easiest ways is to reorganise the way the windows are presented, aka. "perspective". You can save the new reorganised window and indeed have as many of these perspecives as you want.

AVR views (supported devices and MCU inspector)
The AVR plugin also adds two new tabs, one which contains a compatibility list of AVR devices and one which allows you to explore the features of an AVR micro-controller. These two tabs are quite useful if you quickly need a bit of info on the chips but you don't need all the verbose content of the data sheet.

Minimise and maximise panels in eclipse with double click
Panels in eclipse can be made full screen by double clicking the pane tab (at the top), and the process reversed by double clicking it again. This means if you want to code full screen, or you want to see the full list of errors you need only double click.

C\C++ Perspectives (Specifically call hierarchy)
The built in C\C++ perspectives may be very useful in tracking down glitchy code and general bug. You are encouraged to explore the various perspective of eclipse, some of which are extremely useful.

There are far too many cool features for me to cover here. I would suggest that you explore the eclipse help files (Help>Help Contents) and the right click (aka. context- ) menus for projects, source files and lines of code. Specifically look at the Refactor and Source sections.

Step 14: Some Notes on Backing Up

Word to the wise: Eclipse has crashed on me many times before, taking my work with it. The typical failure mode of Eclipse with the AVR Plugin seems to be to break both the program and the work space. For this reason it is Highly advisable to;

-Keep a backup
-Use version control
-Maintain separate workspace for AVR stuff
-Use separate Eclipse for AVR stuff.
-Did I mention backups?

Step 15: Links

AVR Development Community -

AVR GCC tutorial -

AVR C programming without an IDE -

If you think any links should be added to this list please remember to either leave suggestions in the comments or PM me.


sanderdb01 (author)2017-10-04


amazing tutorial. I am renewing my instructable membership just so I can have a hardcopy of this.

Also another tip:

in the bottom left corner you should have a screen called "Make target" (View-show view-make target if you do not see it). If you then right click your project in the Make Target window, click new, and in the text input type "all" then OK (leave everything else as default), you will get a little label called "all" if you double click this, you will build and flash your project. It's a little shortcut.

grtyvr made it! (author)2017-02-27

Great instructable. Very well written and comprehensive. While setting up my Eclipse environment for AVR's I noticed a couple of things.

1) I am using a knock off USBasp programmer, and when I tried to detect the Target Hardware using the Load from MCU button it failed. This is not as bad as it might seem since if you know what MCU you have you can just select it from the list and it still works.

2) The file extension is important for the automated build. When you are naming a file, even if you are choosing a C source file from the New -> Source File menu eclipse does not add the file extension. You have to put in the full file name including the extension.

3) Build takes what is on disk and not what is in the editor. Click Save then clean then build.

4) The Build process automatically uploads the compiled .hex to your target device.

ZbyšekZ1 (author)2017-02-06

Great, thanks

Ashish0kushwaha (author)2016-12-17

Great guides. I still use sometimes when I try new distro. Thanks.

Abdelhamed1989 (author)2015-10-19


AntonR5 (author)2015-08-18

Tylerlee12 (author)2015-08-09

It says I'm missing avr/io.h and util/delay.h - where do I get those?

SriramD (author)2015-07-15

how to connect avr jtag clone in this eclipse

ashish28ranjan made it! (author)2015-04-03

If you get an error in Windows 8.1 saying,

"avr-gcc.exe – Application Error

The application was unable to start correctly (0xc0000142). Click OK to close the application."

Please visit the following site for remedy. It worked for me!

muhamd.magdy (author)2015-02-24


fgodines moreno made it! (author)2015-02-15

Excelent instructable, the answer to my free-style life.

I tried it in Fedora 20 so it's fully functional. yay!

Do you know how to make someting similar for PIC??

oululife (author)2014-12-09

Phew! It may be an old 'instructable', but sure saved me a helluvalotta time!

Trying to 'graduate' from Arduino IDE, I've tried - and rejected a few. Studio 6 (no Linux, needed at home), Code::Blocks (can't get it to pick up the xmega chip I'm using) and also AVR-Eclipse - (too complicated) until I stumbed on your article. Hooked a USBtinyISP Chinese clone to a pro Mini clone - and after a day of frustration, and a morning of 'Eureka!'s, I get it. Even on Windows 7 (Finnish edition...)

Thanks for takig the time to make this. Also for the 'comments' section where I found the last-but-one 'Gotcha!' - save always before build. (Last 'gotcha?' "Why does avrdude work only about 10 times, before the 'AVR download button does nothing?"
But that's an avrdude/eclipse issue for later....

Now at least I can get on and learn enough C++/ATxmega64A4U stuff to give my boss a finished project in a few months...



silas15 (author)2014-02-04

I have some question. I use CodeVisonAVR. There is wizard for ports define, setting timer etc. Is in Eclipse or AVR plugin something like this? This functionality would be very useful. I don't remember this code, because it is use once in project.

novski (author)2013-12-14

I think its this link for OSX users:
can somebody confirm?

novski (author)novski2013-12-18

i had a few issues with this package. Seams that the AVRplugin takes different paths then Crosspack installs to. I then installed MacPorts and installed it with Terminal. Its little bit more effort but then it works also with a Mac.
the full story can be found here:
cheers, novski

dirtyrocks (author)2013-06-27

Step 9 is lacking! Specifically is is lacking entering a port (-P argument) such as "com9".
This Instructable lacks how to setup a programming hardware!

andy (author)dirtyrocks2013-06-27

Thanks for the comments, I have updated Step 9. I've not had a problem with the default port before but maybe some folks have. Certainly if you need to unplug/plug a lot I have seen the port hang and the number increment.

If you were hoping for a tutorial on using a particular external programmer I'm afraid I cannot cover all the many variants of programmers out there. I'd recommend googling around for your particular model of AVR programmer - normally AVRDUDE is very good - it knows about many different programmer hardwares.

If this is the case you can use the drop down in eclipse to select the appropriate entry rather than "arduino" in step nine. You may also need different configuration values, depending on programmer hardware.

ffinacio (author)2013-01-21

When I am trying to install AVR plugins, instead to load CDT Optional Features and corresponding Plugins, it is only installed AVR Eclipse Plugin. AVR Eclipse Plugin Services is not available.
Typing main.c file it is presented semantic errors for all registers and bit included in the blinky example.
I have used indigo and juno versions of eclipse .
I should like to have some comment from you.

bassman76jazz (author)2012-11-20

I don't get the get the AVR cross target application project type. I have the pugin and winavr installed.

andy (author)bassman76jazz2012-11-20

Hmm, that's unexpected. What do you see listed in that view? I'd guess that perhaps the plugin did not install correctly. It half rings a bell with me - I may have had this issue before myself... If you go;

Help>Install new Software

Then select the AVR url in the "work with" drop down, you should see only avr plugins listed, are they all ticked? If so it might be a compatibility problem with the latest version of Eclipse (in which case I'd advise trying again with an older version of Eclipse).

If this doesn't help please can you let me know the version of Eclipse that you are using?


I followed the directions implicitly including the beverage and biscuit. that was a nice touch..

chypsylon (author)2012-04-16

If I understood it correctly, activating the "Avrdude" setting here activates an automatic download to the avr on each build. I would recommend against setting this on, as you'd always have to have your programmer plugged in and the AVR powered on when you compile it.

Thanks for this great tutorial :)

andy (author)chypsylon2012-04-17

Good point,

Thanks for your input,

Emiliano Valencia (author)2011-11-23

Hi, I have a really BIG problem, the thing will just not work. The code is right, all the settings are right, everything is installed, everything in ON and plugged in, etc.
but when I try to upload it, it tell me that the project has not been built, I have in auto Build, but even when I do this manually I get the samemessage. it shows no errors anf in the console it just says "Nothing to Build" and it's not creating any Hex files. my code is this;

int main(void)
DDRB|= (1< while (1) {
PORTB &= ~(1< delay_ms(250);
PORTB|= (1< delay_ms(250);

on a file called "main", PLZ PLZ PLZ help me! I've searched through all the web and found nothing helpful. :)

andy (author)Emiliano Valencia2011-11-24
Hi Emihackr97, Sorry to contradict you but you have some problems with your source code.

Compile errors
I think the reason why you can't see errors in the console from the build is related to how the build is done. What this does is it first compiles your project to hex, then immediately tries to deploy it. This erases the output of the build. I think theres a setting somewhere to change this, but try the following changes to the code first.

You need includes for avr/io and util/delay - you don't have these.

The code logic is very broken, for example;
DDRB|= (1< while (1) {

will break - because you are assigning the result of a "while" to DDRB - but "while" is a loop - it has no result. Furthermore, I can't see what your trying to do, but that's not how while works, and the brackets don't match - although if they did it would still not work.

I won't go through all the source, but I will provide a flashing light demo, which works on arduino. The following code is the entire contents of the main.c file;
#include <avr/io.h>
#include <stdlib.h>
#include <util/delay.h>

* the delay routine is limited to a maximum of 250 ms / clock
* This method will call delay 32 times per second,
* providing a one second interval on a 20Mhz clock
void delay (int seconds)
//count how many times we called delay
long i = 0;

//while we still have time to wait
while (i < ( seconds * 32 ) )
  _delay_ms (250);
  //increase the counter by one

int main(void)
//while ( condition ) 0 means false, all other numbers are true
while (1)
  /* set PORTB high */
  PORTB = 255;

  /* set PORTB low */
  PORTB = 0;

//we should not return from main
//because the AVR just keeps on executing the program
//if in doubt put a while loop at the end (we don't need it in this case)


There are a few "gotcha" type issues with eclipse;
  • Remember to save your file before you build or eclipse will ignore your unsaved changes.
  • Do not use spaces in your project name, if it has them, right click the project and rename it (you can replace the spaces with underscores). This causes an .elf error similar to what you describe.
  • The build will "fail" if you use the debug build target when your device is not plugged in. This is because debug will try to immediately upload to the AVR after a build.If you see something like;
    avrdude: ser_open(): can't open device "/dev/parport0": Permission denied
    make: *** [avrdudedummy] Error 1

    Then the build went fine, it just couldn't find your device (in this case it's looking for the wrong port, it should be using /dev/ttyUSB0). You can upload the hex whenever you want. This problem doesn't occur on the Release build target as far as I know
Try the attached - you may have another problem with set up, but just come back here and we shall see what we can do.

With regard to learning C and programming Micro controllers, there are many good resources on the web, such as


quasipedia (author)2011-05-06

Just wishing to drop a line saying that this tutorial is really cool. I have developed for a few months with Arduino, and when I switched to AVR I felt a bit "lost". The fact of being able to use the same IDE I use for normal work helps greately!

Cool! :)

andy (author)2010-09-02

Is anybody interested in follow up instructables? Some Ideas that spring to mind are "Version Control in Eclipse" and "Arduino Development in Eclipse".


nvradeli (author)andy2010-09-19

HI -

I am new to the AVR and starting out with an Arduino. I would like to expand beyond the Arduino environment, and have downloaded the datasheet and a couple of AVR tool sets onto my MAC. However, they don't seem to have much documentation included (I guess they assume everyone already knows the system from somewhere else). I'm fairly comfortable with C programming but not the AVR specific stuff. Can you suggest a good book/manual (hard cover or e-) that goes over the AVR libraries so I can understand how use them? I have started collecting example code to try learning that way but that leaves many questions.

Thank you for any direction you can give me.


andy (author)nvradeli2010-09-20

First thing to realise is that if your using the AVR Libc library then a lot of the tedious work is done for you. What AVR libc does is that it wraps up all the information that you would otherwise have to look up in the data sheet (i.e. the actual memory addresses of variables). So if you want to set all of the pins high you would simply say PORTB = 0xFF;

If you want further info just on using AVR Libc your best bet is navigating to the documentation pages from the main page (

Personally I learnt by getting hold of a cheap programmer (a USBTinyISP) and a ATTiny2313 and getting a blinky light example to work. From there I tried more involved  things such as serial connections, shift registers, etc. This is my preferred approach - get a working example, (perhaps in the form of a kit) and then research more complex methods. that way you are kept interested and get results fairly quickly.

If you prefer a book I can't say that I'm in a particularly good position to advise you on a good choice as I didn't really use books to learn myself (preferring online info). If your new to electronics a bit of knowledge about circuits would be very helpful, however if your using a kit this probably won't be necessary.

I think your best bet would be to start a forum topic in the answers section along the lines of "How/why does this example AVR program work?" followed by the example that you don't understand and possibly a brief description of what you are using (which AVR chip, which programmer, etc) and what you don't understand. I think discussing the examples in this context would be quite helpful.

If you post a forum topic feel free to PM me and I will try to help out, I'm fairly new to C and AVR programming (having said that I have some fairly cool things constructed already) but I'm fairly sure I'd be able to break down a code example if necessary.

Hope this was helpful,

p.s. the AVR libc manual is here and the FAQ section has saved me more than once (available here). The Answers section of instructables can be found by clicking the Answers link right at the top of this page, next to the instructables logo (of follow this link).

chaotick (author)andy2010-10-01

HI -

(If you get two replies, I apologise. Explorer is acting up)
See, I didn't even know ports are just read/written as variables. Cool. Thing is, I've been programming for a while but never cross-compiling or working with microcontrollers, so I don't really know enough to know what to ask. Thanks to your links, I now have an actual complete program, with #includes and all, to study. (so many articles out there only give you the 'interesting part' of the code, and assume you know what went around it). I'm going to try to build a program again this weekend. Thank you for your patience with me, and the good information.



andy (author)chaotick2010-10-02

I found that learning AVR consisted of a number of single "gotcha" type problems, you may or may not be aware of the following so I'll just write everything that comes to mind.

Hardware - it's important to remember that when programming an AVR we are really dealing with very low level hardware operations.

Set up - When outputting a value we first tell the micro controller (MCU) exactly which pins are inputs and which are outputs. Then we tell the pins what value to have. When we do this we are manipulating physically disparate parts(modules) of the MCU - there is (in the chip) a physical difference between portA and portB. The Pulse Width Modulation (PWM) module is an actual module, as are the Comparitors, the Arithmatic Logic Unit (AMU) and so on.

Registers - Following from the previous point, we need a way of controlling all these components. Since we are dealing with actual hardware modules the way this is done is as follows - these modules (e.g. PWM, comparitor, portA controller etc) have some control variable - the value of which defines the behavior of the module. These "control registers" are hardwired to a particular address, so what Libc does (among other things) is gives you pointers to those fixed addresses for a given chip (different chips may or may not have different addresses for the same module - this is because different chips use different modules - the attiny45 does not have a UART module but the attiny2313 does have one, for example). Microcontrollers are all actually a number of pre-fabricated components stuck into one package.

For example, if I want to light an LED on pin 7 I have to consult the datasheet and find the "Register" to which pin 7 belongs (there are various diagrams and tables near the start of the document that tell me this) lets assume it is PORTA - bit 5. Then I jump to the section that tells me how to use PORTA. Finally in my C editor I for example set DDRB bit 5 to low (or whatever the datasheet indicates) to set pin 7 to outpout and then I tell the port that its value is by setting bit 5 of the PORTA register. (AVR chips have common modules - once you can use the port's on one AVR chances are that the technique is the same for a different AVR chip - as previously stated, microcontrollers are actually a number of pre-fabricated components stuck into one package).

Module on/off - Just to cement the previous points, when you turn on a module, say PWM, the power consumption for the chip will increase because the previously un-powered PWM module is now active (equally turning it off will reduce power consumption).

Libc - Libc gives you a lot of help with registers. If you tell Libc what chip you are targeting it will give you all of the definitions from the datasheet (if the datasheet defines bit 5 of a specific register as being called "PB5" then libc will simply make a definition of #define PB5 5). So if the datasheet says clear bit PB5 of the DDRB register to make pin 7 an output, in C you could write;

//Shift 1 n places to the left, then set that bit low
DDRB &= ~(1<<PB5);

And our hypothetical pin is an output. Note that this is hypothetical, this may or may not actually set pin 7 as output, again, it's best to consult the data sheet. Please see the attached image for a print screen of the attiny2313 data sheet highlighting the section relevant to input and output (I/O -Ports).

Hope this answers some questions,

Mr Earl (author)nvradeli2010-09-23

I don't know exactly what you mean, but take a look at this:

i found it when i looked for a comfortable way to convert a byte input received by into an integer.
There's no documented function in the Arduino libraries. However there is access to the standard libraries of avr (a subset of the C standard libraries) which contain the stdlib.h library (among other things) that provides an atoi function (ASCII to integer).

On the site you will find the supported microcontrollers, library documentation, information about the toolchain, etc.

did that help?

chaotick (author)Mr Earl2010-09-24

This is big help, thank you. I can handle C-code and its regular libraries fine, but it's hard to program interrupts, or even toggle a port pin, when you don't know the name of the library to #include, let alone what's in it. This should get me moving forward again. I really appreciate the direction.



Mr Earl (author)andy2010-09-03

Arduino Development in Eclipse sounds exciting for me as I am in fact programming with the arduino IDE at the moment. As I'm coding Java with Eclipse it would be a nice feature for me to have an one-for-all IDE. By the way: Great instructable.

andy (author)Mr Earl2010-09-03

No worries, I'll probably be able to hack it out in the next 5 days :) Andy

About This Instructable




Bio: Andrew is a software engineer by trade and prefers projects that are simple yet effective. Andrew's areas of interest include software systems that do ... More »
More by andy:Joule Thief With Motor CoilsHow to get started with Eclipse and AVRBeer Tin Barometer
Add instructable to: