Programming an ATTiny85 with an Arduino Uno

Using and Programming Arduino and other microcontrollers
phenoptix
Competent
PostsCOLON 744
JoinedCOLON Sat Apr 17, 2010 11:25 am

Programming an ATTiny85 with an Arduino Uno

Postby phenoptix » Tue Feb 28, 2012 3:22 pm

Using your Arduino as an AVR programmer is just another string to it's already feature packed bow. This is how to program an ATTiny85.

This method uses:
Arduino Uno
USB Cable
Breadboard
Jumpers
4 LEDs
*All items above are available in our Arduino PICO Kit
ATTiny85 Chip
1 x 100 Ohm resistor

Download:

Arduino 1.0 (or newest version)
Update the ArduinoISP Library with the latest version (instructions in readme).
AVRDUDE
Atmel AVR Studio

First you'll want to download the stuff above and install it. The order that it's listed above will be most appropriate.

Then set up your Arduino and breadboard with the chip and jumpers. You'll only need 3 of the LEDs here. They're used to give you the status of the programs you send to the ATTiny chip.

ATTiny85Prog_bb.jpg


Once that's set up you should open your Arduino program and go to File > Examples > Arduino ISP. Click that and it should fill your screen with code. The preamble on the screen tells you what the LEDs on the breadboard to. The one attached to pin 9 is the Heartbeat, pin 10 the Error light and pin 7 the programming light, this will flicker when information is being sent.

