ATTiny 45/85 Pin Conventions for Arduino IDE Sketches

The main source for information on how to program the ATTiny using the Arduino IDE is found at the MIT High-Low Tech site. But I found the information on the pinouts rather opaque for the newbie (= me), so as an aid to myself I made the following chart for the ATTiny 45 and 85 (which are the eight-pin versions):

attiny pinouts

Inside the above chip illustrations are the physical pin numbers, running counter clockwise 1 through 8 starting from the little circle which appears on the chip casing. You would use these numbers as reference for physically connecting the ATTiny to a circuit, but they are irrelevant to the Arduino IDE.

As for detailed information on how the various pin functions work, I recommend visiting the Arduino Language Reference page. But here I’ll summarize some of the peculiarities of the ATTiny regarding the usage of said functions.

Unlike the ATMega328 chip, the ATTiny needs only one pin connected to the voltage source and only one pin to ground. The reset pin will restart your program when it is connected to ground and then released. The reset pin can also be reprogrammed as an IO pin, but that’s outside the scope of this discussion.

In Adruino IDE software, the ATTiny pins can do double duty as either analog or digital. As you can see, they have different numbering conventions depending on whether you are using analog or digital functions. This is confusing but it does allow for flexibility.

To use a pin as an analog input, you simply use the analogRead() function, referencing the respective analog pin number.

To use a pin in digital mode, you must first use the pinMode() function, referencing the digital pin number and specifying whether you want to use INPUT or OUTPUT mode. Then you can use the other digital pin functions.

(As you may have noticed, you didn’t need to specify pinMode() when using analogRead(). When a pin can be used as either analog or digital, analog is the default.)

You may wonder why analogWrite() is down on the lower table with the digital pin functions. It’s because analogWrite() isn’t really an analog pin function, instead it’s used for pulse width modulation of the digital output signal. Thus you use it with the digital pin numbering convention. As the tilde mark (the ‘~’) indicates, only the two pins in the lower right are PWM capable. As it happens, these pins don’t have an analogRead() capability. Perhaps some sort of internal circuitry tradeoff is involved with that. Interesting.

I’m new to the ATTiny, so I wouldn’t be surprised if there are errors. Corrections are appreciated and the chart will be updated accordingly. I realize that there is stuff that I’m omitting, like what is SCK or MISO or MOSI, but I figure I have to start somewhere.

(NOTE: The ATTiny45/85 chip prices offered on Amazon are reasonable if you’re in a hurry or just want one or two. Otherwise it’s recommended that you shop around.)



About engineerzero

Once and future engineer.
This entry was posted in Uncategorized and tagged , , , , . Bookmark the permalink.

4 Responses to ATTiny 45/85 Pin Conventions for Arduino IDE Sketches

  1. Adan says:

    For using the Arduino as ISP, what would a sample code look like (say digitalWrite) for the PWM pins? I’m using an Uno to program an ATTiny45, but I’m no clue where to start with the PWN pins.

    • engineerzero says:

      I know it’s a bit confusing, but the complete instructions are in the blog entry. I’ll paraphrase here in the hopes that it’ll become clearer.

      To use PWM, do the following:

      1. Select either digital pin 0 or 1 for PWM (see digital pin convention diagram). Note that these are your only two choices for PWM on the chip.
      2. Set pin to digital output mode.
      3. Use the analogWrite() function (yes, *analogWrite()* even though the pin is in digital mode).
      4. Set the PWM value at 0 for 0% to 255 for 100%.

      Let’s say that I want to set digital pin 1 at 50% duty cycle. The commands would be:


      You may have to put pinMode() in the setup() function. Remember to refer to the DIGITAL pin convention diagram as shown in the blog entry.

      You only have to set pinMode() once, and then you can change the PWM duty cycle value as much as you please (memory space permitting).

  2. Pingback: ATtiny Programming[References] | SonusDigito

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s