Let's Make Robots!

Programming an atmega with the Arduino IDE

Hi guys.

from this post (http://letsmakerobots.com/node/5593 ) by Rudolph i learned that you can program an atmega with the arudino IDE even if you haven't got an arduino board.

What i have here with me now is an atmega328, a serial programmer (precisely this one: http://www.sparkfun.com/commerce/product_info.php?products_id=14 ).

The point is that I do not know how to connect the programmer to the atmega328. I've seen that arduino boards usually have a 3 by 2 array (6 pin total) of male headers while my programmer has a 5 by 2 socket (10 pin total). I've arranged the pins this way (http://www.olimex.com/dev/images/avr-icsp-10.gif ) but i'm not totally sure it is correct, since the header "size" is different. 

...and since i'm afraid to screw up the chip i'm asking you if it is correct before trying to make it work. (I'm pretty sure it's right, cause no matter what size it is, connections shouldn't change, but i feel it's safer for the chip to ask you before i do anything).

 


Also: i've written "avrisp" in the preferences.txt file under the upload entry (wasn't really upload but something similar, but i guess you got what i mean). I think it should be correct for the type of programmer i have.

 

 

Thank you! :=) 

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
CaptainTuna's picture

exactly!!! the boards.txt was the key to making it work :D Thank you very much RobotFreak!

I also found out that blank atmegas come with the "divide clock by 8" option enabled and are by default at 8MHz (so result would be 1MHz), so if build.f_cpu is 16000000L and you write delay(1000) in you sketch, you'll have a pause which lasts 16 seconds. Make sure you either adjust the f_cpu setting or modify the fuses... Just in case some arduino-newbie like me is reading. 

RobotFreak's picture

I have done some tests with the Arduino IDE. I think I have found a way, that will work. Looking into the avrdude.conf file did not show any differences between ponyser and siprog. Just a different name for the same device.

 

Change the  boards.txt file and add a new board similar to this one (depends on the µc used):

 

 ##############################################################

arduinoclone328.name=Arduino Clone w/ ATmega328

arduinoclone328.upload.protocol=ponyser
arduinoclone328.upload.maximum_size=30720
arduinoclone328.upload.speed=19200

arduinoclone328.bootloader.low_fuses=0xFF
arduinoclone328.bootloader.high_fuses=0xDA
arduinoclone328.bootloader.extended_fuses=0x05
arduinoclone328.bootloader.path=atmega
arduinoclone328.bootloader.file=ATmegaBOOT_168_atmega328.hex
arduinoclone328.bootloader.unlock_bits=0x3F
arduinoclone328.bootloader.lock_bits=0x0F

arduinoclone328.build.mcu=atmega328p
arduinoclone328.build.f_cpu=16000000L
arduinoclone328.build.core=arduino

 ##############################################################

When you start the Arduino IDE the new board  is visible under Tools | Board. Starting to load a sketch gives the following output:

C:\Programme\arduino-0017\hardware/tools/avr/bin/avrdude -CC:\Programme\arduino-0017\hardware/tools/avr/etc/avrdude.conf -v -v -v -v -pm328p -cponyser -P\\.\COM1 -b19200 -D -Uflash:w:C:\Programme\arduino-0017\examples\Digital\Blink\applet\Blink.cpp.hex:i


avrdude: Version 5.4-arduino, compiled on Oct 11 2007 at 19:12:32
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/

         System wide configuration file is "C:\Programme\arduino-0017\hardware/tools/avr/etc/avrdude.conf"

         Using Port            : \\.\COM1
         Using Programmer      : ponyser
         Overriding Baud Rate  : 19200
avrdude: ser_open(): opened comm port "\\.\COM1", handle 0x7b4
         AVR Part              : ATMEGA328P
         Chip Erase delay      : 9000 us
         PAGEL                 : PD7
         BS2                   : PC2
         RESET disposition     : dedicated
         RETRY pulse           : SCK
         serial program mode   : yes
         parallel program mode : yes
         Timeout               : 200
         StabDelay             : 100
         CmdexeDelay           : 25
         SyncLoops             : 32
         ByteDelay             : 0
         PollIndex             : 3
         PollValue             : 0x53
         Memory Detail         :
 

 

voodoobot's picture
What about just getting avr studio? that would give you quite a lot more features vs the arduino prog editor. At least in Devopment it would give you a better understanding of whats going on and you could just copy/paste the code into the arduino prog editor when you want to upload...or use the avrdude app...however you do it.
CaptainTuna's picture
arduino looks quite simple. Maybe when i can handle atmega chips better i'll move on to avr studio, but for now i'd prefer to stay with a higher level language.
CaptainTuna's picture

I experimented a bit with the infos you gave me RFreak, and i found out that the right one for me is "ponyser" (from pony prog i guess). I used AVRdude (alone, not the one that comes with the arduino ide) to upload the code and it works fine. BUT, i still can't upload it with the arduino IDE.

This is what i found in avrdude's .CONF file:

# serial ponyprog design (dasa2 in uisp)

# reset=!txd sck=rts mosi=dtr miso=cts

programmer

  id    = "ponyser";

  desc  = "design ponyprog serial, reset=!txd sck=rts mosi=dtr miso=cts";

  type  = serbb;

  reset = ~3;

  sck   = 7;

  mosi  = 4;

  miso  = 8;

;

 

I guess i somehow have to insert these information in the hardware.txt file, but do not know how. I tried with siprog and ponyser already the way you wrote it and it doesn't work. Any suggestion? 

RobotFreak's picture

OK, I see, the hardware.txt file needs to be modified too. Maybe this modification will work. AFAIK The Arduino IDE uses avrdude as programmer and avrdude supports the Lancos SI-Prog. 

siprog.name=LANCOS SI-PROG

siprog.communication=serial

siprog.protocol=siprog

 

CaptainTuna's picture

Hey thank for the answer RobotFreak!

The guide I read on arduino.cc talked about adding in the preferences.txt file one of the codes found in the hardware.txt file. But in the hardware.txt file i only have 3 programmer codes, so i guess that before adding "siprog" in preferences, i need to add an entry for it in hardware.txt (i am not sure i explained this correctly).

Just to give you an idea, the hardware file contains this:

 

 avrisp.name=AVR ISP

avrisp.communication=serial

avrisp.protocol=stk500

 

avrispmkii.name=AVRISP mkII

avrispmkii.communication=usb

avrispmkii.protocol=stk500v2

 

usbtinyisp.name=USBtinyISP

usbtinyisp.protocol=usbtiny

 

parallel.name=Parallel Programmer

parallel.protocol=dapa

 

 

parallel.force=true

# parallel.delay=200

 


 the communication and the protocol of the "avrisp" match those of my programmer already.

RobotFreak's picture

Hi CaptainTun,

This serial programmer looks similar to the Lancos SI Prog. You should use 'siprog' instead of 'avrisp' in the preference file. The 10pin connector is identical to the 6pin connector, it is only a different pinout.