In the effort to understand building projects around the ATtiny84, I started first with the Arduino Uno and followed the steps to "Shrinkify" it onto the ATtiny85. From there, assuming I understand the terminology and pins for the ATtiny85, I can progress to the ATtiny84 and take advantage of more I/O pins. I've been reading both datasheets and consulting as many online references and forum posts as I could find. The core I'm using is from Google Code Archive - Long-term storage for Google Code Project Hosting..
My pilot project for learning has been a simple TMP36 temp sensor & RGB fading blink program that uses four analog pins, three for output and one for input. Very straightforward on the Uno. For the ATtiny85, I use the following pin assignments which works well:
const int inPin = 3; // analog in, to ADC3 for temp sensor, pin 2 on ATtiny85
const int redPin = 0; // analog out, to PB0 for red LED, pin 5 on ATtiny85
const int bluePin = 1; // analog out, to PB1 for blue LED, pin 6 on ATtiny85
const int greenPin = 4; // analog out, to PB4 for green LED, pin 3 on ATtiny85
My understanding is that when I assign "1" to variable bluePin on analog output, I'm really referring to "PB1" and from the ATtiny85 datasheet, that corresponds to physical pin 6. A similar definition on an analog input refers to the ADC pin, so you look up what pin that corresponds to. Also understood is that on the datasheet, OC refers to Output Compare, a bar over the label refers to inverted output (Coding Badly says don't concern myself with those), and ADC is the analog-to-digital cerverter pins.
Now, following this logic doesn't seem to work on the ATtiny84, and I'm uncertain why. My questions will be based on the following code, which only runs the blink part of it (omitting the temp sensor for now) using these assignments (plus some trial & error):
const int redPin = 2; // analog out, to PB2 for red LED, pin 5 on ATtiny84
const int bluePin = 3; // analog out, to PA7 for blue LED, pin 6 on ATtiny84 <== why does this work?
const int greenPin = 5; // analog out, to PA5 for green LED, pin 8 on ATtiny84
void setup() {
pinMode(bluePin, OUTPUT);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
}
void loop() {
GlowLightOnce(bluePin);
GlowLightOnce(greenPin);
GlowLightOnce(redPin);
delay(2000);
}
void GlowLightOnce(int bulb) {
int brightness = 0;
int fadeAmount = 5;
int totalcount = 0;
do {
analogWrite(bulb, brightness);
brightness += fadeAmount;
totalcount++;
if (brightness = 255) {
fadeAmount = -fadeAmount;
}
delay(35);
}
while (totalcount < 103);
delay(500);
}
References I used besides the datasheets:
- Unofficial Arduino & ATtiny pinout diagrams from www.pighixxx.com
- A diagram on ATtiny84 Pin Layout for the arduino-tiny core | arduino-tiny… | Flickr
QUESTIONS:
- While the redPin and greenPin assignments make sense, I honestly don't know why setting bluePin = 3 sends the signal out physical pin 6. Yet it works! Are my pinout diagrams inaccurate?
- If I were to call pinMode(0,OUTPUT), does that refer to PA0 or PB0? I'm unclear on what physical pin I'd use.
- Is PA0 through PA7 strictly for analog I/O, and PB0 through PB3 for digital I/O? What goes into choosing PA# over PB#?
Thanks,
Tom