Table of Contents

Development environment Eclipse (Windows) ATmega2561

This section contains the information necessary to install HomeLab version 5 (Microcontroller v1 - ATmega2561) development software and initial setup on Windows operating system.

Installation

For installation the HomeLab development software must be downloaded for your operating system. The software package contains Eclipse development environment, Eclipse AVR plugin, Robotic HomeLab library, HomeLab programming utilities and and example project.

MS Windows

Software download → Eclipse HomeLab package

Linux Ubuntu

Software download → Homelab-keyring

Linux other and Mac OS

The following software is required to be installed:

Creating new project

In order to write a program for the controller you need to create the new project. The project includes typically different files like source codes, header files, compiled program files, etc. It is strongly advised to create new folder for every project (which is offered also by the New Project Wizard.

The following steps have to be completed when creating new project with the help of wizard:

1. Start Eclipse (Robotic HomeLab IDE) and ja setup new project. If the software is newly installed, project repository Workspace must be created. To do this, select the Workspace folder location in main window where the repository will be created.

To create the new project, select in menu File - New - C project. Add project name and click Next.

2. Project configuration in the next dialog box should be selected as only Release.

3. In the next window, microcontroller type and working frequency must be selected. Robotic HomeLab (v5) microcontroller is ATmega2561 working frequency 14745600 Hz. To finish project setup click Finish.

4. After this the user interface for program development will open. Before you can start writing code, new file for source code is needed to create. To do this, click mouse right button on your fresh project, select New - Source File and input a name to it, which must be ended with “.c”. It is recommended to name the main file as “main.c”. After pressing Finish button, a new file is created and opened in development environment.

5. Before you start writing the source code, it is advisable to make some changes in preferences for easier use of development environment. Choose from menu Window - Preferences and navigate from leftside tree to General - Workspace and select option Save automatically before build

6. For testing the correct operation of Eclipse, the following source code can copied to environment and compiled. For compilation the keyboard combination of CTRL + B can be used.

//A simple test code which is not using HomeLab library
#include <avr/io.h>
 
int main(void)
{
	unsigned int x,y;
	// Set pin PB7 as output
	DDRB = 0x80;
 
	// Infinite loop
	while (1)
	{
		// Invert pin PB7
		PORTB ^= 0x80;
		y=3200;
		while(y--){ 
    			x=260;
    			while(x--){
    				asm volatile ("nop");
    			}
  		} 
	}
}

For successful compilation, the code is needed to be error free and the compilator must be able to find all necessary header files. A successful compilation is indicated in Problem window as emptiness (or at outermost cases some warnings Warning) and in Console window as the output of compilator which will for example be in this case:

AVR Memory Usage
----------------
Device: atmega2561
Program:     308 bytes (0.1% Full)
(.text + .data + .bootloader)
Data:          0 bytes (0.0% Full)
(.data + .bss + .noinit)
Finished building: sizedummy

If the code has errors or header files are not found, then the Console window displays the number of errors on end line and describes possible faults above it.

../main.c: In function 'main':
../main.c:23: error: expected ';' before 'while'
../main.c:13: warning: unused variable 'x'
make: *** [main.o] Error 1

Alsothe Problems window displays several error messages and corresponding location in code is marked with error icon.

7. For using HomeLab library, it is assumed to be correctly installed into operation system with the help of instruction. For every project the library must be included into list of linkable objects in project options. To do this, open at first: Project → Properties and then from leftside tree C/C++ Build → Settings, further Tool Settings → AVR C linker → Libraries. Choose in window that opened in the right under Libraries (-l) icon Add… and input to the dialog box “homelab2561”. Then OK and one more OK.

8. For testing HomeLab library the following source code can be used when copied besids the previous code and compiled. You can again use CTRL + B combination on keyboard.

//A simple test code which uses HomeLab library
#include <avr/io.h>
#include <homelab/delay.h>
 
int main(void)
{
	// Set pin PB7 as output
	DDRB = 0x80;
 
	// Infinite loop
	while (true)
	{
		// Invert pin PB7
		PORTB ^= 0x80;
		hw_delay_ms(500);
	}
}

If compilation of this code is also successful, the development environment was set up correctly.

 

Loading the code into microcontroller

1. Connect the microcontroller board to PC using USB cable. After successful connection a small green LED labeled as PWR will light up (after some time on first connection).

2. Set options for program loader (AVRDude). For this again open project properties Project → Properties and from leftside tree AVR → AVRDude, further Programmer configuration → New. The dialog box that now opens needs no changes and you can press OK button. If it is selected press Apply and then OK.

It is important to check that in list Programmer configuration something can be choosed and by default this will be: New Configuration.

3. If HomeLab microcontroller module is connected with PC, you can now try to load the compiled program into microcontroller. For this simply press AVR icon or use CTRL + ALT + U in keyboard.

As an effect of this program, the on-board LED (PB7) should start flashing. If the program works, you have successfully set up your programming environment and completed your first program. Congratulations!

Using floating-point variables

It is sometimes necessary in AVR programs to use floating-point variables. For calculating with them and presenting with printf-type functions, the following changes are necessary in the configuration of the project:

1. Open the configuration of the project from the menu File → Properties. On the leftside panel open AVR C Linker → Libraries, where in addition to HomeLab library other library objects must be included printf_flt and m (libprintf_flt.a ja libm.a).

2. Then open AVR C Linker → General and into box of Other Arguments add line -uvfprintf.

3. Press OK and close configuration window.