Arduino Forum

Using Arduino => Microcontrollers => Topic started by: powertek on Dec 13, 2011, 08:13 am

Title: ATTiny 25/45/85/2313 Pin numbers
Post by: powertek on Dec 13, 2011, 08:13 am
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 ?

 
Title: Re: ATTiny 25/45/85/2313 Pin numbers
Post by: Coding Badly on Dec 13, 2011, 08:48 am

Which core(s) are you using?
Title: Re: ATTiny 25/45/85/2313 Pin numbers
Post by: charlie_dream on Dec 13, 2011, 01:53 pm
first time posting :D

found this "cheatsheet" (akafugu.jp) 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.



Title: Re: ATTiny 25/45/85/2313 Pin numbers
Post by: Erni on Dec 13, 2011, 04:16 pm
If you are using this core:

http://code.google.com/p/arduino-tiny/
You can find the pin numbers in the file core_pins.h

Fx for Attiny 2313:

Code: [Select]

#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 */


Title: Re: ATTiny 25/45/85/2313 Pin numbers
Post by: powertek on Dec 13, 2011, 04:32 pm
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 ?
Title: Re: ATTiny 25/45/85/2313 Pin numbers
Post by: charlie_dream on Dec 13, 2011, 04:57 pm

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....
Title: Re: ATTiny 25/45/85/2313 Pin numbers
Post by: powertek on Dec 13, 2011, 05:55 pm
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
Title: Re: ATTiny 25/45/85/2313 Pin numbers
Post by: karl_b on Feb 02, 2012, 03:25 pm
Hi,

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:
http://fb.me/1sv07S3Pj
Title: Re: ATTiny 25/45/85/2313 Pin numbers
Post by: falcon74 on Feb 02, 2012, 03:38 pm
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...

Code: [Select]

// ATMEL ATTINY2313
//
//                   +-\/-+
//      (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.
Title: Re: ATTiny 25/45/85/2313 Pin numbers
Post by: karl_b on Feb 02, 2012, 04:01 pm
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).
Title: Re: ATTiny 25/45/85/2313 Pin numbers
Post by: Coding Badly on Feb 02, 2012, 07:19 pm

@karl_b: Asterisks indicate PWM pins?
Title: Re: ATTiny 25/45/85/2313 Pin numbers
Post by: karl_b on Feb 03, 2012, 05:37 am

@karl_b: Asterisks indicate PWM pins?


Yes :)

I see that it is not so clear in the cheat sheet, will update it with an additional note. Thanks!
Title: Re: ATTiny 25/45/85/2313 Pin numbers
Post by: Coding Badly on Feb 03, 2012, 06:21 am

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.
Title: Re: ATTiny 25/45/85/2313 Pin numbers
Post by: karl_b on Feb 03, 2012, 07:19 am
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 :)
Title: Re: ATTiny 25/45/85/2313 Pin numbers
Post by: smeezekitty on Feb 03, 2012, 07:46 am
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.
Title: Re: ATTiny 25/45/85/2313 Pin numbers
Post by: Coding Badly on Feb 03, 2012, 07:48 am

In that case, I misunderstood the purpose of the cheat-sheet.  I assumed it was meant to document pin mappings for Arduino compatible cores.
Title: Re: ATTiny 25/45/85/2313 Pin numbers
Post by: karl_b on Feb 03, 2012, 08:57 am
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.
Title: Re: ATTiny 25/45/85/2313 Pin numbers
Post by: Coding Badly on Feb 03, 2012, 09:08 am

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.
Title: Re: ATTiny 25/45/85/2313 Pin numbers
Post by: karl_b on Feb 03, 2012, 12:37 pm
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.
Title: Re: ATTiny 25/45/85/2313 Pin numbers
Post by: paulcardno on Feb 05, 2012, 10:43 pm
Hey Karl_B
thanks for this cheat sheet, looks great. Wonder if you could also include attiny84 ?
Title: Re: ATTiny 25/45/85/2313 Pin numbers
Post by: karl_b on Feb 06, 2012, 01:34 am
Thanks kermit,

attiny84 and attiny87/167 are on our TODO list. :)
Title: Re: ATTiny 25/45/85/2313 Pin numbers
Post by: karl_b on Feb 07, 2012, 04:06 am
Good news, we have now added ATTinyX4 as well to the cheat sheet, you can find the updated version here: http://www.akafugu.jp/posts/resources/reference-sheet/
Title: Re: ATTiny 25/45/85/2313 Pin numbers
Post by: Coding Badly on Feb 07, 2012, 04:34 am

Nice.  Thank you.

I have a suggestion: use ", " (comma space) instead of "/" (slash) to separate the labels.  It's a little difficult to locate a pin from its function (like MISO).
Title: Re: ATTiny 25/45/85/2313 Pin numbers
Post by: karl_b on Feb 07, 2012, 04:53 am
Thanks for the suggestion, we'll try it out and see how it looks
Title: Re: ATTiny 25/45/85/2313 Pin numbers
Post by: balam on Mar 06, 2012, 09:53 pm
Great post.
do you guys know what is the analog input pin numbers on the  2313
been reading the datasheet  and can not find it.

