Pages: [1]   Go Down
Author Topic: ATtiny pinout leaves me confused. How to call the pins?  (Read 2256 times)
0 Members and 1 Guest are viewing this topic.
Denmark
Offline Offline
Full Member
***
Karma: 10
Posts: 220
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

When I look at the pinout for the tinies, i get confused.
(I found a little about it on the forum: http://arduino.cc/forum/index.php/topic,124139.15.html and it helped in some respect, but also raised me to a higher level of confusion).

Not wanting to redefine the reset-pin, that leaves me with 5 available pins, DIP# 2, 3, 5, 6 and 7.

That looks nice anyway!
- Analog in on DIP# 2, 3, and 7
- Digital in/out on DIP# 2, 3, 5, 6 and 7
- Out with possibility of PWM on DIP# 2, 3, 5 and 6

But how do I call them?

If I write:
Code:
digitalRead(4)
I will read the logic value of PIN# 3 ?

And likewise, if I write:
Code:
analogRead(2)
I will read the analog value of PIN# 3 ?

In other words: There are several possibilities from the processor connected to a limited number of pins. I can't use them all at the same time, but by telling the processor what I want to do, it will give me that?

I know it is a microcontroller-noobish question, but it has kept me wondering for some time.


* tiny pinout.jpg (77.13 KB, 691x405 - viewed 268 times.)
« Last Edit: May 04, 2013, 03:42:00 am by Peter_I » Logged

Bob Pease: "My favorite programming language is ... solder."

Offline Offline
Newbie
*
Karma: 0
Posts: 37
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
i don't really understand you question, but :
Quote
If I write:
Code:

digitalRead(4)

I will read the logic value of PIN# 3 ?
-> yes, it is going to return "HIGH" or "LOW"

Quote
And likewise, if I write:
Code:

analogRead(2)

I will read the analog value of PIN# 3 ?
-> i think that, if it is not a analog pin, it can't work


Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 200
Posts: 12779
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


The A# labels are for analogRead and the D# labels are for the digital functions where # is the parameter you pass to the function.

From the datasheet, ADC# labels are for analogRead and PB# labels are for the digital functions
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 200
Posts: 12779
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
If I write... digitalRead(4) ...I will read the logic value of PIN# 3 ?

Yes.
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 200
Posts: 12779
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
And likewise, if I write... analogRead(2) ...I will read the analog value of PIN# 3 ?

Yes.
Logged

Denmark
Offline Offline
Full Member
***
Karma: 10
Posts: 220
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks to all of you.

It was the possibility of having several different numbers referring to the same pin, but doing different things that had me wondering.("wondering" sounds better than "having an empty look in the eyes and driveling")

I know the arduino has several functions on the same pin, but the number stays the same.
 smiley-red
Logged

Bob Pease: "My favorite programming language is ... solder."

Atlanta, USA
Offline Offline
Edison Member
*
Karma: 53
Posts: 1777
AKA: Ray Burne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There are several variants out on the Net for the ATtiny uC's.  I have always found it safe to just peek into the particular implementation that I am using at the time.... for example:
https://github.com/damellis/attiny/blob/master/attiny/variants/tiny8/pins_arduino.h

Looking down the listing, you see how David mapped the pins:
Code:
// ATMEL ATTINY45 / ARDUINO
//
//                  +-\/-+
// Ain0 (D 5) PB5  1|    |8  Vcc
// Ain3 (D 3) PB3  2|    |7  PB2 (D 2)  Ain1
// Ain2 (D 4) PB4  3|    |6  PB1 (D 1) pwm1
//            GND  4|    |5  PB0 (D 0) pwm0
//                  +----+

Ray
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 124
Posts: 6653
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So...
The numbers you use in digitalWrite() are more like the "names" given to the pins.
You can change the names however you want, in the pins_arduino.h and associated files for that "variant."

In this case, it looks like the pins were "named" based on their bit position in the port.  "0" is bit 0 of portB,
"1" is bit 1, and so on (there is only portb.)  This makes a lot of sense from a technical and implementation point of view.  But I always thought that naming the pins after what made sense from a USER point of view was one of the smart things that was done in Arduino; so it might be better if the names matched the pin numbers of the chip instead (so "4" wouldn't work, being the GND pin...)
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 200
Posts: 12779
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


For the ATtiny85 (8-pin processors) I used "bit numbering" for four reasons...

1. Historical.  Others (e.g. Alessandro Saporetti) before me had used that assignment.  I wanted the Tiny Core to be a drop-in replacement for existing cores.

2. Convenience / sanity.  It eliminates the tedious step of translating when referring to the datasheet.  PB0 (datasheet reference) is digital pin 0 (Arduino reference).  PB1 is digital pin 1.  Etcetera.

3. Uniformity.  The m328 mapping forms a U around the processor.  The t85 mapping (almost) forms an inverted U around the processor.

4. Performance.  The mapping makes it trivial to implement digital*Fast functions.
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 124
Posts: 6653
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The mapping makes it trivial
Which of course can be particularly important on something like tiny13, where code space is very limited.
Logged

Pottstown, PA
Offline Offline
Sr. Member
****
Karma: 5
Posts: 317
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Perhaps you have not come across this thread. Great job on pinouts of some of the popular Atmel AVR microcontrollers. - Scotty
Logged

Pages: [1]   Go Up
Jump to: