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.
<p>Great instructable. Very well written and comprehensive. While setting up my Eclipse environment for AVR's I noticed a couple of things.</p><p>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.</p><p>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 -&gt; Source File menu eclipse does not add the file extension. You have to put in the full file name including the extension.</p><p>3) Build takes what is on disk and not what is in the editor. Click Save then clean then build.</p><p>4) The Build process automatically uploads the compiled .hex to your target device.</p>
<p>Great, thanks</p>
<p>Great guides. I still use sometimes when I try new distro. Thanks.</p>
<p>excellent </p>
<p>It says I'm missing avr/io.h and util/delay.h - where do I get those?</p>
<p>how to connect avr jtag clone in this eclipse</p>
<p>If you get an error in Windows 8.1 saying,</p><p>&quot;avr-gcc.exe &ndash; Application Error</p><p>The application was unable to start correctly (0xc0000142). Click OK to close the application.&quot;</p><p>Please visit the following site for remedy. It worked for me!</p><p>http://smallshire.org.uk/sufficientlysmall/?p=689&amp;preview=true</p>
<p>Excelent instructable, the answer to my free-style life.</p><p>I tried it in Fedora 20 so it's fully functional. yay!</p><p>Do you know how to make someting similar for PIC??</p>
<p>Phew! It may be an old 'instructable', but sure saved me a helluvalotta time!</p><p>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...)</p><p>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?' &quot;Why does avrdude work only about 10 times, before the 'AVR download button does nothing?&quot;<br>But that's an avrdude/eclipse issue for later....</p><p>Now at least I can get on and learn enough C++/ATxmega64A4U stuff to give my boss a finished project in a few months...</p><p>BR</p><p>Andy</p>
<p>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.</p>
I think its this link for OSX users: http://www.obdev.at/products/crosspack/index.html <br>can somebody confirm?
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. <br>the full story can be found here: https://sourceforge.net/p/avr-eclipse/discussion/664382/thread/465ba881/ <br>cheers, novski
Step 9 is lacking! Specifically is is lacking entering a port (-P argument) such as &quot;com9&quot;. <br>This Instructable lacks how to setup a programming hardware! <br> <br> <br> <br> <br>
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.<br> <br> 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.<br> <br> If this is the case you can use the drop down in eclipse to select the appropriate entry rather than &quot;arduino&quot; in step nine. You may also need different configuration values, depending on programmer hardware.
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. <br>Typing main.c file it is presented semantic errors for all registers and bit included in the blinky example. <br>I have used indigo and juno versions of eclipse . <br>I should like to have some comment from you. <br>Regards
I don't get the get the AVR cross target application project type. I have the pugin and winavr installed.
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;<br><br>Help&gt;Install new Software<br><br>Then select the AVR url in the &quot;work with&quot; 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).<br><br>If this doesn't help please can you let me know the version of Eclipse that you are using?<br><br>Thanks,<br>Andrew
I followed the directions implicitly including the beverage and biscuit. that was a nice touch..
If I understood it correctly, activating the &quot;Avrdude&quot; 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. <br> <br>Thanks for this great tutorial :)
Good point, <br> <br>Thanks for your input, <br>Drew
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.<br>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 &quot;Nothing to Build&quot; and it's not creating any Hex files. my code is this;<br><br>int main(void)<br>{<br> DDRB|= (1&lt; while (1) {<br> PORTB &amp;= ~(1&lt; delay_ms(250);<br> PORTB|= (1&lt; delay_ms(250);<br> }<br> return(0);<br>}<br><br>on a file called &quot;main&quot;, PLZ PLZ PLZ help me! I've searched through all the web and found nothing helpful. :)
Hi Emihackr97, Sorry to contradict you but you have some problems with your source code.<br> <br> <strong>Compile errors</strong><br> 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.<br> <br> <strong>Source</strong><br> <em>You need includes for avr/io and util/delay - you don't have these.</em><br> <br> The code logic is very broken, for example;<br> DDRB|= (1&lt; while (1) {<br> <br> will break - because you are assigning the result of a &quot;while&quot; to DDRB - but &quot;while&quot; 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.<br> <br> 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;<br> <div style="margin-left: 40.0px;"> <strong><em>#include &lt;avr/io.h&gt;<br> #include &lt;stdlib.h&gt;<br> #include &lt;util/delay.h&gt;<br> <br> /*<br> * the delay routine is limited to a maximum of 250 ms / clock<br> *<br> * This method will call delay 32 times per second,<br> * providing a one second interval on a 20Mhz clock<br> *<br> */<br> void delay (int seconds)<br> {<br> //count how many times we called delay<br> long i = 0;<br> <br> //while we still have time to wait<br> while (i &lt; ( seconds * 32 ) )<br> {<br> &nbsp; //wait<br> &nbsp; _delay_ms (250);<br> &nbsp; //increase the counter by one<br> &nbsp; i++;<br> }<br> }<br> <br> int main(void)<br> {<br> //while ( condition ) 0 means false, all other numbers are true<br> while (1)<br> {<br> &nbsp; /* set PORTB high */<br> &nbsp; PORTB = 255;<br> &nbsp; delay(1);<br> <br> <br> &nbsp; /* set PORTB low */<br> &nbsp; PORTB = 0;<br> &nbsp; delay(1);<br> }<br> <br> //we should not return from main<br> //because the AVR just keeps on executing the program<br> //if in doubt put a while loop at the end (we don't need it in this case)<br> <br> return(0);</em></strong></div> <div style="margin-left: 40.0px;"> <em><strong>}</strong></em></div> <br> <br> <br> <strong>Reminders</strong><br> There are a few &quot;gotcha&quot; type issues with eclipse;<br> <ul> <li> Remember to save your file before you build or eclipse will ignore your unsaved changes. <li> 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. <li> The build will &quot;fail&quot; 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;<br> <em><strong>avrdude: ser_open(): can't open device &quot;/dev/parport0&quot;: Permission denied<br> make: *** [avrdudedummy] Error 1</strong></em><br> 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 </ul> <strong>Summary</strong><br> Try the attached - you may have another problem with set up, but just come back here and we shall see what we can do.<br> <br> With regard to learning C and programming Micro controllers, there are many good resources on the web, such as <a href="https://www.mainframe.cx/~ckuethe/avr-c-tutorial/" rel="nofollow">https://www.mainframe.cx/~ckuethe/avr-c-tutorial/</a><br> <br> Regards,<br> A.<br> <br> <br> <br> <br> <br> <br>
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 &quot;lost&quot;. The fact of being able to use the same IDE I use for normal work helps greately!<br><br>Cool! :)
Is anybody interested in follow up instructables? Some Ideas that spring to mind are &quot;Version Control in Eclipse&quot; and &quot;Arduino Development in Eclipse&quot;.<br> <br> <br> Andy<br> <br> <br>
HI -<br><br> 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.<br><br> Thank you for any direction you can give me.<br><br> nav
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;<br> <br> If you want further info just on using AVR Libc your best bet is navigating to the documentation pages from the main page (<a href="http://www.nongnu.org/avr-libc/">http://www.nongnu.org/avr-libc/</a>).<br> <br> 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&nbsp; 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.<br> <br> 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.<br> <br> I think your best bet would be to start a forum topic in the answers section along the lines of &quot;How/why does this example AVR program work?&quot; 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.<br> <br> 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.<br> <br> Hope this was helpful,<br> Drew<br> <br> p.s. the AVR libc manual is<a href="http://www.nongnu.org/avr-libc/user-manual/index.html"> here</a> and the FAQ section has saved me more than once (available <a href="http://www.nongnu.org/avr-libc/user-manual/FAQ.html">here</a>). 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 <a href="https://www.instructables.com/tag/type-question/">this</a> link).<br> <br>
<br> <br>HI - <br> <br> (If you get two replies, I apologise. Explorer is acting up) <br> 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. <br> <br> RGRDS <br> <br> nav
I found that learning AVR consisted of a number of single &quot;gotcha&quot; type problems, you may or may not be aware of the following so I'll just write everything that comes to mind.<br> <br> <strong>Hardware </strong>- it's important to remember that when programming an AVR we are really dealing with very low level hardware operations.<br> <br> <strong>Set up </strong>- 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.<br> <br> <strong>Registers </strong>- 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 &quot;control registers&quot; 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.<br> <br> For example, if I want to light an LED on pin 7 I have to consult the datasheet and find the &quot;Register&quot; 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).<br> <br> <strong>Module on/off</strong> - 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).<br> <br> <strong>Libc </strong>- 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 &quot;PB5&quot; 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;<br> <br> <em>//Shift 1 n places to the left, then set that bit low<br> DDRB &amp;= ~(1&lt;&lt;PB5);</em><br> <br> 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).<br> <br> Hope this answers some questions,<br> Drew<br>
I don't know exactly what you mean, but take a look at this:<br>http://www.nongnu.org/avr-libc/user-manual/index.html<br><br>i found it when i looked for a comfortable way to convert a byte input received by Serial.read into an integer.<br>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).<br><br>On the site you will find the supported microcontrollers, library documentation, information about the toolchain, etc.<br><br>did that help?<br>
<br>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. <br> <br> RGRDS <br> <br> nav
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.
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 Coils How to get started with Eclipse and AVR Beer Tin Barometer 
Add instructable to: