Arduino Forum

Forum 2005-2010 (read only) => Hardware => Development => Topic started by: bigfun on Sep 29, 2006, 05:08 am

Title: Arduino on the ATMEGA168
Post by: bigfun on Sep 29, 2006, 05:08 am
I've seen advertisements for Arduino boards with the Atmega168 programmed with the Arduino bootloader.  How is this done?  I've tried doing this in PonyProg (which doesn't claim to support the Atmega168 but can be used to write its flash memory) and the resulting Atmega doesn't boot when plugged into an Arduino board.

If someone can just point me to an atmega168 .hex bootloader file, i would be most pleased!

Title: Re: Arduino on the ATMEGA168
Post by: DojoDave on Sep 30, 2006, 01:04 am
Hej,

the bootloader is available both as source and as hex file, however the bootloading process is still a mistery, it works with some programmers and with others it doesn't.

Download the thing here:

http://webzone.k3.mah.se/projects/arduino-workshop/upload/default.asp?folder=40

Regards,

/David
Title: Re: Arduino on the ATMEGA168
Post by: bigfun on Sep 30, 2006, 05:11 am
i used ponyprog for that .hex file (and though ponyprog claims it doesn't recognize the device, it does stuff when you hit ignore and then claims the write was successful). i'm not really clear on whether i should be flashing the flash or uploading to the eeprom - i know what these terms mean, but how they apply to the arduino have never been clear.  does the arduino pay any attention to eeprom?  anyway, my flashed atmega168 showed more signs of life when placed on an arduino board - that digital out 13 LED flashed a few times.  but the TX LED never flashed and it never turned into any sort of usable arduino.  is there any other atmel chip that fits in this socket that i could try?  lord knows they're cheap enough!
Title: Re: Arduino on the ATMEGA168
Post by: bigfun on Sep 30, 2006, 05:16 am
by the way, the dongle programmer thing i'm using is the AVR-PG1.  What programming software should I be trying with this dongle, the olimex AVR-P28 board and the ATMEGA168? I'm totally new to microcontrollers and the AVR world, but I have extensive experience in digital electronics, usually making things happen with flip flops, logic gates, and what not.  the arduino board makes things so much easier, but I need a little more memory to write routines to drive an LCD display.
Title: Re: Arduino on the ATMEGA168
Post by: neillzero on Oct 17, 2006, 04:17 am
Quote
does the arduino pay any attention to eeprom?

The arduino system doesn't pay attention to the eeprom, as far as I can tell.  It is data memory, rather than program memory.  You are free to use it to persist parameters, or last sensor readings, or whatever.  Neither the build process (http://www.arduino.cc/playground/Learning/BuildProcess) nor bootloader (http://www.arduino.cc/en/Main/Bootloader) docs mention eeprom at all.

This wiki page (http://www.arduino.cc/playground/Code/EEPROM-Flash) documents how to read / write in that space from your arduino program, and you can also read the atmega8 datasheet (http://www.atmel.com/dyn/resources/prod_documents/doc2486.pdf).

Note there's only 512 bytes of this eeprom on both the atmega8 and atmega168.

I might be hideously wrong about this, but I've wiped all 512 bytes of my eeprom and... so far so good.  The bootloader (http://svn.berlios.de/viewcvs/arduino/trunk/bootloader/ATmegaBOOT.c?view=markup) does have code for writing to eeprom but I don't know if it currently does.  A possible use of eeprom by the bootloader would be keeping a track of the number of times the flash had been written (helping you to predict when it's going to fail).  

I also heard a rumour that the atmega8s prepared on the arduino boards have future winning lottery ticket numbers written in that space, so some people do a backup first.

Sorry I can't answer your other questions.
Title: Re: Arduino on the ATMEGA168
Post by: bigfun on Oct 20, 2006, 10:11 pm
I just successfully wrote the ATmegaBOOT_168.hex file to my Atmega168 using the AVR-PG1 serial dongle
http://www.sparkfun.com/commerce/product_info.php?products_id=14
using avrdude and the command line
avrdude -patmega168 -cponyser -Pcom1 -b9600 -u -Uflash:w:a.hex
(where a.hex is a renamed ATmegaBOOT_168.hex)
What I wouldn't have given for someone to give me a real world example of that program in use!

Now, though, that reflashed Atmega168 is still unrecognized by the Arduino environment.
Has anyone ever used an Atmega168 in an Arduino board?
Title: Re: Arduino on the ATMEGA168
Post by: leKuk on Oct 21, 2006, 03:02 am
yes. i didn't burn the bootloader myself though. i got the pre-burned atmega168 from ars electronica. i simply replaced the (dead)atmega8 on the board and it worked.

remember that you have to select the target microprocessor manually, i.e. 8 or 168 in the arduino application. that took me some time to figure out.

//kuk
Title: Re: Arduino on the ATMEGA168
Post by: bigfun on Oct 21, 2006, 03:37 am
I know about the processor selection menu and that isn't my problem.  But if you or anyone else can get a dump of the flash memory on a working Arduino Atmega168 and post it here somehow, maybe I could try that out.  I guess you'd have to use avrdude or a program like that - Arduino can't read processors at all.

Title: Re: Arduino on the ATMEGA168
Post by: bigfun on Oct 21, 2006, 08:25 pm
For the time being I've given up on getting a bootloader to work on my Atmega168. I compiled my Arduino sketch using the Atmega168 processor setting and then went and dug the .hex file out of the applet folder in its project folder.  Then I uploaded it to Atmega168 using AVRdude and the AVR-PG1 dongle.  This all worked fine.

The sketch I'd uploaded has a known behavior of outputting (over the serial output) a line of space-delimited integers every two seconds.  Interestingly, I noticed that though it was working, it was doing so much more slowly than normal and the output was garbled at the expected baud rate.  So I did some experiments by changing the build.f_cpu in the preferences file, ultimately changing it from 16 MHz to just one MHz.  At 1 MHz the baud rate matched the one expected, meaning that somehow the compilation process for the Atmega168 is misjudging the baud rate timing by a factor of 16.  Mind you, I know for a fact that it is actually being clocked at 16MHz (an Atmega8 works exactly as expected in this same socket).  Does anyone have any theories about this peculiar behavior? I have a feeling this all will go a long way to explaining why the Atmega168 bootloader isn't working.
Title: Re: Arduino on the ATMEGA168
Post by: mellis on Oct 21, 2006, 08:50 pm
The fuses on your ATmega168 aren't set correctly; fuses being the bane of microcontroller programming - a few important but obscure options that you can only set with an external programmer.  The ATmega168 defaults to the use of a 1 MHz internal clock (e.g. ignoring the 16 MHZ crystal on your board).  

The fuses you want might be:
high fuse: 0xdf
low fuse: 0xc7
extended fuse: 0x08
but it's also possible that they will make your ATmega168 unusable.  I've had lots of problems trying to find the right fuse settings, and particularly with setting the extended fuse (which most AVRs, like the ATmega8, don't have).
Title: Re: Arduino on the ATMEGA168
Post by: bigfun on Oct 21, 2006, 09:55 pm
I kept hearing the term "fuse" and I had no reason to find out what it meant until you mentioned that it was probably my problem. I recommend that anyone who is curious check out this page:

http://electrons.psychogenic.com/modules/arms/art/14/AVRFusesHOWTOGuide.php

I took a gamble and used the fuse settings you suggested and, happily, my Atmega168 is flashed with a proper Arduino bootloader!  Thanks so much!

For those who need to properly set their Atmgea168 fuses in the future, the AVRdude command line is (depending on your programmer/serial port, I'm using the AVR-PG1 serial dongle on COM1):

avrdude -patmega168 -cponyser -Pcom1 -b9600 -u -v  -Uhfuse:w:0xdf:m -Ulfuse:w:0xc7:m -Uefuse:w:0x08:m
Title: Re: Arduino on the ATMEGA168
Post by: jds on Nov 13, 2006, 08:50 am
Is there anyone that can sell these Atmega1268  'pre-programmed' and ready to use for the standard Arduino (not the Arduino mini)?
Title: Re: Arduino on the ATMEGA168
Post by: bigfun on Nov 13, 2006, 05:52 pm
hmm, business opportunity!

paypal me $15 at bigfunATverizon.net and send me your snail mail address and i'll make you one.
$10 each for each additional atmega168 in the package.  if lots of people take advantage of this, you might have to wait for me to resupply.
Title: Re: Arduino on the ATMEGA168
Post by: jds on Nov 14, 2006, 09:02 am
I just sent you US$ 15.00 through PayPal...  Looking forward to get started with this as the Atmega8 is really too small for me...

You also participated in a thread about getting the Atmega32 ready for use with the Arduino... Any status on that?

Thanks

JD
Title: Re: Arduino on the ATMEGA168
Post by: bigfun on Nov 15, 2006, 03:34 am
Well, interestingly, if you look at its source there appears to be support in the Arduino bootloader code (the version I use for the Atmega168) for the Atmega32 (and other AVR processors not often discussed). The problem is that there is no actual support in the Arduino IDE for Atmega32.   It's crucial that the IDE know about the Atmega32 or it won't be able to do anything. If I was a little more adventurous I would have waded into the IDE source code to see what had changed to add Atmgea168 support and see if those changes, geared to the specifics of the Atmega32, could then added again. But I'd want one of the Arduino old school kids here to point me in the right direction first.
Title: Re: Arduino on the ATMEGA168
Post by: BeaverWise on Nov 15, 2006, 04:16 am
I am interested in getting one of those Atmega168 chips.  What would I need to do?
Title: Re: Arduino on the ATMEGA168
Post by: jds on Nov 15, 2006, 02:11 pm
paypal $15 at bigfunATverizon.net and Brainfart will get it sorted for you....
Title: Re: Arduino on the ATMEGA168
Post by: wolfpaulus on Nov 19, 2006, 05:22 am
... At this point, the microcontroller chip on the Arduino board had been replaced with the 16 KByte ATmega168 and everything but the ICSP port had been disconnected. The Arduino board itself was powered by a 7.5V 500mA power supply and the AVRISP-mkII connected the board with the Mac's USB port.

On the software side, avrdude 5.2 was installed into /usr/local/bin and the ATmega168 boot-loader was made available here /AT168.hex

Burning and Fuses
Burning a new boot loader is a three-step process: unlocking the boot loader segment, uploading the new boot loader, and looking boot loader segment again.

Read the full story here: http://wolfpaulus.com/journal/embedded/arduino2.html

Title: Re: Arduino on the ATMEGA168
Post by: jds on Nov 19, 2006, 11:40 am
Quote
paypal $15 at bigfunATverizon.net and Brainfart will get it sorted for you....


I already received my Atmega168 from bigfun. It took 3 days from him in the USA to me in The Netherlands!

Thanks bigfun!
Title: Re: Arduino on the ATMEGA168
Post by: visionFoo on Nov 20, 2006, 03:46 am
Quote
Read the full story here: http://wolfpaulus.com/journal/embedded/arduino2.html


:) Thank you! You've put everything on one page and as a mac-only hardware owner I greatly appreciate your work.

And the same to everyone else who has posted on this thread.

(looking forward to having more space to program with!)
Title: Re: Arduino on the ATMEGA168
Post by: bigfun on Dec 04, 2006, 12:50 am
Ok - I made a real page for someone to go to to buy Atmega168/8s preloaded with Arduino firmware.
http://asecular.com/arduino/
Title: Re: Arduino on the ATMEGA168
Post by: lgbsneak on Mar 07, 2007, 01:10 am
I've tried this and got it the boot loader burned and everything appears to be working, except for one thing.
Does anybody else observe that the orange light blinks slower on boot/reset than on the atmega8? I also have motors that take servo commands to set the speed and they appear to be going slower. Though this could be all in my head.
Anybody else notice anything like this? Is there a way to measure if the atmega168 is running at the right speed? I've gone round and round with the fuses (causing me to burn out my mega8 so i can't compare it) and i haven't been able to get light to blink faster on boot. This could of course just be in the code for the 168 boot loader though. Anybody have an insight?
Title: Re: Arduino on the ATMEGA168
Post by: bigfun on Mar 07, 2007, 06:15 am
I can assure you that you are imagining the speed difference.  I have used Atmega8s and Atmega168s in the same socket with the same circuitry and have never seen speed differences when executing identical programs, some of which do nothing but record the time, iterate through thousands of loops, and then record the time again.  

Of course, if you have the fuse settings set wrong, it's possible to, say, have the Atmega168 cranking along at only 1MHz, but in those cases its serial port will not work with the default settings for the Arduino IDE and you'd have an objective sense of the problem instead of the subjective one you describe.
Title: Re: Arduino on the ATMEGA168
Post by: lgbsneak on Mar 14, 2007, 08:34 pm
Ah, thanks for the assurance. It doesn't seem like I could slow it down the little bit that it seems with the fuses anyway.
Title: Re: Arduino on the ATMEGA168
Post by: bigfun on Apr 07, 2007, 11:21 pm
Not that this discussion should be happening here, but I did mail them.

It seems there's a downside to depending on international mail to make people happy.
Obviously, if they don't arrive then you get a refund.
Title: Re: Arduino on the ATMEGA168
Post by: lgbsneak on Apr 10, 2007, 07:51 pm
I can't tell if I've had this issue the entire time I've been using a 168 or not, but at the moment, in order for the programs i download to the chip to run, I need to briefly plug in the usb cable. I can then unplug it, and after the bootloaders wait time, the program will run. It does this even with the led_blink program, so it has to do with either the bootloader or whatever happens before the bootloader. Both pressing the reset button, or reseting the power will cause it to have this problem. I've tried two different chips, tried all the bootloaders i can find. Tried uisp and avrdude. Anybody have an insight to why this is happening? I'm using the arduino on a robot that is only connected to usb to download, so it's very annoying  to have to plug it in every time i want to start it. Fuse settings i'm using are: hfuse 0xDF lfuse 0xFF efuse 0xF8 lock 0xCF
Title: Re: Arduino on the ATMEGA168
Post by: admin on Apr 10, 2007, 08:02 pm
put a 100k pulldown resistor on RX and you'll be fine...

this must be the biggest FAQ about arduino.. :) :)

massimo
Title: Re: Arduino on the ATMEGA168
Post by: lgbsneak on Apr 10, 2007, 10:07 pm
Wow, that did it.. Thanks
Title: Re: Arduino on the ATMEGA168
Post by: Erik on Apr 11, 2007, 11:13 am
Quote
still waiting for my 3 atmega168 to arrive from bigfun!


they arrived this morning!!!

thanks bigfun for the kind offer to return the money or send a new batch. excellent service.

erik