Introduction: Program an ATtiny44/45/84/85 With Arduino

Picture of Program an ATtiny44/45/84/85 With Arduino

This tutorial gives provides the steps to set up, program, and test an ATtiny44/45/84/85 with an Arduino. It is also provides some explanations as to the inner workings of AVR chips in general.

Step 1: AVR and ISP Explained

Picture of AVR and ISP Explained

Many tutorials can show you how to do something. I would like to start off by giving a basic explanation as to why you are doing what you are doing.

This process is showing how to use an Arduino Uno as an In-System Programmer or ISP. An ISP allows AVR microcontrollers to be programmed and reprogrammed without having to remove them from the circuit. Programming any AVR microcontroller six wires are needed. Three of these wires are referred to as the Serial Peripheral Interface (SPI) and are the Master In - Slave Out (MISO), Master Out - Slave In (MOSI), and Serial ClocK (SCK). The "Master" is the ISP or the device you are using to program the AVR chip. The "Slave" is the AVR chip being programmed. The other three wires are for the 5V power supply (VCC), Ground (GND), and Reset (RESET).

The images above illustrate which pins on the ATtiny correlate to which function when programming them. The SCK pin is where the Master provides the clock information for communication. Every pulse of the SCK pin sends one bit of data over both the MOSI and MISO pins (this is essentially the ATtiny and Arduino communicating back and forth). The GND pins of both the Arduino and AVR should be connected to help the chips establish the same reference voltage. The RESET pin is the channel to which the Arduino is able to erase the contents on the AVR chip and enable serial programming. The VCC pin is connected to the Arduino simply to remove the need for batteries or external power supplies.

When you come to set up your Arduino to act as an ISP (you will see how to do this later in the tutorial) you are basically informing the Arduino how to format the code and over which pins it should send the data. You can buy 6 pin serial ports to program the AVR chips but if you already have an Arduino than this is a convenient method for you.

Step 2: Parts

Picture of Parts

Needed

Computer

Arduino Uno

ATtiny45 or ATtiny85

Breadboard

Insulated Jumper Cables

10 µF Capacitor

Optional

LED

Resistor (Anywhere from 220 - 330 Ohms)

Step 3: Add Support for ATtiny

Picture of Add Support for ATtiny

First you want to open File > Preferences.

Then, at the bottom of the pop up menu where you see "Additional Boards Manager URLs" you want to copy and paste "https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json" (without the quotation marks).

Now click OK.

Navigate to Tools > Board > Board Manager.

Scroll down to the bottom and you should find "attiny". Click the install button and the words "Installed" should appear when the task is complete.

To confirm that you have added support for the boards, navigate to Tools > Board and you should see ATtiny at the bottom of the list.

Step 4: Setup Arduino As ISP

Picture of Setup Arduino As ISP

Navigate to File > Examples > ArduinoISP. Open the sketch and upload it to your Arduino.

Step 5: Connect Components

Picture of Connect Components

First you will want to connect the 10 μF Capacitor to the Ground and Reset Pins on the Arduino. Make sure the ground side of the capacitor (Typically the side with a silver stripe) goes into the Ground pin on the board. This will help act as a filter and stop the Arduino from resetting itself when programming the ATtiny.

Next place the ATtiny on the breadboard. The gap in the center is made for different Integrated Circuits to be able to span it. Make sure the small dot on the ATtiny is in the top left hand corner as this is how we will be referencing it in the tutorial.

Now we will hook up the jumper wires. Because there can be confusion due to the physical pins being numbered different than the digital output pins, I will be referring to them based on their property (VCC, MISO, GND, etc.) but the graphic above will help remind you which is which.

Pinouts

  • Arduino Pin 13 ---> SCK
  • Arduino Pin 12 ---> MISO
  • Arduino Pin 11 ---> MOSI
  • Arduino Pin 10 ---> RESET
  • Arduino 5V ---> VCC
  • Arduino Ground ---> GND

Step 6: Burn Bootloader (Optional)

Picture of Burn Bootloader (Optional)

