Configure Eclipse to work with Arduino Uno

Preamble


I have oil heating at home. To measure the oil level in the tank, an antediluvian sensor with an arrow and a float on the rope is used. The principle of operation of the sensor is striking in its inaccuracy. But since we live in the distant future, in relation to my childhood, I wanted to make a sensor that fulfills the following conditions:
  • The sensor must be digital.
  • His testimony should be preserved for further processing.
  • Data should be available to me always and everywhere.
  • The whole device should be cheaper than 200 €.
With this specification, I began to search for suitable components. The choice fell pretty quickly on the Arduino platform. Iron itself suited me completely, but the development environment was just awful. Therefore, it was decided to switch to Eclipse.

It was possible, of course, to switch to the beloved Visual Studio, but at the moment I am rediscovering Linux for myself, so the Windows is not available.

Today, I want to share with you about how to configure Eclipse to work with Arduino Uno under Ubuntu 10.10.

What we need


Software
  • PC with Ubuntu 10.10 installed
  • Eclipse IDE, I used version 3.5.2
  • C Development Toolkit, I used version 6.0.2
  • AVR Plugins for Eclipse, I used version 2.3.4
  • GNU AVR-GCC toolchain
  • Arduino IDE, I used version 0022
Iron
  • Arduino uno
  • USB cable for connecting Arduino to a computer
  • Free USB port on the computer.

Software installation

1.1 We install Eclipse, for this we go to the Ubuntu Software Center, enter the word “Eclipse” in the search, in the Eclipse line click the “Install” button. Alternatively, you can write in the terminal: 1.2 Install the C Development Toolkit. To do this, open Eclipse, go to the Help menu, then click on “Install New Software ...”. A window opens. In the “Work with” field, select the “Galileo Update Site” page. In the search field, insert the line "Eclipse C / C ++ Development Tools" Put a checkmark in the cancer to the left of the search result, ie opposite the line "Eclipse C / C ++ Development Tools" and click Next, then again Next, Accept, Finish. After this super-combo, the installation of CDT will begin. After installation, restart Eclipse. 1.3


sudo apt-get install eclipse-platform











Install AVR Plugins. Open the “Install New Software” window, click on the “Add ...” button, to enter the address where to get the plugin. Enter “AVR plugins for Eclipse” in the Name field, and enter in the “Location” field:
http://avr-eclipse.sourceforge.net/updatesite/
and click OK. We mark the line “AVR Eclipse Plugin” and perform the combo from step 1.2. Close Eclipse.

1.4 Installation of the GNU AVR-GCC toolchain is performed from the terminal. To do this, insert the line in the terminal: Press Enter and wait a bit.
sudo apt-get install avrdude binutils-avr gcc-avr avr-libc gdb-avr


Configure Eclipse

After installing all the necessary plugins for Eclipse, we need to configure AVRDude. To do this, go to Eclipse, in the settings menu ( Window → Prefrences ).

We write in the search bar "AVRDude" press Enter and see the next window. click the “Add” button and add a new configuration for the programmer. To do this, in the window that opens, change the name and description of the configuration (for order). Select Arduino in the "Programmer Hardware (-c)" list. In the field “Override default baudrate (-b)” we select the value 115200 and in the field “Override default port (-P)” should be set the value / dev / ttyACM0 (The port to which the Arduino is connected may differ from mine. You can see the port value in Arduino IDE). Click OK. Then again OK.









Creating a project for Arduino

For the first project we will have to adjust the project with pens. Therefore, I recommend creating this project as a “base” project for Arduino, and then copying it as needed.

2.1 In Eclipse, go to the menu ( File → New → Project ... ), select “C Project” and click Next.

2.2 We name the child, in my case ArduinoUno and select the type of project, we should have “ AVR Cross Target Application “. Click Finish.

2.3 Select our project in the “Project Explorer” window and go to change the project settings ( Project → Properties ). In the left pane of the window that opens, we find the AVR tab, expand it.

2.4 Click on AVRDude, select the configuration of the programmer (we created it earlier).

2.5 We connect Arduino to a computer using a USB cable. Make sure Arduino is turned on.

2.6 Left click on Target Hardware. On the right we see the “Load from MCU” button, click it. MCU Type and frequency should change to suit your microcontroller. We check the type with the inscription on the crystal, if it matches, good. If it is not possible to automatically recognize the controller, we smoke a description of the hardware and set the values ​​with your hands. In the case of Uno, the type is recognized as an ATmega328P and a frequency of 16 MHz.

2.7 Close the Properties window by clicking on OK.

Create a library for Arduino Uno

For each project with Arduino, we need a kernel library. There are several ways to get it, the fastest is to pull it out of the original Arduino development environment. What will we do now.

3.1 Starting Arduino IDE

3.2 Select our hardware ( Tools → Board → ... ) In this example, select Arduino Uno.

3.3 Download any sample code, for example Blink ( File → Examples → Basics → Blink ).

3.4 Click on the Verify

3.5 button. Now we go to the folder where the library we need lies. You need to look for it in the folder /tmp/buildXXXXXXXX.tmp/ where XXXXXXXXX is a bunch of numbers. If there are several such folders, erase all directories and goto 3.4

3.6Rename the file core.a to libArduinoUnoCore.a

3.7 Drag and drop the file into our Eclipse project and drop it there.

Customize build

Now it remains only to make a few settings for a successful build and you're done.

4.1 In Eclipse, press Alt + Enter and get into the project settings.

4.2 Go to the C / C ++ branch ( Build → Settings ). In the Tool Settings tab, select the Additional Tools in Toolchain item and check the boxes
  • Generate HEX file for Flash memory
  • Print size
  • AVRDude
4.3 Uncheck the item Generate Extended Listing. It turns out like this: 4.4 Go to the AVR Compiler tab, click on it and change the value of the Command field from “avr-gcc” to “avr-g ++”. 4.5 Next, go to the AVR Compiler → Directories branch , add the path where you can find the header files to our libArduinoUnoCore.a. The path we need lies in the folder with the Arduino IDE. I have ... / arduino-0022 / hardware / arduino / cores / arduino / (replace the ellipsis with your path to the IDE). This is the path we indicate to the compiler. 4.5 Next, go to the AVR Compiler → Debugging branch , set the Generate Debugging Info value to No debugging Info. 4.6 Go to the AVR Compiler → Optimization branch








, set the Optimization Level value to Size Optimizations (-Os)

4.7 In the AVR Assembler → Debugging branch , set the Generate Debugging Info value to No debugging Info.

4.8 In the AVR C Linker → General branch, in the Other Arguments field, write “--cref -Wl, -gc-sections”. This should reduce the HEX file by a factor of four.

4.9 And the final touches in AVR C Linker → Libraries :
  • Add the ArduinoUnoCore library to Libraries (-l)
  • Add the path to the Libraries Path (-L), in this project " $ {workspace_loc: / ArduinoUno} "
it turns out like this:


Create main.c

Well, we got to the cherished main file. As we remember from the Arduino IDE, there we need to create two functions and everything works (setup and loop). In our project we need to write more code and I suggest just creating a new file in the project with the name main.c (File → New → Source File). And paste the following code into it:
/ *
* main.c
*
* Created on: 01/12/2011
*
* Basic main file for the Arduino Project.
* /
#include "WProgram.h"
// Global variables
int g_LedPin = 13; // LED on digital pin 13
void setup ()
{
  // opens serial port, sets data rate to 9600 bps
  Serial.begin (9600);
  // sets the pin as output
  pinMode (g_LedPin, OUTPUT);
  Serial.println ("********************");
  Serial.println ("* hello world *");
  Serial.println ("********************");
}
void loop ()
{
  digitalWrite (g_LedPin, HIGH); // set the LED on
  delay (1000); // wait for a second
  digitalWrite (g_LedPin, LOW); // set the LED off
  delay (1000); // wait for a second
}
extern “C” void __cxa_pure_virtual ()
{
  while (1);
}
int main (void)
{
  init ();
  setup ();
  // endless loop
  for (;;)
  {
     loop ();
  }
  return 0;
}

Having inserted the code, we only need to build our project. But I think that you can handle it yourself. And yet, in the proposed version, the HEX file size competes with the original development environment for Arduino.

Also popular now: