Programming the ATtiny45 / ATtiny85 with Arduino

This tutorial shows you how to program an ATtiny45 or ATtiny85 microcontroller using the Arduino software and hardware. The ATtiny45 and ATtiny85 are small (8-leg), cheap ($2-3) microcontrollers; they are almost identical, except that the ATtiny85 has twice the memory of the ATtiny45 and can therefore hold more complex programs. We like to use both of them with paper circuits and other craft electronics. To program them, we'll use a port of the Arduino core libraries created by Alessandro Saporetti and slightly modified by HLT.

Materials and Tools

For this tutorial, you'll need:

For more information, see our list of materials and parts and our list of prototyping supplies.

Software

You'll need the Arduino software. If you haven't yet, you can download it from the Arduino website. Installation instructions are available for Windows and for Mac OS X.

Installing ATtiny45 / ATtiny85 support:

  • Download: attiny45_85.zip
  • Locate your Arduino sketchbook folder (you can find its location in the preferences dialog in the Arduino software)
  • Create a new sub-folder called "hardware" in the sketchbook folder.
  • Copy the attiny45_85 folder from the attiny45_85.zip to the hardware folder.
  • Restart the Arduino development environment.

Programming the ATtiny45 or ATtiny85

We're going to use the Arduino board to program the ATtiny45 or ATtiny85. Here's the pinout of the ATtiny45 and ATtiny85:

We'll connect the Arduino board to the ATtiny as shown in the following diagram. Use the dot in the corner of the ATtiny to orient it properly.

Then, we'll need to turn the Arduino board into an "in-system programmer" (ISP). To this:

  • Run the Arduino development environment.
  • Open the ArduinoISP sketch from the examples menu.
  • Select the board and serial port that correspond to your Arduino board.
  • Upload the ArduinoISP sketch.

Next, we can use the Arduino as an ISP to upload a program to the ATtiny45/85:

  • Open the Blink sketch from the examples menu.
  • Change the pin numbers from 13 to 0.
  • Select ATtiny45 or ATtiny85 from the Tools > Board menu (leave the serial port set to that of your Arduino board).
  • Upload the sketch.

You'll probably get the following message, but don't worry, the upload should have worked anyway:

avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85
avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85

Now, connect an LED and see if it blinks.

Reference

The following Arduino commands should be supported: