Go Down

Topic: ATtiny pinout leaves me confused. How to call the pins? (Read 2879 times) previous topic - next topic

Peter_I

Mar 08, 2013, 11:15 am Last Edit: May 04, 2013, 10:42 am by Peter_I Reason: 1
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: [Select]

digitalRead(4)

I will read the logic value of PIN# 3 ?

And likewise, if I write:
Code: [Select]

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.
"Nothing is foolproof to a sufficiently talented fool"

Tirmit

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



Coding Badly


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

Coding Badly

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


Yes.

Coding Badly

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


Yes.

Peter_I

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:
"Nothing is foolproof to a sufficiently talented fool"

mrburnette

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: [Select]

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

westfw

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...)

Coding Badly


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.

westfw

Quote
The mapping makes it trivial

Which of course can be particularly important on something like tiny13, where code space is very limited.

scottyjr

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

Go Up