Robot Recipe (Software)

Welcome to the software portion of the Robot Recipe.
I am using the Ubuntu 10.04 operating system on my notebook that I use for my coding machine. If you don't have Ubuntu and want it, you may get it from the Roseburg Community Computer Center . I highly recommend using this for your operating system for embedded programming, as windows is a lot trickier to access the ports on your computer for the micro-controller programmer. So that is the first step. I'll write more for the next step of setting up your software for this project.
Ok, since you have your notebook with a freshly clean install of Ubuntu 10, now lets add some things that you will need to do this project. This is the hard part, because I am going by memory here on how I did it. That's never a good thing! But, let's give it a go, shall we?
First you need to either be logged in as root, which is rarely recommended, you can do bad things to your operating system here if not careful, Or just type in your root password when prompted.
Go to Application, System Tools and launch the Kpackagekit. This will bring up a window to allow you to install all sorts of fun stuff. Try not to get side tracked here.
Now choose gcc-avr and install it. Do the same for avrdude, and avr-libc. The next step is flexable, but if you want to use what I use for avr IDE, go to . Then download and install the kontrollerlab program. It's free and it's really good for what it does. So, get all that done and then we can take the next step of actually writing a program and programming our Tiny2313 mcu. If you get stumped, or confused, or something doesn't quite work, you can email me in this blog, and I'll try to help you out. It will also give me a chance the clarify things here better so that others can follow along more easily.
Well, I hope you got all that done with out too much difficulty. There is one trick with the Kontroller Lab though. It does not have the AT Tiny2313 chip to select. The programmer foolishly left his email on the site, so I made use of it. This was Martin's reply:
Dear Dennis,

you can add an entry for that processor in the file


(At least on (K)Ubuntu, this is the location where that file is
installed. For other distros, the path might be different.)

The format of that xml file is quite self explanatory. So you should
face no problems with adding that CPU.

I followed his instructions explicitly, and it worked like a charm! Thanks Martin!
Next we need to configure Kontroller lab. I won't go into great detail, if you want that, you can search for Kontroller lab and read more there. Here is the nitty gritty:

1. Open the application. I put my shortcut in the Programming section of the Main Menu.
2. Go to the tool bar menu and click on the Debug option. Then select "Configur ICD".
3. Click on the Common Tab and click in the Box that says "Objdump Command"
Type in "avr-objdump" with out the quotes.
4. Click on the ICD-Monitor tab.
5. Click the down arrow for the "Port" selection box and choose /dev/tty50.
6. Baud Rate at 19200. Then click save.
That takes care of the first part, now for the really important part of the set up.

1. Click on project on the top tool bar of the program, then select configure programmer.
2.In the choose programmer, select the AVRDUDE radio button and type in the command box "avrdude" for the command.
3. Now click on the AVR Dude tab and check "specify programer type and select "usbtiny". (remember everything you type is with out the quotes)
4. Check the connection port and choose USB.
5. Click the "set as default" button, then OK

OH YES, I almost forgot, we need to configure the project. This is the last part, I promise.
1. Click on project and select, Configure Project.
2. On the common tab on the right side is CPU settings, drop down and select "ATTiny2312" (this is the one you added)
3. For clock you select 4,000,000 hz.
4. Type in your hex file name. Since we are going to use the blink program, type in "blink.hex". For the map file name type "". (I'll try to describe what these are later.
5. Click the compiler tab and type in the first box "avr-gcc".
6. Click on the linker tab and type in "avr-gcc" in the first box, then "avr-objcopy" in the second box.
7. Click on the assembler tab and type in "avr-gcc"
Now click save as default button and click ok.

Now we are done configuring. I'll let you catch up while I look up the blinker.c program for our first test program. I will walk you through it and try to make it as painless as possible. I think this is the end of the real boring stuff. It should get more fun from here. Stay tuned!


OK, here is the blink program I promised:
Copyright Spark Fun Electronics├»¿½ 2007
Nathan Seidle
nathan at


Example Blink
Toggles all IO pins at 1Hz


//Define functions
void ioinit(void); //Initializes IO
void delay_ms(uint16_t x); //General purpose delay

int main (void)
ioinit(); //Setup IO pins and defaults

PORTC = 0x0F;
PORTB = 0x0F;
PORTD = 0x0F;

PORTC = 0x00;
PORTB = 0x00;
PORTD = 0x00;


void ioinit (void)
//1 = output, 0 = input
DDRB = 0b11111111; //All outputs
DDRC = 0b11111111; //All outputs
DDRD = 0b11111110; //PORTD (RX on PD0)

//General short delays
void delay_ms(uint16_t x)
uint8_t y, z;
for ( ; x > 0 ; x--){
for ( y = 0 ; y < 90 ; y++){
for ( z = 0 ; z < 6 ; z++){
asm volatile ("nop");

Copy and paste the code above into the Kontroller editor. I will spare you the details of what it says, unless you request me to do so.
After pasting the code into the kontroller lab editor, click on the build button in the toolbar. I will now go to the hardware side of the project, as the software portion for phase one is complete. We will return here after phase one of this project is complete.