ATTiny 25/45/85/2313 Pin numbers

I have successfully programmed ant ATTiny 45 with my Arduino UNO. Since I am new to the Arduino community I have a couple of questions to ask.

What I don't understand is why the chips physical pin numbers aren't used in the sketch ? When I programmed the Tiny 45, I used phydical pin 5 on the chip but in the sketch it's known as pin 0.

If I wanted to use the ATTINY 2313, ATTiny 84, ATTiny 85, what are the physical chip pins known as in the sketch ?

Which core(s) are you using?

first time posting :smiley:

found this “cheatsheet” ( with pinouts of some atmel micros (pin 5 in attiny x5 shows as pb0) hope you can use it.

please sorry for my english, it’s not my main language.

If you are using this core: You can find the pin numbers in the file core_pins.h

Fx for Attiny 2313:

#define PIN_D0  ( 0)
#define PIN_D1  ( 1)
#define PIN_A1  ( 2)
#define PIN_A0  ( 3)
#define PIN_D2  ( 4)
#define PIN_D3  ( 5)
#define PIN_D4  ( 6)
#define PIN_D5  ( 7)
#define PIN_D6  ( 8)
#define PIN_B0  ( 9)
#define PIN_B1  (10)
#define PIN_B2  (11)
#define PIN_B3  (12)
#define PIN_B4  (13)
#define PIN_B5  (14)
#define PIN_B6  (15)
#define PIN_B7  (16)
#define PIN_A2  (17)  /* RESET */

Thanks for the replies.

However, I still don't understand why the physical pin numbers of these chips aren't used in the sketch like they are if you are using the 328 on the main Arduino board ?

powertek: Thanks for the replies.

However, I still don't understand why the physical pin numbers of these chips aren't used in the sketch like they are if you are using the 328 on the main Arduino board ?

look at the "cheatsheet" attached in my last reply, in the arduino board the pins are already labeled and traced to the headers so atmega328 physical pin 19 is Digital 13 in the board, , (try looking at the front of the arduino pcb board and trace physical pin 28 to A5, that's the best way to "understand" the layout)....

p.d.: im a newbie too in this, sorry if i misunderstood something....

Thanks charlie_dream now I understand. We aren't using the actual pin numbers of the chip itself. We're using the pin 'function'. In the case of the ATTiny 45, physical pin 5 is PB0. Therefore we're referencing 0 (zero) like digitalWrite(0, HIGH); zero referring to PB0 of the chip.

Duh on me. I guess I need to read a little better. LOL


We've updated the cheat sheet that was mentioned earlier in this post to include Arduino-tiny pinouts for the ATTiny2314/4313 as well as ATTiny25/45/85.

If you are interested, it can be downloaded here:

Thanks karl_b. Really useful cheatsheet.

BTW, there’s another easy way to check the pin-out and logical pin numbers…

Go to “My Documents/Arduino/hardware/tiny/cores/tiny” and open the file “pins_arduino.c” and one can find nice ASCII text description of the pins, like this in comments…

//                   +-\/-+
//      (D 17) PA2  1|    |29  VCC
// RX   (D  0) PD0  2|    |19  PB7 (D  16)
// TX   (D  1) PD1  3|    |18  PB6 (D  15)
//      (D  2) PA1  4|    |17  PB5 (D  14)
//      (D  3) PA0  5|    |16  PB4 (D  13)*
// INT0 (D  4) PD2  6|    |15  PB3 (D  12)*
// INT1 (D  5) PD3  7|    |14  PB2 (D  11)*
//      (D  6) PD4  8|    |13  PB1 (D  10)
//     *(D  7) PD5  9|    |12  PB0 (D  9)
//             GND 10|    |11  PD6 (D  8)
//                   +----+
// * indicates PWM port

// these arrays map port names (e.g. port B) to the
// appropriate addresses for various functions (e.g. reading
// and writing)

In a browser, due to usage of proportional fonts, it might not look great, but in a text-editor with fixed-width fonts, it’s just fine.

Yeah, that's a very nice diagram too. In fact, we used it along with the description in core_pins.h as a reference when we updated the cheat sheet.

PS: D17 isn't directly usable, since it is the RESET pin and needs to be remapped by changing fuses to function as a normal digital port. The same goes for D5 in the ATTinyX5 (but we left it in the diagram, since it is also assigned to analog port A0).

@karl_b: Asterisks indicate PWM pins?

[quote author=Coding Badly link=topic=82951.msg675717#msg675717 date=1328206766] @karl_b: Asterisks indicate PWM pins? [/quote]

Yes :)

I see that it is not so clear in the cheat sheet, will update it with an additional note. Thanks!

You have one too many for the X5 family and two too many for the 13. Let’s see… PB3 needs to be excluded for the X5 family. PB3 and PB4 need to be excluded for the 13.

There is a note in the cheat sheet that says "ATTiny13 has PWM only on PB0 and PB1"

As for ATTinyX5, PB3 and PB4 can both output PWM, but they are not independent (see page 89 in the full datasheet: PB3 can be set to output the inverse of PB4). I suppose that information could be added to the note, if I can figure out a concise way of writing it :)

Check the diagram in the datasheet. The "PB" numbers will be the correct ones, not the physical pin numbers. Realistically, this makes sense, for example VCC and GND can not be I/O pins.

In that case, I misunderstood the purpose of the cheat-sheet. I assumed it was meant to document pin mappings for Arduino compatible cores.

You didn't misunderstand: The new version of the cheat sheet was meant to do exactly that: For example, physical pin 11 on the ATTiny2313/4313 is PD6 (when programming in low-level avr-gcc) and is assigned to Arduino pin number 8: This is written as PD6/D8 in the cheat sheet.

In that case, PB3 needs to be excluded for the X5 family. As far as I know, no Arduino compatible cores make use of inverted PWM outputs.

You won't be able to use the inverted PWM for Arduino, but the sheet covers both Arduino pin numbers and normal port numbers (that's why it says D3/PB3). That said, there should be a note saying that PB3 is a "special" PWM pin.

Hey Karl_B thanks for this cheat sheet, looks great. Wonder if you could also include attiny84 ?