This post contains a collection of links, notes and references related to programming the ATtiny 45 & 84 chips using the arduino language.

Getting Started…
David Mellis has posted some great tutorials on how to turn an Arduino board into an ISP programmer and use it to program bare microcontrollers such as the ATtiny85.
Getting started with AVR programming >> http://hlt.media.mit.edu/wiki/pmwiki.php?n=Main.AVRProgramming
Advanced AVR programming >> http://hlt.media.mit.edu/wiki/pmwiki.php?n=Main.AVRProgrammingAdvanced
From Arduino to a Microcontroller on a Breadboard >> http://arduino.cc/en/Tutorial/ArduinoToBreadboard

Using FabISP and Arduino IDE for programming ATtiny45 and 85s (Notes to self)
Edit the boards.txt file in the Arduino application folder!
>> http://fab.cba.mit.edu/content/projects/fabkit/
>> http://fab.cba.mit.edu/classes/MIT/863.09/people/mellis/fabisp/index.html
>> http://fab.cba.mit.edu/content/projects/fabisp/
>> http://fab.cba.mit.edu/content/tools/microcontrollers/compiling.html
>> http://hlt.media.mit.edu/wiki/pmwiki.php?n=Main.ArduinoATtiny4585
forum answer >> http://arduino.cc/forum/index.php/topic,70841.0.html
Setting Registers on ATtiny45 and 85
To change the clock speed of an ATtiny type the following into your terminal:
If you are using the MKII programmer:
avrdude -p t85 -c avrispmkii -P usb -U lfuse:w:0xe2:m
If you are using Dave’s fab isp progammer:
avrdude -p t85 -c usbtiny -U lfuse:w:0xe2:m
Also see this fuse calculator website to see where we got the settings from:
>> http://www.engbedded.com/fusecalc/
Dave Mellis’s Touch code that does capacitive sensing on the ATtiny
ATtiny touch code from Dave Mellis >> http://hlt.media.mit.edu/?p=1653

Software Seiral on ATtiny
#include
SoftwareSerial mySerial(0, 1); // RX, TX
void setup()
{
// set the data rate for the SoftwareSerial port
mySerial.begin(4800);
mySerial.println(“Hello, world?”);
pinMode(3, INPUT_PULLUP);
}
void loop() // run over and over
{
int sensorValue = analogRead(3);
mySerial.println(sensorValue);
}
Software PWM on the ATtiny
More >> http://www.kobakant.at/DIY/?p=3393

Leah Buechley’s sound code that will run on an ATtiny (because it does not use the tone() library)
Taken from >> http://web.media.mit.edu/~leah/lilypad/07_sound.html

// using leah buechley’s sound code, taken from: http://web.media.mit.edu/~leah/LilyPad/07_sound_code.html
int sensorPin = 2;
int speakerPin = 3;
int LED0 = 0;
int LED1 = 1;
int LED2 = 2;
int reading;
int count = 0;
int threshold = 850;
int LEDstate = 0;
int SENSORstate = 0;
int previousSENSORstate = 0;
int SENSORgo = 0;
void setup()
{
pinMode(sensorPin, INPUT);
digitalWrite(4, HIGH);//sensorPin
pinMode(speakerPin, OUTPUT);
pinMode(LED0, OUTPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
digitalWrite(LED0, HIGH);
digitalWrite(LED1, HIGH);
digitalWrite(LED2, HIGH);
}
void loop() {
reading = analogRead(sensorPin);
SENSORstate = reading/(threshold/8);
if(SENSORstate == previousSENSORstate) SENSORgo = 0;
else SENSORgo = 1;
if(SENSORstate == 0 && SENSORgo == 1) scale(‘C’);
if(SENSORstate == 1 && SENSORgo == 1) scale(‘D’);
if(SENSORstate == 2 && SENSORgo == 1) scale(‘E’);
if(SENSORstate == 3 && SENSORgo == 1) scale(‘F’);
if(SENSORstate == 4 && SENSORgo == 1) scale(‘G’);
if(SENSORstate == 5 && SENSORgo == 1) scale(‘A’);
if(SENSORstate == 6 && SENSORgo == 1) scale(‘B’);
if(SENSORstate == 7 && SENSORgo == 1) scale(‘H’);
previousSENSORstate = SENSORstate;
if(reading < threshold && LEDstate == 0){
count++;
LEDstate=1;
}
if(count == 1 && LEDstate == 1) {
digitalWrite(LED0, HIGH);
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
}
if(count == 2 && LEDstate == 1) {
digitalWrite(LED0, LOW);
digitalWrite(LED1, HIGH);
digitalWrite(LED2, LOW);
}
if(count == 3 && LEDstate == 1) {
digitalWrite(LED0, LOW);
digitalWrite(LED1, LOW);
digitalWrite(LED2, HIGH);
}
if(count == 4 && LEDstate == 1) {
digitalWrite(LED0, HIGH);
digitalWrite(LED1, HIGH);
digitalWrite(LED2, HIGH);
}
if(count > 4) count = 1;
if(reading > threshold) LEDstate = 0;
}
void scale (char note)
{
if(note == ‘C’)
beep(speakerPin,2093,500); //C: play the note C (C7 from the chart linked to above) for 500ms
if(note == ‘D’)
beep(speakerPin,2349,500); //D
if(note == ‘E’)
beep(speakerPin,2637,500); //E
if(note == ‘F’)
beep(speakerPin,2793,500); //F
if(note == ‘G’)
beep(speakerPin,3136,500); //G
if(note == ‘A’)
beep(speakerPin,3520,500); //A
if(note == ‘B’)
beep(speakerPin,3951,500); //B
if(note == ‘H’)
beep(speakerPin,4186,500); //C
}
void beep (unsigned char speakerPin, int frequencyInHertz, long timeInMilliseconds) // the sound producing function
{
int x;
long delayAmount = (long)(1000000/frequencyInHertz);
long loopTime = (long)((timeInMilliseconds*1000)/(delayAmount*2));
for (x=0;x
digitalWrite(speakerPin,HIGH);
delayMicroseconds(delayAmount);
digitalWrite(speakerPin,LOW);
delayMicroseconds(delayAmount);
//break;
}
SENSORgo = 0;
}








[...] 3. ATTiny tips and other resources [...]
Howdy,
Atmel brought ought a newer, cheaper version of the ATTiny84 recently. It is the ATTiny84A. I am thinking about ordering a tube of these to play($1.38 each) with, but I wonder if they will work OK. The only significant difference I see is slightly different voltage ranges. Have you tried it?
Thanks,
Ralph
[...] 4. ATTiny tips and other resources [...]
[...] http://www.kobakant.at/DIY/?p=3408 [...]
Thanks for the examples. The Software serial example is broken though, #include what?
// software serial example for ATtiny!
#include
SoftwareSerial mySerial(0, 1); // RX, TX
ja dat foutje van the serial program =
#include
//en natuurlijk:
pinMode(3, INPUT); //in the setup
gr.