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