This is an additional step that is required if you plan to use the SoftwareSerial Library (though I do this to all of my chips so I don't have to worry about it in the future). The ATtiny runs at 1 MHz by default. You will need to change this to be 8 MHz so that it can communicate with the Arduino at the same frequency.

To do this, first select "Arduino as ISP" under Tools > Programmer.

Select ATtiny from Tools > Board.

Select the specific ATtiny you are using (44/45/84/85) from Tools > Processor.

Next select "8 MHz (Internal)" from Tools > Clock. It is important that you select Internal. Do NOT select "external" as your ATtiny will not work unless you attach an external clock to it (The ATtiny will keep these settings until you explicitly change them).

Finally, select "Burn Bootloader" under tools and wait for it to complete.

Step 7: Upload Code

Picture of Upload Code

Now you can start uploading code.

A good first program to try out your new chip is the Blink program found under examples. You will want to change the pin value to something between 0 - 4. The image above shows you which digital pins correspond to which physical pins. The digital pins are what you will be inputting into Arduino. For this example I made it digital pin zero.

Make sure you have the correct Board, Clock, and Processor selected under the Tools Menu for what you are using. Then hit upload.

Not all functions on Arduino will carry over to the smaller ATtiny chips. Sparkfun provides a good cheat sheet for some basic functions and is attached above.

Step 8: Test ATtiny

Picture of Test ATtiny

To test the ATtiny, attach your resistor and LED in series to the pin you specified in your program. In this case it was digital pin 0 and physical pin 5. Make sure to ground both the ATtiny and your LED. In this case I used the Arduino for both Ground and 5V out of convenience. Once you connect the 5V from the Arduino to the microcontroller it should start blinking (You could also attach this microcontroller to another power supply and add a 5V regulator).

How do you know what resistor you need? Well it is a safe bet that most LEDs will function with a resistor between 220 and 330 ohms (with a higher resistance providing a dimmer light). If you wish to calculate the resistor yourself you would need to use the equation V = IR where V is the difference in voltage between what is supplied and what is used, I is the current drawn by the LED, and R is the resistance of the resistor you would need to make a safe circuit. An example calculation is shown below where 5 volts is provided by the Arduino, 3 V is used by the LED, and 12 mA are drawn by the LED:

V = IR

R = V/I

R = (5 - 3) / (12 / 1000)

R = 166.7 Ohms

It is safe of course to use a resistor that is higher than what was calculated. The value that is calculated is the minimum that is necessary.

I removed the wires used to program the ATtiny from the above pictures to make it easier to see but it is not necessary to test your chip.

Step 9: ATtiny44/84

Picture of ATtiny44/84

To program an ATtiny44 or ATtiny84, follow all the same steps but make sure you hookup the MOSI, MISO, GND, SCK, VCC, and RESET with reference to the image above.

Step 10: References

The creators of this technique and more information on it can be found here.

More information AVR microcontrollers and how ISPs work can be found here.

Comments

subzero69 (author)2016-09-10

A big thank you for this. :D Really helped me to finally program all my tiny's. :)

sharpe351 (author)2016-09-05

Well done instructable. Thanks for sharing!

SoloArduinoM (author)2016-05-09

Are you sure that you should "Burn Bootloader"?

I got an error and I discovered that came for trying to do it. The ATTINY is so small that it seems "to have no space" for Bootloader. I, then, decided to program it uploading the sketch using only Arduino IDE while ATtiny was still wired to Arduino board and works fine.

Bamaan made it! (author)2015-09-05

Thanks for the instructable!

SaipriyaM (author)2015-08-21

i am not able to see attiny in board manager

Maximous (author)SaipriyaM2015-08-21

You first have to install the libraries for the ATtiny. I would re-read Step 3 and look closely at the pictures. If it still doesn't work I would check to make sure you have the latest Arduino version.

SaipriyaM (author)2015-08-21

from past one week i am getting this trouble please somebody help to clear this ... advance thank you

Raphango (author)2015-06-24

Great compilation!

I've had some trouble finding out how to program the Tiny myself and I really appreciate your initiative to teach the others how to do it!

This instructable should be renamed the "Ultimate guide to Program an ATtiny44/45/84/85 with Arduino".

Congratulations!

Maximous (author)Raphango2015-07-04

I was considering a name like that but, having not written the actual libraries for the code, I felt I wouldn't be the best to write an "Ultimate" guide. Thank you so much for your kind words though.

galen (author)2015-07-02

This is really handy. Thanks.

Maximous (author)galen2015-07-04

You're very welcome. Glad I could be of help.