Programming the Arduino with Eclipse on Linux

This is the first of a series of three posts. The ultimate goal is to setup a communication interface between an Arduino Uno/Mega board and an Android tablet over USB. Everything will be as user-friendly as possible, i.e. no root will be required on your Android tablet. The following posts Arduino USB transfers and Android USB Host + Arduino: How to communicate without rooting your Android Tablet or Phone conclude the series.

The Arduino Uno is a popular and affordable hardware platform which comes with its own IDE and core libraries for programming. If you like the Arduino IDE you may skip this post, however, if you feel more comfortable developing in Eclipse this might help you out.
We are using Ubuntu 11.10 (oneiric ocelot) and Eclipse 3.6.1 (helios), although this should not play an important role (as it turns out, Eclipse Indigo might need a few tweaks, check the end of this post). Also, setting up Eclipse for programming the Arduino Uno Atmega328P is pretty straightforward. Nevertheless, here is a quick how-to for the Arduino Uno (Arduino Mega 2560 below):

  1. Install avrdude and AVR libraries:
    sudo apt-get install gcc-avr avr-libc avrdude
  2. Start Eclipse and install CDT Plugin (C/C++ Development Tools):
    • Help -> Install New Software…
    • Work with: (your current Eclipse version)
      i.e. “Helios – http://download.eclipse.org/releases/helios”
    • Download the “pending” software package (don’t worry, download starts automatically 😉 )
    • Choose “Programming Languages” and select “C/C++ Development Tools”
    • Accept and continue by restarting Eclipse
  3. Install AVR Eclipse Plugin:
    • Help -> Install New Software…
    • Add new repository: http://avr-eclipse.sourceforge.net/updatesite/
    • Re-download the “pending” software package, download will be faster since it is probably cached 😀
    • Download AVR Eclipse Plugin and restart Eclipse
  4. Create new C project named “BlinkBlink”:
    • Project Type AVR Cross Target Application (Empty Project, AVR-GCC Toolchain)
    • Click next…
    • Untick “Debug” (in Debug mode, no hex-files are generated and avrdude can’t flash the device)
    • Click Advanced settings…
    • AVR -> AVRDude -> Programmer configuration…
    • Create a new programmer and name it “Arduino Uno”. Make sure this newly created programmer configuration is selected for the current project.
      • Programmer Hardware: Arduino
      • Override default port: /dev/ttyACM0 or similar
      • Override default baudrate: 115200
    • AVR -> Target Hardware:
      • MCU Type: ATmega328P (or load from MCU)
      • MCU Clock Frequency: 16000000 (default external clock source of Arduino Uno)
  5. Click Apply and OK to leave the properties window and click Finish to create the new project in the workspace.
  6. Create a new source file main.c and copy the contents from this link. Make sure to save main.c before proceeding (File -> Save).
  7. Project -> Build Project
  8. Click on the AVR Button within Eclipse to upload the generated hex file from BlinkBlink/Release/BlinkBlink.hex.
    Your Arduino Uno’s LED should be blinking on and off repeatedly. If somehow it doesn’t work, right-click your Project and select Properties. Make sure all AVR and Programmer settings are active as mentioned above.

For the Arduino Mega 2560 you should choose Atmel STK500 Version 2.x firmware as Programmer Hardware, and ATMega2560 as target hardware, the rest is the same as with the Arduino Uno. Also, if you are using the above source file for testing, you should change the definition of LED from PB5 to PB7, since the LED on the Arduino Mega is on Pin7 of Port B.

Update: if you are using Eclipse Indigo, some specific AVR symbols such as DDRB (data direction register of port b) may not be recognized.
To solve this problem go to preferences…

  • C/C++
  • Language Mappings
  • Add the following mappings:
    • Content Type: C Header File / Language: GNU C
    • Content Type: C Source File / Language: GNU C
  • Make sure to click on Apply afterwards… also you may need to restart eclipse after adding the mappings

Your Language Mapping preference window should look like the following screenshot:

If it still does not work, also try adding this line at the beginning of your main.c source file:
#include <avr/iom128.h>

17 Replies to “Programming the Arduino with Eclipse on Linux”

  1. Hello Manuel,
    I am working on a project about the IEEE802.15.4/ZigBee. The ultimate goal is to setup a communication interface between the ZigBee wireless board and an Android phone application over USB. The preloaded firmware on the CC2531 chip on ZigBee board presents itself as an USB Communication Device Class (CDC). From your article I want to write my own USB soft driver using the USB Host API,but I am not know if the ZigBee board can work with the Android phone. How the Android phone enumerate the ZigBee board?Should I write the ZigBee kernel driver?
    Do you think this approach is OK?If donn’t,please give me some suggestions. Thank you for this blog post – it was very helpful already!

    Thanks,
    Zlon

  2. Problems occurred building the selected resources.
    Errors running builder ‘CDT Builder’ on project ‘blank’.

    java.lang.NullPointerException

    java.lang.NullPointerException

  3. I use ubuntu11.10 and Eclipse 3.6.1 ,but I find this problem, please tell me where is problem? thanks

    1. Hello there,
      Well it is always hard to find out exactly what the problem is when you are not right in front of the computer 🙂
      Still, what I would try, make sure you close all other projects. Also, be sure to name your new project.
      In the error it said “on project blank”.. so maybe there is another project opened at that time?
      Furthermore, go to Help -> Check for updates.
      Good luck

  4. thank to answer my questions! I have build the hex document, I download in the AVR mcu,but when i insert the device in the computer,there is no device found in the ubuntu11.10, that is why

    1. Hi Dum,

      Well, as this tutorial is for Ubuntu, there is not much more to it, open a terminal (Ctrl+Alt+T) and then paste or type in the commands from step 1, you will need administrator rights or a password respectively.

      This will install avrdude, the avr libraries and the avr cross compiler.

      Hope this helps
      Andreas

  5. I have a problem in AVRDude Programmer. I am using Mega 2560 and I set the above values. I placed COM3 in serial port cause that’s what it says in the Device Manager and 115200 for baud. It did not work. Still getting errors like the port is blocked and make sure the port is open. I tried to change the baud to 9600 cause it’s the baud shown on Device Manager but still nothing happened.

    Any suggestions?

  6. Awesome writeup! Got this working in ubuntu 13.04, eclipse 3.8.1 – with the exception that I had to restart eclipse after adding the Language Mappings.

  7. Thanks Andreas, got this working on Ubuntu 14.04 and Eclipse 3.8.1 without a problem thanks to your guide. This page should replace the Arduino direction, it is so much better.

    Great job!

    1. Hi Bowdog,
      Thanks a lot for your positive feedback! Glad to know this still works with Ubuntu 14.04 🙂

      cheers
      andreas

Leave a Reply

Your email address will not be published. Required fields are marked *


*