Programming Atmel ATtiny85 with the Sparkfun Pocket AVR Programmer

IMG_0131

Last Updated: Jan 11, 2013

This is a short note on programming the Atmel ATtiny85 with the Sparkfun Pocket AVR Programmer. There are 2 parts to this note – please read the one relevant to you.

  1. Programming ATtiny85 on windows using Atmel Studio 6 and WinAVR.
  2. Programming ATtiny85 on Mac OS X using Crosspack.

1. Programming ATtiny85 on windows using Atmel Studio 6 and WinAVR.

First, jump through the necessary hoops to install the driver for the programmer (USBTiny). You can read instructions here:

http://newbiehack.com/MicrocontrollerProgramTransferPart2Drivers.aspx

Then, you need to download Atmel Studio 6:

http://www.atmel.in/tools/atmelstudio.aspx

Next, install WinAVR:

http://sourceforge.net/projects/winavr/files/

Now, watch this video by newbiehack.com on Atmel Studio 6 setup:

http://www.youtube.com/watch?v=iTTZUpzAjKc

The video backtracks a lot due to some path errors, and even at the end, it is not clear what was entered in the text boxes. So here is the relevant dialog:

avr

The problem is that Atmel Studio 6 ignores the “Initial Directory” box, and the hex file path specification is tricky. So here it is – notice the “:i” at the end:

-c usbtiny -p attiny85 -U flash:w:”$(ProjectDir)\Release\$(ItemFileName).hex”:i

That’s it. Once you have these set up, you have a fantastic tool for AVR development. Code, debug, and upload to your chip right from Atmel Studio 6. I am switching to windows for AVR development, since there is no such professional tool on the Mac.

2. Programming ATtiny85 on Mac OS X using Crosspack.

First you need to install CrossPack for AVR development:

http://www.obdev.at/products/crosspack/index.html

You don’t need Xcode, and the above comes with everything you need, including avrdude.

After installation, you will find a “CrossPack-AVR-Manual” link in the Application folder, which you should go through.

Here is how you can create simple LED blinking application.

In a Terminal window:

$ avr-project hello
Using template: /usr/local/CrossPack-AVR-20121207/etc/templates/TemplateProject
$ cd hello
$ ls
firmware    hello.xcodeproj
$ cd firmware/
$ ls
Makefile    main.c

Now, you need to modify the Makefile as follows: (diff below)
20c20,21
< DEVICE     = atmega8
---
> #DEVICE     = atmega8
> DEVICE      = attiny85
22c23
< PROGRAMMER = #-c stk500v2 -P avrdoper
---
> PROGRAMMER = -c usbtiny #-c stk500v2 -P avrdoper
24c25,27
< FUSES      = -U hfuse:w:0xd9:m -U lfuse:w:0x24:m
---
> #FUSES      = -U hfuse:w:0xd9:m -U lfuse:w:0x24:m
> # for ATTiny85
> FUSES       = -U lfuse:w:0x62:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m 

I got the information for fuse from the website below:

http://www.engbedded.com/fusecalc/

Here is a simple program from denhart.dk which I modified a bit:

http://denhart.dk/2011/08/programming-attiny85-with-avrdude/

 C |  copy code |? 
01
#include <avr/io.h>
02
#include <util/delay.h>
03
 
04
int main (void)
05
{
06
  //Set PORTB.3 to be output
07
    DDRB = 0b00001000;
08
  while (1) {
09
    //Set PORTB.3 high
10
    PORTB = 0b00001000;
11
 
12
    _delay_ms(500);
13
 
14
    //Set PORTB.3 low again
15
    PORTB = 0b00000000;
16
 
17
    _delay_ms(100);
18
  }
19
 
20
  return 1;
21
}

Now for the connections.

Here is the pinout for ATtiny 85 from the Atmel datasheet:

attiny85-pinout

And here is the connection diagram for the 3×2 header of the Sparkfun pocket programmer.

IMG_0136

Now, hook up the circuit, put an LED between pin 2 (PB3) and pin 4 (GND), plug in the programmer to the USB port and type :

$make install

If all goes well, you will see the LED blinking.

In India, you can buy the Sparkfun Pocket AVR Programmer from Rhydolaz, Kochi (albeit at an inflated price).

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>