thanks

Title: Re: ATTiny 25/45/85/2313 Pin numbers
Post by: Coding Badly on Mar 06, 2012, 10:45 pm

For the analog comparator or the analog-to-digital converter?
Title: Re: ATTiny 25/45/85/2313 Pin numbers
Post by: balam on Mar 06, 2012, 10:55 pm
more like Analog input/ Sensor input
Title: Re: ATTiny 25/45/85/2313 Pin numbers
Post by: balam on Mar 06, 2012, 11:26 pm
I  guess the analog is the PB0/AIN0/D9

I have been trying to get the  analog input to work with a sensor
how is set this pin to be a alaog input

see sketch

Code: [Select]
///////////////////

int sensPin=PB0; //  analog  input  for  2313
int sensVal=0; //  value





int ledPin = 1; // The pin number of the LED  
int ledPin7 = 7;


//////SETUP////////

void setup() {
pinMode( ledPin, OUTPUT ); // Sets the led pin to an output mode
pinMode( ledPin7, OUTPUT );
// pinMode( sensPin, INPUT );

// Serial.begin(57600); //set Serial Data flow / debug/ read

}



///LOOP///////////

void loop() {
 
 digitalWrite(ledPin7, HIGH);
 
 
sensVal = analogRead(sensPin); // READS sensor,  




if( sensVal > 350 )            // object is close to sensor??
{
 
 

   
      digitalWrite( ledPin, HIGH ); //Turn  LED pin on
    }
   
   
   
    if( sensVal < 450 )
{
 
 

   
      digitalWrite( ledPin, LOW); //
    }
   
   
   
  }



Moderator edit: [code] [/code] tags added.
Title: Re: ATTiny 25/45/85/2313 Pin numbers
Post by: Coding Badly on Mar 06, 2012, 11:41 pm
more like Analog input/ Sensor input


An analog-to-digital converter.  The 2313 does not have one.
Title: Re: ATTiny 25/45/85/2313 Pin numbers
Post by: Coding Badly on Mar 06, 2012, 11:44 pm
I  guess the analog is the PB0/AIN0/D9


That is one of the two inputs to the analog comparator. 

Code: [Select]
sensVal = analogRead(sensPin); // READS sensor,  

If you are using this core...
http://code.google.com/p/arduino-tiny/
...zero is always returned.
Title: Re: ATTiny 25/45/85/2313 Pin numbers
Post by: balam on Mar 06, 2012, 11:49 pm

I  guess the analog is the PB0/AIN0/D9


That is one of the two inputs to the analog comparator. 

Code: [Select]
sensVal = analogRead(sensPin); // READS sensor, 

If you are using this core...
http://code.google.com/p/arduino-tiny/
...zero is always returned.





Thank you.

yes  I am using  this cores

http://code.google.com/p/arduino-tiny/


you mean that analog input does not work?

on the   core pin s file
seems like there is analog port  as  PIN_A0  (3)
been trying to read a sensor and turn an led but doe snot work
any help is really apreciated ,  how can I read a sensor   from this  2313 chip.

thanks
Title: Re: ATTiny 25/45/85/2313 Pin numbers
Post by: Coding Badly on Mar 07, 2012, 12:10 am
Quote
you mean that analog input does not work?


The processor does not have an analog-to-digital converter (ADC).  So, yes, analog input does not work.

Quote
how can I read a sensor   from this  2313 chip.


Two things come to mind...

1. Add an external ADC.

2. Atmel has a whitepaper describing how to mimic an ADC using the analog comparator.  It requires some external components (I think two).  If you're interested, I'll try to find a link.
Title: Re: ATTiny 25/45/85/2313 Pin numbers
Post by: balam on Mar 07, 2012, 12:33 am
THANK  you.

I been  editing the  core pins
but now that you are saying that analog input is not supported 

yea I will be interested in find out how to add a sensor
Title: Re: ATTiny 25/45/85/2313 Pin numbers
Post by: Coding Badly on Mar 07, 2012, 01:35 am

http://arduino.cc/forum/index.php/topic,92864.msg700430.html#msg700430
Title: Re: ATTiny 25/45/85/2313 Pin numbers
Post by: funkyguy4000 on Mar 07, 2012, 11:35 pm
buuuummmppp
Title: Re: ATTiny 25/45/85/2313 Pin numbers
Post by: Coding Badly on Mar 07, 2012, 11:37 pm

Why are you bumping this topic?
Title: Re: ATTiny 25/45/85/2313 Pin numbers
Post by: Arduino_User49502 on Sep 10, 2015, 05:17 am
smeezekitty, do you assign thepins by the PB# or just # in the code.
Title: Re: ATTiny 25/45/85/2313 Pin numbers
Post by: DrAzzy on Sep 10, 2015, 10:24 am
smeezekitty, do you assign thepins by the PB# or just # in the code.
You use the numbers to refer to the pins in your code

Please don't bump three-year-old threads.