Guide: How to use an Arduino as an In System Programmer (ISP)

I recently bought the "Graphic LCD Serial Backpack" from Sparkfun (SparkFun Graphic LCD Serial Backpack - LCD-09352 - SparkFun Electronics). When reading the comments for the product. I discovered that a user named "SummoningDark", had made a new improved firmware. A lot of people asked Sparkfun to change the official firmware with the new one, so i decided to check it out. The problem were that I do not own a programmer, so at first I thought that I had to buy one. But after some googling I found out that the Arduino could actually be used as an In System Programmer (ISP).
After a lot of work I finally got it working and it has really improved the perfomance of the screen. The speed is much higher (SummoningDark says 10 times) and there are no more bugs (with the old firmware the screen would suddenly write the text or a line a odd place).

I will now try to explain as best as I can, how to upload the new firmware.
NB: You can also use this guide if you need a different bootloader or another hex file on any AVR. This is just meant as an example.

The following DO NOT work with the Arduino Uno, for more information visit: http://arduino.cc/en/Tutorial/ArduinoISP

1) Start up the Arduino IDE (http://arduino.cc/en/Main/Software)
2) Go to File>Exampels>ArduinoISP and upload the software onto your Arduino - if your .hex file is more than 255bytes, you should use the newest version found on this page: Google Code Archive - Long-term storage for Google Code Project Hosting. (Version dev04b is confirmed to work)
3) Now you have to install AVRDude. I recommend downloading CrossPack (http://www.obdev.at/products/crosspack/index.html) for Max OX and WinAVR (http://winavr.sourceforge.net/) for Windows as it includes all you will need. Including an AVR compiler and AVRDude.
4) Download the program your want to upload. In my case it is the new firmware for the Serial Backpack (http://serialglcd.sourceforge.net/)
5) Compile the program to make a hex file, this can be done by typing "make all" in a terminal while inside the folder (use "cd" and then the path to the folder - see step 11 for help)
You might have to change some setting for it to work. If there is already an hex file (as in my example) you can just skip this step
6) Now connect the Arduino to the device you want to program. The pin used by the Arduino are as follows:

  • 10: slave reset
  • 11: MOSI
  • 12: MISO
  • 13: SCK

You have to connect these pins including VCC (5V with the Serial BackPack) and GND to the ISP header on your device like so:

The orientation of the ISP header on the backpack is like so:

If you are programming an AVR directly or an Arduino board. See this page for information: http://arduino.cc/en/Tutorial/ArduinoISP

You might also want to connect three LED's (with resistors) on the following pins:

  • 9: Heartbeat - shows the programmer is running
  • 8: Error - Lights up if something goes wrong (use red if that makes sense)
  • 7: Programming - In communication with the slave

7) The next thing you have to do is to connect a 120 ohm resistor (I use a 100 ohm and two 10 ohm resistors) between the 5V and reset headers on the Arduino to disable auto reset on serial connection (Arduino Playground - DisablingAutoResetOnSerialConnection) - some people do not need this small hack, so if you have problems to get it working, try without the 120 ohm resistor
8 ) Start up a terminal program. On a Mac simply find the terminal app in the programs folder. If you are using Windows open "run" and type "cmd". Your should now have a terminal window open
9) Now you have to figure out what port your Arduino is using. On a Mac simply type "ls -l /dev/cu.*" in the terminal and all your serial ports should pop up. If you are using Windows open Device Manager>ports and find your Arduino's COM-port. My port is: "/dev/cu.usbserial-A700dX8R", so I will use it in the following example
10) Write the following command in the terminal:
avrdude -p m168 -P /dev/cu.usbserial-A700dX8R -c avrisp -b 19200

"/dev/cu.usbserial-A700dX8R" should be replaced by your port. If your Arduino is on COM port 1, you should write "com1" instead. "m168" means that the target is a ATmega168 see this link for other aliases: AVRDUDE: 2.2 Programmers accepting extended parameters

The teminal will print out something like this:

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.13s

avrdude: Device signature = 0x1e9406

avrdude: safemode: Fuses OK

avrdude done.  Thank you.

Where 0x1e9406 is atmega168 device signature (look in avrdude.conf for other signatures)

11) If everything worked well it is now time for programming your device. The first thing you have to do is go inside the folder where your hex file is located. In my case I just copied the folder "trunk" to the main directory in the harddisk. Your should then use the following command:
cd /trunk

12) Next step is almost the same as 10), but this time you should add -U flash:w:filename to the command. Where "filename" should be replaced with the name of your hex file. In my case the name is "main.hex" so the command should look like this:
avrdude -p m168 -P /dev/cu.usbserial-A700dX8R -c avrisp -b 19200 -U flash:w:main.hex

The terminal will then print something like this:

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.13s

avrdude: Device signature = 0x1e9406
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "main.hex"
avrdude: input file main.hex auto detected as Intel Hex
avrdude: writing flash (11210 bytes):

Writing | ################################################## | 100% 14.03s

avrdude: 11210 bytes of flash written
avrdude: verifying flash memory against main.hex:
avrdude: load data flash data from input file main.hex:
avrdude: input file main.hex auto detected as Intel Hex
avrdude: input file main.hex contains 11210 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 12.89s

avrdude: verifying ...
avrdude: 11210 bytes of flash verified

avrdude: safemode: Fuses OK

avrdude done.  Thank you.

You should now - hopefully - have a new firmware on your device :slight_smile:
Hope this will be a help to some, because it really took me a long time figuring all this out.

  • Lauszus