You need to send this code to your Arduino. Hopefully you've done this before. If not don't worry, you just need to select your boardtype (Tools > Board) and serial port (Tools > Serial Port). If you don't know what port is being used go to my computer, right click and go to device manager > Ports and you should see one as labelled Arduino Uno (or whatever you're using). Click the arrow button on the Arduino programmer to upload this Sketch (that's what we call an Arduino program) to your Arduino board.

Hopefully the LED attached to the 9 pin will now start beating. We're ready to program. If not we need to start trouble shooting!

Now open your shiny new AVR Studio. Congratulations you are now a programmer. Start a new project and call it Blink, selecting the
"C Executable Project" Cut and Paste the code below.

CodeColon Select all

/*
 * Blink.c
 *
 * Created: 28/02/2012 13:14:10
 *  Author: phenoptix
 */
#include <avr/io.h>

int main(void)
{
   int i;
   DDRB = 0x1F; /*all pins are outputs. DDRB = Port B Data Direction Register
   The Hex code 0x1F translates in binary to 0001 1111 and in this case gives
   the pins as shown in the datasheet as input or output. All are initially input
   and set at 0. Looking at the datasheet for the ATTiny85 really helps in understanding*/
   while(1){
      PORTB = 0x1F; // all LEDs on. Again the Hex defines the state of the Pins. PORTB = Port B Data Register
      for(i = 30000; i > 0; i--); // short delay
      PORTB = 0x00; // all LEDs off
      for(i = 30000; i >0;i--); // another short delay
   }      
   return 0;

}


This is a C code that makes all pins on the ATTiny85 outputs then makes them flash. I had trouble getting any code to work at first and this was the only one I've thus far got working. http://www.dprg.org/tutorials/2011-02a/very-tiny-development.pdf

What Hex code is in binary

CodeColon Select all

0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
A 1010
B 1011
C 1100
D 1101
E 1110
F 1111

I've included that as it helped me understand what I was doing on the chip. You may or may not be interested in learning but that's up to you.

With the code pasted in go to Build > Build Solution. Every time after this go to Build > Rebuild Solution. This will compile the code and give you the all important .hex file.

Now to AVRDude. Cool name eh? Go to the windows button > search and type cmd

This brings up the good old terminal. Now navigate to where your shiny new .hex file is. If you don't know how to navigate you type cd (change directory) and where you want to go. Alternatively you could copy and paste the .hex file into your user directory but you'll have to do this everytime you recompile your code.

Now we want to upload the .hex file using AVRDude. The command used to upload to the ATTiny85 was

CodeColon Select all

avrdude -c arduino -p t85 -P COM5 -b 9600 -U flash:w:Blink.hex


Bit of a note here. Without defining Baud rate it seems to identify the arduino AVR chip as the one to program rather than the ATTiny85. 9600 worked whilst I was writing this tutorial on an R2, however this has since stopped! Now 19200 works on my R3. Don't know why.

Type that and see if it uploads. If you get a message that finishes with avrdude done. Thank you. We may have just been successful.

Now we want to attach the other LED to the board. Like this
ATTiny85Prog2_bb.jpg

It should start to flash. If it does you can remove all the yellow, white and brown connectors so all you've got is power to the chip can you can see that it's flashing on its own.
If it doesn't we need to trouble shoot.

Datasheet for the ATTiny85 can be found here http://www.atmel.com/Images/doc2586.pdf

Some of the resources that helped me get to this stage are:
http://metku.net/index.html?path=articles/microcontroller-part-1/index_eng5
http://www.instructables.com/id/Program-an-ATtiny-with-Arduino/
http://www.ladyada.net/learn/avr/avrdude.html
http://hlt.media.mit.edu/?p=1229

This is still a bit fragmented and bitty but I just wanted to publish it quickly and get it online so others can use. It's still a WIP and no doubt you'll have some problems replicating as I had many and at some points felt like giving up. It's the first part of the Larson / TinyCylon project and it's done. Whoop Whoop.
You do not have the required permissions to view the files attached to this post.

Almurray42
Competent
PostsCOLON 293
JoinedCOLON Wed Jun 30, 2010 11:42 pm
LocationCOLON Bridgwater, Somerset, England
CONTACTCOLON

Re: Programming an ATTiny85 with an Arduino Uno

Postby Almurray42 » Wed Mar 28, 2012 7:48 pm

Getting all my programs ready, But could you clarify the Updating the Arduino ISP? You say the instructions are in tyhe readme but that contains multiple links... don't want to go doing the wrong thing haha! But great tut anyway! Will be using the rest of it soon! :D
Image
[MOD IT] [OR BIN IT]

phenoptix
Competent
PostsCOLON 744
JoinedCOLON Sat Apr 17, 2010 11:25 am

Re: Programming an ATTiny85 with an Arduino Uno

Postby phenoptix » Wed Mar 28, 2012 8:04 pm

It's pretty much a paste over the top job, it can be undone if needed.

Almurray42
Competent
PostsCOLON 293
JoinedCOLON Wed Jun 30, 2010 11:42 pm
LocationCOLON Bridgwater, Somerset, England
CONTACTCOLON

Re: Programming an ATTiny85 with an Arduino Uno

Postby Almurray42 » Wed Mar 28, 2012 8:10 pm

phenoptix wroteColonIt's pretty much a paste over the top job, it can be undone if needed.

Ah right okay, just that big section of code to replace the old one?
Much simpler than I first thought haha!

EDIT: All done! :D
Image
[MOD IT] [OR BIN IT]

Almurray42
Competent
PostsCOLON 293
JoinedCOLON Wed Jun 30, 2010 11:42 pm
LocationCOLON Bridgwater, Somerset, England
CONTACTCOLON

Re: Programming an ATTiny85 with an Arduino Uno

Postby Almurray42 » Wed Mar 28, 2012 8:36 pm

One more thing, hate to be a grammar nazi but i notice you spelled Atmel As Amtel; The m + t being the other way around.
phenoptix wroteColonAmtel AVR Studio
The website spells it as Atmel, and i notice the ATTiny is listed as Amtel...: http://www.phenoptix.com/index.php/amtel-attiny85-8bit-microcontroller.html Just one of those things that you dont notice until someone points it out! :P

EDIT: Another point; if you are looking to download AVR studio 5 but dont want to complete a registration, use this link: http://www.atmel.com/Images/as5installer-stable-5.1.208-small.exe
Image
[MOD IT] [OR BIN IT]

phenoptix
Competent
PostsCOLON 744
JoinedCOLON Sat Apr 17, 2010 11:25 am

Re: Programming an ATTiny85 with an Arduino Uno

Postby phenoptix » Wed Mar 28, 2012 11:58 pm

Seems I had a mental block when putting together the tut and listing (same day, same 20 minutes!). All switched now. Well done on finding the reg-less download.

Almurray42
Competent
PostsCOLON 293
JoinedCOLON Wed Jun 30, 2010 11:42 pm
LocationCOLON Bridgwater, Somerset, England
CONTACTCOLON

Re: Programming an ATTiny85 with an Arduino Uno

Postby Almurray42 » Thu Mar 29, 2012 1:20 am

phenoptix wroteColonSeems I had a mental block when putting together the tut and listing (same day, same 20 minutes!). All switched now. Well done on finding the reg-less download.

Haha okay, though you might wanna know! Had a bit of problem regarding the Visual Studio required for the As5. Will sort it out tomorrow!
Image
[MOD IT] [OR BIN IT]


Return to

Who is online

Users browsing this forum: 1 and 0 guests