Arduino sans IDE - a tutorial

colin's picture
Printer-friendly versionSend by email

For the GPS Disciplined Oscillator (GPSDO) project, an Arduino Mega 2560 with an Adafruit TFT Touch shield will be used to provide the user interface (to report one's geographical location, etc.). The Arduino platform makes this sort of prototyping and one-off design a breeze. However the Arduino IDE is not really up to the task, and particularly not if one employs good software development techniques: all source being controlled, an automated build system, etc. So here's a tutorial with notes for compiling and running software for the Arduino with Eclipse and the standard GNU GCC toolset.

Initially I used the step-by-step guide on the Code Project site as a reference: This guide is no longer 100% accurate given updates in software, then there were other things I needed to do and try, and thus this tutorial.

Build System Set-up

Firstly the build system set-up, which consisted of:

Arduino Core Library

Then the core Arduino library needs to be built. This consists of all the functionality that is present in-the-background when using the Arduino IDE. (In a similar style, the other Arduino libraries such as the SPI library can be built in a similar fashion.) The steps to create this core library are:

  1. Create a new AVR Cross Target Static Library type C++ project. The name I used for this library is arduino_core, resulting in the actual file name: libarduino_core.a. (Any other libraries would have similar file names: libarduino_spi.a.)
  2. Add all the source files from the Arduino software installation, which is: <arduino_dir>/hardware/arduino/cores/arduino
  3. Add an appropriate include path for the AVR Compiler for the project, via Project | Properties | C/C++ Build | Settings | AVR Compiler | Directories. It should read: "${workspace_loc:/${ProjName}}"
  4. Repeat for the AVR C++ Compiler for the project, via Project | Properties | C/C++ Build | Settings | AVR C++ Compiler | Directories. Again it should read: "${workspace_loc:/${ProjName}}"
  5. Select the target hardware platform via Project | Properties | AVR | Target Hardware. Given the target platform here is the Arduino Mega 2560, this should be MCU Type = ATmega2560 and MCU Clock Frequency = 16000000.
  6. Build the library. There will be some warning messages but these can be safely ignored.

A general note would be that Eclipse is set up to build both Debug and Release versions of a library/executable. Only the Release build will really be of any use, so the settings need to be set appropriately for the Release build. (Alternatively they can be set for both build types by selecting [All configurations] in the dropdown menu at the top of the Settings dialog.)

Blink Test Application

Before moving onto something more adventurous, a test of the build system by creating the equivalent of the Blink application included with the Arduino software.

The source for this application is different to that included with the Arduino software as we're now working at the coal face. The functiontality is still the same - to blink the LED on pin 13 - but the source code needs to contain a main() function, and no longer contains a setup() and loop() function. The source code looks like the following:

#include "Arduino.h"
const int LED_PIN = 13;      // LED pin.
const int INTERVAL = 1000;   // in milliseconds.
int main()
    pinMode( LED_PIN, OUTPUT );
    while( true )
        digitalWrite( LED_PIN, HIGH );
        delay( INTERVAL / 2 );
        digitalWrite( LED_PIN, LOW );
        delay( INTERVAL / 2 );
    return 0;

The steps to create this application are:

  1. Create a new AVR Cross Target Application type C++ project. The name I used for this application was of course blink.
  2. Add a new file main.cpp with code as above.
  3. Add the include path to the core library for the AVR Compiler for the project, via Project | Properties | C/C++ Build | Settings | AVR Compiler | Directories. It should read: "${workspace_loc:/arduino_core}"
  4. Set the optimisation flags for the AVR Compiler to only include code/data sections actually used, via Project | Properties | C/C++ Build | Settings | AVR Compiler | Optimization, in the Other Optimization Flags section add: -ffunction-sections -fdata-sections
  5. Repeat steps 3 and 4 for the AVR C++ Compiler, via Project | Properties | C/C++ Build | Settings | AVR C++ Compiler.
  6. Add the core library link details for the AVR C++ Linker for the project via Project | Properties | C/C++ Build | Settings | AVR C++ Linker | Libraries. This involves adding the library itself under the Libraries section:arduino_core, and the library path under the Libraries Path section: "${workspace_loc:/arduino_core/Release}"
  7. Also set the optimisation flags for the linker, via Project | Properties | C/C++ Build | Settings | AVR C++ Linker | General, in the Other Arguments section add: -Wl,--gc-sections
  8. Select the target hardware platform via Project | Properties | AVR | Target Hardware. Per above this needs to be for the Mega 2560, therefore MCU Type = ATmega2560 and MCU Clock Frequency = 16000000.
  9. Build the application. There should be no errors nor warnings.

Downloading and Running an Application

This is where things really started to diverge from the Code Project guide I mentioned above, and also the out-of-the-box operation of Eclipse. (The short story is that I couldn't get Eclipse to connect to the Arduino, the long story of course is what I tried and how I derived the solution, which I won't go into, but which I detail here.)

The easiest way to use the AVRDude downloader system (which both the Arduino and Eclipse software use) successfully appears to be to simply reuse the version which accompanies the Arduino software. The steps to do this are:

  1. Select the AVRDude configuration file that accompanies the Arduino software. Go to Window | Preferences | AVR | AVRDude, tick Use custom configuration file for AVRDude, then browse to and select the Arduino software version of the file at: <arduino_dir>/hardware/tools/avr/etc/avrdude.conf
  2. Add a programmer configuration (which is located in the same dialog) by pressing the Add button in the the Programmer Configuration section, then:
    i) Entering a configuration name, e.g., Arduino Mega 2560
    ii) Select
    the programmer hardware type: Wiring
    iii) Enter the serial (USB) port that the Arduino is connected to, for me this was: 
    iv) Select the communications speed: 115200
  3. Assign the programmer configuration to the application project: go to Project | Properties | AVR | AVRDude and select the programmer configuration just created from the dropdown list.
  4. Download the application in Eclipse by pressing the AVR button in the toolbar. The communication lights on the Arduino should flash fast (given the speed of 115200 baud rate) and then the D13 LED will flash at 1 Hz.

All good, and now a working method for creating and testing Arduino applications exists sans the Arduino IDE!

Next Steps

Something more adventurous beyond an LED blinking is of course the aim. This will be covered in the next installment of this tutorial where I will cover building and running the TFT Touch shield example application. Stay tuned...


Credit given where due: I also gained insight from the following sites/posts in trying to work out how to download software to the Arduino:

Continues: Arduino sans IDE - TFT Touch shield


Nice guide

nice and simple guide that worked. tried a few other guides without success before i came across yours.

i had a small problem uploading to the board using avrdude, got an error on line 332 of the avrdude config file

the fix was to replace the avrdude exe file from C:\WinAVR-20100110\bin
with the one from the arduino installation C:\Arduino\arduino-1.0.3\hardware\tools\avr\bin
i also did not have the "wiring" option in the programmer hardware type. i used "Atmel STK500 Version 2.x firmware" insted

again thx for a nice guide