Using the ATTiny85 instead of the UNO

Programming the ATTiny85, Arduino Style
by Thatcher
This is a sort of a continuation of the last post. In the last post,
I showed how to load the ATTiny85 cores into the Arduino IDE.
If that worked for you, cool! This how to actually program the chip. 
If it didn't work... put a comment somewhere. I'll try to help.
Anyway, programming the ATTiny is very easy. 
The only thing you really need to do is set up a target board. 
This is either a breadboard, perfboard, or PCB circuit that interfaces 
the ATTiny to an Arduino board. The circuit should have
these connections:

This is called ISP circuit. The chips communicate over
SPI via this configuration.


What this circuit does is connect the ATTiny to power and ground,
but it also has four wires for communication. It does this using a 
protocol called SPI. The four connections are SCK (clock), 
MISO and MOSI (communication), and Reset (resets the chips 
when it is done). That circuit connects the SCK, MISO, and MOSI pins
of both chips to the corresponding one on the other chip. 

The reset pins of the two chips are not connected, however. 
The Master (Arduino in this case) has a digital pin connected to the 
actual reset pin of the slave (ATTiny85). On the Arduino Uno and 
Duemilanove (and some other ones of the same shape), SCK is pin 13,
MISO pin 12, MOSI pin 11, and reset pin 10. The ATTiny85 pinout is below.

ATTiny85 pinout, showing the uses of all the pins.

The breadboard programmer above isn't the only way making
a target board.I made one out of a small piece of perf board, 
a DIP 8 socket, a five-pin header, and a bunch of wires.

That one wire that shoots off in both pictures is going to power.

It is is the same circuit as the breadboard, only more permanent. 
Same connections, though.

Actually Programming the Chip
Once you have one of these target boards, either on a breadboard or
perfboard (or something else), we can actually program it. 
The first thing to do is upload the ArduinoISP sketch onto
the Arduino board. You find it here:

File/Examples/Arduino ISP

And then upload it. What it does is a couple of things: the first thing it 
does is emulate an AVRISP programmer. The computer asks what
it is, and it says it is a AVR programmer instead of a more
generic serial device.

The computer sends it the program (in hexadecimal form) and then it 
goes to its second function. It loads the program hex file onto the 
other chip via SPI and then relays whether or not the operation 
worked to the computer.

So connect your target board, make sure everything is connected,
and (IMPORTANT!) set the Tools/Board Menu to ATtiny85
(w/ Arduino as ISP). Note: you may have to put a 110 ohm resistor
between reset and power on the Arduino board. Then you can upload
your program. I used this one. It is for the board that I fixed in the
last post!

int toast = 0;

void setup(){
  pinMode(0, OUTPUT);
  pinMode(1, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  PORTB = B0000100;


0 - H
1 _ H
2 - L
3 - H


void loop(){
  PORTB = B0001011;
  toast = int(random(4));
  for(int i = 0; i <= int(random(5,12)); i++){
    delay(int(random(30, 60)));
    digitalWrite(toast, LOW);
    digitalWrite(toast, HIGH);
    PORTB = B0001011;

That should do it. You'll get this message in the bottom window:

If another set of text appeared, something is wrong. Here is a 
good site for finding out what the errors mean. Otherwise just
Google it. Now you can test the chips on a breadboard or a
PCB or something... I really hope this helps people. I just
love the ATTiny chips because they're so small yet can still
do many of the same things as a normal Arduino. Remember,
though, not every function works.