thanks,

no need for it yet but very valuable (please consider posting it on the playground too)

Rob

I am not sure how to do that, do I just add it to this post: Arduino Playground - MegaISP?

  • Lauszus

could be ok, but a separate article might be prefered, for you to decide ... :wink:

The loginform does not work (Arduino Playground - LoginForm) or am i just doing it wrong?

  • Lauszus

heard that before on the forum, you might need to register separately.

I have now registered a new profile, but I still can not make a new page, or figure out how to do so.
I will just add it to Arduino Playground - MegaISP then :slight_smile:

  • Lauszus

Thanks Lauszus.

With my AVR ISP MkII busted and my FABISP having driver issues, this would work til I get a new AVR ISP.

I made my own version of the GLCD board for a different GLCD. I got the boards but have yet to populate them. I will try the SummoningDark firmware when its up and running.

Roy

I had hell of a time getting the programmer to work. The ArduinoISP example in Arduino-0022 does not allow more than 255bytes to be uploaded. To solve that you need to use ArduinoISP-dev04b (found at the MegaISP issues page.

Additionally, my Diecimilla mounted Atmega328 refused to act as an ISP with the reset-resistor in place. Removed the resistor and all was golden.

Moderator Edit: Corrected link.

#regomodo
Thanks for your respons, I have now updated the guide :slight_smile:

Hello.
I have to programming a ATmega8 in my own board. I followed the described procedure, but it doesn't work.
avrdude return:
"avrdude: stk500_getsync(): not in sync: resp=0x00"
I tried put 120 ohm resistor VCC to reset: the same result.

Enrico.

Have you connected everything correctly?
I had problems with the new Arduino ISP code in the Arduino IDE ver. 1, but the one in ver. 0.22 and 0.23 worked just fine :slight_smile:

Thanks for replay.

Now I explain my steps:

  • I am using Arduino Mega 2560;
  • Arduino software 0.22;
  • upload sketch 'ArduinoISP';
  • connect a ATmega8 with breadboard (for test) to Arduino with single wire for: reset (pin 10 Arduino, pin 1 ATmega8), MOSI (pin 11 Arduino, pin 17 ATmega8), MISO (pin 12 Arduino, pin 18 ATmega 8), SCK (pin 13 Arduino, pin 19 ATmega8), also connect VCC and GND;
  • put 120 ohm resistor between VCC and reset Arduino;
  • in console mode I digit: 'avrdude -p m8 -P com5 -c avrisp -b 19200';
  • result: avrdude: stk500_getsync(): not in sync: resp=0x00.

What do I worng?

Many thanks for your support.

Enrico.

I looks like that you havn't disabled auto reset properly :slight_smile:
Try with a 110 ohm resistor instead. You could also cut the trace labeled "RESET-EN", see http://arduino.cc/en/Main/ArduinoBoardMega2560 at the "Automatic (Software) Reset section".

Regards
Lauszus

I tried your indications.

With 110 ohm resistor:
avrdude.exe: stk500_getsync(): not in sync: resp=0x00

Then I cut the trace labeled "RESET-EN", without resistor (first time):
avrdude.exe: stk500_program_enable(): protocol error, expect=0x14, resp=0x50
avrdude.exe: initialization failed, rc=-1

  • Double check connections and try again, or use -F to override*
  • this check.*
    avrdude.exe: stk500_disable(): protocol error, expect=0x14, resp=0x51

With cutted, without resistor (others times):
avrdude.exe: stk500_getsync(): not in sync: resp=0x00
avrdude.exe: stk500_disable(): protocol error, expect=0x14, resp=0x51

Bye.
Enrico.

Hmm, that's weird.
Are you sure you have connected everything to the atmega8? Like all ground connections, VCC and a crystal (if you are using that).

Regards
Lauszus

Hello.
I tried to replace the card with another Arduino Mega 2560 and also the ATmega8 chip.
I'm using version 0.23 of the IDE.
AVRDUDE used is provided with the IDE.
I also added the crystal.

But the result is always the same.

You can see photo of the installation.

Hi,

You should install avrdude separately and not use the one bundled with the Arduino software - I have seen other people having problems with the bundled one as well.

I recommend downloading either WinAVR: http://winavr.sourceforge.net/ if you are running Windows or CrossPack: http://www.obdev.at/products/crosspack/index.html if you use MAC OS X. As they include all you will ever need like: a compiler (avr-gcc), programmer (avrdude), and debugger (avr-gdb) plus more.
You can also just download avrdude seperatly: AVR Downloader/UploaDEr - Summary [Savannah], but I can't see the point, as WinAVR and CrossPack is just way faster to get installed.

Hope that did the trick :slight_smile:

Regards
Lauszus

Thank you very much, but:
I downloaded WinAVR, type 'avrdude -p m8 -P com4 -c avrisp -b 19200' in C:\WinAVR-20100110\bin directory, and result is:
avrdude.exe: stk500_program_enable(): protocol error, expect=0x14, resp=0x50
avrdude.exe: initialization failed, rc=-1

  • Double check connections and try again, or use -F to override*
  • this check.*
    avrdude.exe: stk500_disable(): protocol error, expect=0x14, resp=0x51

I downloaded avrdude-5.11-Patch7610-win32, but the result is the same.

The problem could be the bootloader?

Enrico.

Hmm, are you sure that you have connected it the right way? See this post for more info: USBtiny-based AVR Programmer FAQ
Also take a look at this old thread, where people are discussing some of the errors you get: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1248528012/all

Regards
Lauszus