Making .hex files in ubunto

hey
I got ubunto 7.10.
I heard that I can use avrdude with it but I don’t know how to make the .hex files.
thanks
Arbel

Hello Arbel,
To compile C programs for the AVR under Ubuntu Linux you’ll need to install a few different packages: avr-libc, binutils-avr, and gcc-avr. Typically, I just start up synaptic and install everything with “avr” in the name.

Once the software is installed, you’ll need to run a sequence of commands like

/usr/bin/avr-gcc -g -Os -Wall -mcall-prologues -mmcu=atmega168   -c -o lcd.o lcd.c
/usr/bin/avr-gcc -g -Os -Wall -mcall-prologues -mmcu=atmega168   -c -o main.o main.c
/usr/bin/avr-gcc -g -Os -Wall -mcall-prologues -mmcu=atmega168   -c -o analog.o analog.c
/usr/bin/avr-gcc -g -Os -Wall -mcall-prologues -mmcu=atmega168 lcd.o main.o analog.o -o main.obj
/usr/bin/avr-objcopy  -R .eeprom -O ihex main.obj main.hex

to compile several C files and incorporate the results into a single hex file. For convenience, you will want to write a Makefile that automatically runs the correct commands as necessary. Let me know if you have any more questions about getting this working under linux!

-Paul

For an example of such a makefile, you can take a look at the linux portion of our Orangutan USB Programmer user’s guide:

pololu.com/products/pololu/0 … ide/#linux

- Ben

this is the error I get:

arbel@arbel-desktop:~$ make arbel/BlinkLED/Makefile
make: *** No rule to make target `arbel/BlinkLED/Makefile’. Stop.

I must say that I am using the AVRISP MKII and not the pololu programmer. I tried to use the example given by Ben.
Arbel

To use a Makefile, you don’t need to specify the name of the file, since it is by default assumed to be “Makefile”. If you change your current directory to arbel/BlinkLED and then run “make”, it should work automatically.

-Paul

now I got this error:
arbel@arbel-desktop:~$ cd /home/arbel/BlinkLED
arbel@arbel-desktop:~/BlinkLED$ make
/usr/bin/avr-gcc -g -Os -Wall -mcall-prologues -mmcu=atmega168 -c -o BlinkLED.o BlinkLED.c
/usr/bin/avr-gcc -g -Os -Wall -mcall-prologues -mmcu=atmega168 BlinkLED.o -o BlinkLED.obj
/usr/bin/avr-objcopy -R .eeprom -O ihex BlinkLED.obj BlinkLED.hex
/usr/bin/avrdude -c avrispv2 -p m168 -P /dev/ttyUSB0 -e
avrdude: ser_open(): can’t open device “/dev/ttyUSB0”: No such file or directory
make: *** [program] Error 1
rm BlinkLED.o BlinkLED.obj

where do I get that? /dev/ttyUSB0 ?
dose that means he can’t find the programmer or the baby O?

Hello,

First of all, you will need to change avrispv2 to avrispmkii in the avrdude line of your Makefile. Second, I don’t know much about this device and linux - to check whether it is being recognized, after plugging it in, type the command “dmesg” and tell me if anything related to that device appeared in the output. Then, instead of “-P /dev/ttyUSB0”, I think you will just use “-P usb”.

Let me know if that helps.
-Paul

ok, new errors:
I wrote dmesg and got the longest list and I couldn’t understand any of it.

I changed the makefile as you said an got thus error:
arbel@arbel-desktop:~/BlinkLED$ make
/usr/bin/avrdude -c avrispmkii -p m168 -P USB -e
avrdude: ser_open(): can’t open device “USB”: No such file or directory
make: *** [program] Error 1

I tried to change the port specifications according to the avrdude manual to usb:serialno and I got a different error:

arbel@arbel-desktop:~/BlinkLED$ make
/usr/bin/avrdude -c avrispmkii -p m168 -P usb:serialno -e
avrdude: usb_open(): cannot read serial number "error sending control message: Operation not permitted"
make: *** [program] Error 1

I think that means that he cant read my programmer…

Arbel

After plugging in the programmer, do you see anything at the end of the dmesg output about USB devices being detected? That’s really important to know.

I think that you don’t need to specify the serial number to avrdude if you only have one programmer - please try it just with “-P usb” (the “usb” is not capitalized) and let me know what happens.
-Paul

O.K i wrote dmesg and here is the end of the output:
[ 2361.228000] EXT3 FS on hdb1, internal journal
[ 2361.228000] EXT3-fs: mounted filesystem with ordered data mode.
[ 6621.420000] usb 1-2.1: new full speed USB device using uhci_hcd and address 5
[ 6621.544000] usb 1-2.1: configuration #1 chosen from 1 choice
[ 6894.088000] usb 1-2.1: USB disconnect, address 5
[ 6895.952000] usb 1-2.1: new full speed USB device using uhci_hcd and address 6
[ 6896.076000] usb 1-2.1: configuration #1 chosen from 1 choice
arbel@arbel-desktop:~/BlinkLED$

thanks
Arbel

Okay, so did you try programming again with “-P usb”?

-Paul

yes, steal no good, in fact, I think that when I changed the avrispv2 to avrispmkii it stoped erllyer then it did with the avrispv2, maybe I should chang it back.

Try changing “avrispmkii” to “avrispmkII” (capitalize the last two i’s). If you’re using an AVRISP MKII, you don’t want to have your -c flag as avrispv2.

- Ben

Hay again…
o.k, I can’t seem to be able to make avr dude to work, so I will give you gays ALL the details, I hope you will be able to help me…
so:
I am using the digikey avr ISP mkII. I got both baby O and orangutan, I got ubunto 7.10. I think thats it…

my makefile looks like this:

CC=/usr/bin/avr-gcc
MEGA=168
CFLAGS=-g -Os -Wall -mcall-prologues -mmcu=atmega$(MEGA)
OBJ2HEX=/usr/bin/avr-objcopy 
PROG=/usr/bin/avrdude
TARGET=BlinkLED

program : $(TARGET).hex
	$(PROG) -c avrispmkII -p m$(MEGA) -P usb
	$(PROG) -c avrispmkII -p m$(MEGA) -P usb -U flash:w:$(TARGET).hex

%.obj : %.o
	$(CC) $(CFLAGS) $< -o $@

%.hex : %.obj
	$(OBJ2HEX) -R .eeprom -O ihex $< $@

clean :
	rm -f *.hex *.obj *.o

I got the .hex file in the same directory as the makefile.

I am using this code and makefile.
when I write MAKE I get this error:

arbelmichal@arbelmichal-desktop:~/Desktop/Documents/BlinkLED/linux$ make
/usr/bin/avrdude -c avrispmkII -p m168 -P usb
avrdude: usb_open(): cannot read serial number "error sending control message: Operation not permitted"
avrdude: usb_open(): cannot read product name "error sending control message: Operation not permitted"
avrdude: usbdev_open(): error setting configuration 1: could not set config 1: Operation not permitted
avrdude: usbdev_open(): did not find any USB device "usb"
make: *** [program] Error 1
arbelmichal@arbelmichal-desktop:~/Desktop/Documents/BlinkLED/linux$ 

please help! if I will be able to use my ubunto to program my robot, I will be able to leave windows for ever!!!
thanks
Arbel

It’s alive!!! IT’S WORKING!!! so, how do I make my own code, how do I link it to other source files and how do I make .hex file or do the make command makes the .hex file for me? :laughing:

Hello Arbel,
I’m glad that you got it working! Can you explain what you were doing wrong in case other people run into the same problem in the future?

A good way to start working on your own code is to edit the .c files included with the example program. Since you have everything working correctly now, you should be able to change something, then type “make” to compile your code to a hex file and load it onto your board. If there are any errors, they will be displayed on the screen. Making small changes at first will help you understand what’s going on.

Let us know if you get stuck!
-Paul

I think that the main change that I made was to reinstall avrdude because I dident find the files specified in the makefile in the directory they should have been. I think that the reinstall solved the problem. thanks for every thing/ I will let you know when I am stuck
Arbel

so, first of all, I found I did another thing to make ‘make’ work, I switched to root user.

any way’ every thing is working, the make command dose make a hex file but I tried to add some lcd functions, so I included the lcd.h from the orangutan lib, and I placed both the lcd.h file and the lcd.c file in the same folder containing the BlinkLED.c file and then I wrote:

// F_CPU tells util/delay.h our clock frequency

#define F_CPU 8000000UL	// Orangutan frequency (8MHz)

//#define F_CPU 20000000UL	// Baby Orangutan frequency (20MHz)

#include <avr/io.h>

#include <util/delay.h>

#include "lcd.h"

void delayms( uint16_t millis ) {

	while ( millis ) {

		_delay_ms( 1 );

		millis--;

	}

}



int main( void ) {

	DDRD |= 1 << PD1;			// set LED pin PD1 to output

	while ( 1 ) {

		PORTD &= ~( 1 << PD1 );	// LED off

		delayms( 300 );			// delay 900 ms

		PORTD |= 1 << PD1; 		// LED on

		delayms( 300 );			// delay 100 ms

lcd_clear();
lcd_gotoxy(0,0);
lcd_string("HELLO");

	}

	return 0;

}

and then I got this error:

/usr/bin/avr-gcc -g -Os -Wall -mcall-prologues -mmcu=atmega168   -c -o BlinkLED.o BlinkLED.c
BlinkLED.c: In function ‘main’:
BlinkLED.c:22: warning: implicit declaration of function ‘lcd_clear’
BlinkLED.c:23: warning: implicit declaration of function ‘lcd_gotoxy’
BlinkLED.c:24: warning: implicit declaration of function ‘lcd_string’
/usr/bin/avr-gcc -g -Os -Wall -mcall-prologues -mmcu=atmega168 BlinkLED.o -o BlinkLED.obj
BlinkLED.o: In function `main':
/home/arbelmichal/Desktop/Documents/BlinkLED/linux/BlinkLED.c:22: undefined reference to `lcd_clear'
/home/arbelmichal/Desktop/Documents/BlinkLED/linux/BlinkLED.c:23: undefined reference to `lcd_gotoxy'
/home/arbelmichal/Desktop/Documents/BlinkLED/linux/BlinkLED.c:24: undefined reference to `lcd_string'
make: *** [BlinkLED.obj] Error 1
rm BlinkLED.o

Arbel

Hello,
To use Orangutan-lib, you’ll also need to include device.h and compile lcd.c along with the rest of the program. One way to do this is by changing the %.obj section of the Makefile to this:

BlinkLED.obj : BlinkLED.o lcd.o
	$(CC) $(CFLAGS) BlinkLED.o lcd.o -o $@

By the way, there are a bunch of good examples included with Orangutan-lib, and the authors include a script called “winavr-to-unix” that is supposed to modify all of the Makefiles for use with Linux. I haven’t tried it before, but I can probably help you if you have trouble with it.

-Paul

Hello
I get this error:

Makefile:13: *** missing separator.  Stop.

I think I didn’t change the makefile like I should have… this is what I did:

%.obj : BlinkLED.o lcd.o
   $(CC) $(CFLAGS) BlinkLED.o lcd.o -o $@[/code]

I tried to change it like this to:
[code]CC=/usr/bin/avr-gcc
MEGA=168
CFLAGS=-g -Os -Wall -mcall-prologues -mmcu=atmega$(MEGA)
OBJ2HEX=/usr/bin/avr-objcopy 
PROG=/usr/bin/avrdude
TARGET=BlinkLED

program : $(TARGET).hex
	$(PROG) -c avrispmkII -p m$(MEGA) -P usb -e
	$(PROG) -c avrispmkII -p m$(MEGA) -P usb -U flash:w:$(TARGET).hex

    BlinkLED.obj : BlinkLED.o lcd.o
       $(CC) $(CFLAGS) BlinkLED.o lcd.o -o $@

%.hex : %.obj
	$(OBJ2HEX) -R .eeprom -O ihex $< $@

clean :
	rm -f *.hex *.obj *.o[/code] 

steal, same error…
by the way, how do I use that script in the orangutan lib?
Arbel